mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
nicer subcommand api
This commit is contained in:
parent
2afb859027
commit
8ab5e19499
4 changed files with 20 additions and 9 deletions
|
|
@ -2,4 +2,4 @@ import { Command } from '../utils/mod.ts';
|
||||||
import { init } from './init.ts';
|
import { init } from './init.ts';
|
||||||
|
|
||||||
export const remote = new Command('remote', 'Manage a Ditto Tribes server')
|
export const remote = new Command('remote', 'Manage a Ditto Tribes server')
|
||||||
.subcommand('init', init);
|
.subcommand(init);
|
||||||
|
|
|
||||||
|
|
@ -3,5 +3,5 @@ import { config } from './config.ts';
|
||||||
import { Command } from '../utils/mod.ts';
|
import { Command } from '../utils/mod.ts';
|
||||||
|
|
||||||
export const tribe = new Command('tribe', 'Create and manage tribes.')
|
export const tribe = new Command('tribe', 'Create and manage tribes.')
|
||||||
.subcommand('create', create)
|
.subcommand(create)
|
||||||
.subcommand('config', config);
|
.subcommand(config);
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
import { Command } from '../utils/mod.ts';
|
import { Command, ParsedArgs } from '../utils/mod.ts';
|
||||||
|
|
||||||
export const create = new Command('create', 'Create a new tribe.')
|
export const create = new Command('new', 'Create a new tribe.')
|
||||||
.option('-c --custom-domain', {
|
.option('-c --custom-domain', {
|
||||||
description: 'Do not use a subdomain of the tribes server; instead, use a custom domain.',
|
description: 'Do not use a subdomain of the tribes server; instead, use a custom domain.',
|
||||||
})
|
})
|
||||||
.option('-s --subdomain', {
|
.option('-s --subdomain', {
|
||||||
description: 'Use a subdomain of the tribes server to host the new Ditto instance.',
|
description: 'Use a subdomain of the tribes server to host the new Ditto instance.',
|
||||||
|
})
|
||||||
|
.setAction((args: ParsedArgs) => {
|
||||||
|
// const ssh = sshConnect();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
import { Option, ParsedArgs } from './mod.ts';
|
import { Option, ParsedArgs } from './mod.ts';
|
||||||
|
import { parseArgs } from '@std/cli';
|
||||||
|
import { parseSubcommand } from './parsing.ts';
|
||||||
|
|
||||||
export class Command {
|
export class Command {
|
||||||
name: string;
|
name: string;
|
||||||
|
|
@ -36,11 +38,11 @@ export class Command {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
subcommand(name: string, command: Command) {
|
subcommand(command: Command) {
|
||||||
if (this.isValidSubcommand(name)) {
|
if (this.isValidSubcommand(command.name)) {
|
||||||
throw new Error(`tribes-cli: ${name} is already a subcommand.`);
|
throw new Error(`tribes-cli: ${command.name} is already a subcommand.`);
|
||||||
}
|
}
|
||||||
this.commands[name] = command;
|
this.commands[command.name] = command;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,4 +50,10 @@ export class Command {
|
||||||
this.options[fmt] = option;
|
this.options[fmt] = option;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parse(args: string[]) {
|
||||||
|
const parserArgs = parseSubcommand(this, {});
|
||||||
|
const parsed = parseArgs(Deno.args, parserArgs);
|
||||||
|
return { parsed, parserArgs };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue