mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
skeleton of how args are gonna look
This commit is contained in:
parent
055716fd97
commit
4f94309ec2
1 changed files with 26 additions and 0 deletions
|
|
@ -21,4 +21,30 @@ for (const [_name, body] of Object.entries(commands)) {
|
||||||
// TODO: construct a help string here
|
// TODO: construct a help string here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const parsed = parseArgs(Deno.args, parserArgs);
|
||||||
console.log(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue