diff --git a/tribes-cli/cli.ts b/tribes-cli/cli.ts index fedfe014..9f1d9913 100644 --- a/tribes-cli/cli.ts +++ b/tribes-cli/cli.ts @@ -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); + } +}