skeleton of how args are gonna look

This commit is contained in:
Siddharth Singh 2024-09-26 18:07:25 +05:30
parent 055716fd97
commit 4f94309ec2
No known key found for this signature in database

View file

@ -21,4 +21,30 @@ for (const [_name, body] of Object.entries(commands)) {
// TODO: construct a help string here
}
const parsed = parseArgs(Deno.args, parserArgs);
console.log(parserArgs);
console.log(parsed);
const [subcommand, verb] = parsed._;
const isValidSubcommand = (key: string): key is keyof typeof commands => {
return Object.keys(commands).includes(key.toString());
};
if (typeof subcommand === 'number') {
console.error('Error: subcommand cannot be a number');
Deno.exit(1);
}
if (!subcommand) {
// todo: output help, probably
} else if (subcommand && !verb) {
// todo: output help only for specific subcommand
} else {
if (isValidSubcommand(subcommand)) {
console.log(commands[subcommand]);
} else {
console.error(`Error: ${subcommand} is not a valid subcommand`);
Deno.exit(1);
}
}