mirror of
https://github.com/isledecomp/isle.pizza.git
synced 2026-02-28 13:57:38 +00:00
Use Node.js built-in parseArgs for CLI argument parsing (#17)
Replace manual argument parsing with util.parseArgs() API.
This commit is contained in:
parent
9ab402393b
commit
eed65faeac
@ -5,6 +5,7 @@ import * as fs from 'node:fs/promises';
|
|||||||
import * as os from 'node:os';
|
import * as os from 'node:os';
|
||||||
import * as path from 'node:path';
|
import * as path from 'node:path';
|
||||||
import * as readline from 'node:readline';
|
import * as readline from 'node:readline';
|
||||||
|
import { parseArgs } from 'node:util';
|
||||||
|
|
||||||
// Expand ~ to home directory
|
// Expand ~ to home directory
|
||||||
function expandTilde(filePath) {
|
function expandTilde(filePath) {
|
||||||
@ -72,25 +73,12 @@ const OPTIONAL_FOLDERS = ['extra', 'textures'];
|
|||||||
|
|
||||||
const TARGET_DIR = path.join(process.cwd(), 'LEGO');
|
const TARGET_DIR = path.join(process.cwd(), 'LEGO');
|
||||||
|
|
||||||
// Parse command line arguments
|
const { values: args } = parseArgs({
|
||||||
function parseArgs() {
|
options: {
|
||||||
const args = process.argv.slice(2);
|
path: { type: 'string', short: 'p' },
|
||||||
let sourcePath = null;
|
force: { type: 'boolean', short: 'f', default: false },
|
||||||
let force = false;
|
},
|
||||||
|
});
|
||||||
for (let i = 0; i < args.length; i++) {
|
|
||||||
if (args[i] === '--path' || args[i] === '-p') {
|
|
||||||
sourcePath = args[i + 1];
|
|
||||||
i++;
|
|
||||||
} else if (args[i] === '--force' || args[i] === '-f') {
|
|
||||||
force = true;
|
|
||||||
} else if (args[i].startsWith('--path=')) {
|
|
||||||
sourcePath = args[i].slice(7);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return { sourcePath, force };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create readline interface for prompts
|
// Create readline interface for prompts
|
||||||
function createReadline() {
|
function createReadline() {
|
||||||
@ -270,7 +258,7 @@ async function createOptionalSymlinks(optionalFiles) {
|
|||||||
async function main() {
|
async function main() {
|
||||||
console.log('LEGO Island Asset Setup\n');
|
console.log('LEGO Island Asset Setup\n');
|
||||||
|
|
||||||
const { sourcePath: argPath, force } = parseArgs();
|
const { path: argPath, force } = args;
|
||||||
const rl = createReadline();
|
const rl = createReadline();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user