Use Node.js built-in parseArgs for CLI argument parsing (#17)

Replace manual argument parsing with util.parseArgs() API.
This commit is contained in:
Christian Semmler 2026-02-02 16:37:08 -08:00 committed by GitHub
parent 9ab402393b
commit eed65faeac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 {