ditto/tribes-cli/cli.ts
2024-09-27 21:29:01 +05:30

36 lines
827 B
TypeScript

import { tribe } from './tribe/mod.ts';
import { remote } from './remote/mod.ts';
import { Command, defaultIdentityFile, setupCli } from './utils/mod.ts';
async function main() {
const tribes = new Command('tribes-cli', 'Create and manage Ditto Tribes servers.')
.subcommand('tribe', tribe)
.subcommand('remote', remote);
const { parsed } = setupCli(tribes, {
string: ['identity-file'],
default: {
'identity-file': await defaultIdentityFile(),
},
});
const [s, v] = parsed._;
let cmd = tribes;
if (s && !v) {
cmd = tribes.getSubcommand(s);
} else if (s && v) {
cmd = tribes.getSubcommand(s).getSubcommand(v);
}
await cmd.action(parsed);
}
if (import.meta.main) {
try {
await main();
} catch (e) {
console.error('ERROR:', e.message);
Deno.exit(1);
}
}