mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
get rid of setupCli, use .option() to configure global methods
This commit is contained in:
parent
8ab5e19499
commit
9f034fdf1d
3 changed files with 14 additions and 27 deletions
|
|
@ -1,27 +1,22 @@
|
|||
import { tribe } from './tribe/mod.ts';
|
||||
import { remote } from './remote/mod.ts';
|
||||
import { Command, defaultIdentityFile, setupCli } from './utils/mod.ts';
|
||||
import { Command, defaultIdentityFile } 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);
|
||||
.subcommand(tribe)
|
||||
.subcommand(remote)
|
||||
.option('-i --identity-file', {
|
||||
description: 'The ssh identity file to use. Defaults to ~/.ssh/id_rsa.',
|
||||
default: await defaultIdentityFile(),
|
||||
});
|
||||
|
||||
const { parsed } = setupCli(tribes, {
|
||||
string: ['identity-file'],
|
||||
default: {
|
||||
'identity-file': await defaultIdentityFile(),
|
||||
},
|
||||
});
|
||||
|
||||
const [s, v] = parsed._;
|
||||
const { parsed } = tribes.parse(Deno.args);
|
||||
const [s, v] = parsed._.slice(1);
|
||||
|
||||
let cmd = tribes;
|
||||
if (s && !v) {
|
||||
cmd = tribes.getSubcommand(s);
|
||||
} else if (s && v) {
|
||||
cmd = tribes.getSubcommand(s).getSubcommand(v);
|
||||
}
|
||||
if (s) cmd = tribes.getSubcommand(s);
|
||||
if (v) cmd = cmd.getSubcommand(v);
|
||||
|
||||
await cmd.action(parsed);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { join } from '@std/path';
|
||||
import { ParsedArgs, setupCli } from './parsing.ts';
|
||||
import { ParsedArgs } from './parsing.ts';
|
||||
import { Command } from './command.ts';
|
||||
|
||||
export const defaultIdentityFile = async () => {
|
||||
|
|
@ -27,5 +27,5 @@ export const cleanArg = (arg: string) => {
|
|||
return arg.replace(/^--?/g, '');
|
||||
};
|
||||
|
||||
export { Command, setupCli };
|
||||
export { Command };
|
||||
export type { ParsedArgs };
|
||||
|
|
|
|||
|
|
@ -1,13 +1,5 @@
|
|||
import { parseArgs as stdParseArgs } from '@std/cli';
|
||||
import { cleanArg, Command } from './mod.ts';
|
||||
|
||||
export const setupCli = (command: Command, parserArgs: Partial<ParsedSubcommand> = {}) => {
|
||||
parserArgs = parseSubcommand(command, parserArgs);
|
||||
const parsed = stdParseArgs(Deno.args, parserArgs);
|
||||
return { parsed, parserArgs };
|
||||
};
|
||||
|
||||
export type ParsedArgs = ReturnType<typeof setupCli>['parsed'];
|
||||
export type ParsedArgs = ReturnType<Command['parse']>['parsed'];
|
||||
|
||||
export interface ParsedSubcommand {
|
||||
string: string[];
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue