Use run() instead of CLI class
This commit is contained in:
parent
f51b41c576
commit
c8d22278a5
@ -1 +1 @@
|
|||||||
export * from './CLI'
|
export * from './run'
|
||||||
|
|||||||
@ -1,31 +1,25 @@
|
|||||||
import { Bootstrap } from "../application";
|
import { Bootstrap } from "../application";
|
||||||
import { argparse, arg } from "@rondo.dev/argparse";
|
import { argparse, arg } from "@rondo.dev/argparse";
|
||||||
|
|
||||||
export class CLI {
|
export function run(bootstrap: Bootstrap, argv: string[]) {
|
||||||
constructor(readonly bootstrap: Bootstrap) {
|
const choices: Array<keyof typeof commands> = ['start', 'migrate']
|
||||||
}
|
const {parse} = argparse({
|
||||||
|
command: arg('string', {
|
||||||
execute(argv: string[]) {
|
default: 'start',
|
||||||
const choices: Array<keyof typeof commands> = ['start', 'migrate']
|
choices,
|
||||||
const {parse} = argparse({
|
positional: true,
|
||||||
command: arg('string', {
|
description: 'Command to run',
|
||||||
default: 'start',
|
}),
|
||||||
choices,
|
args: arg('string[]', {
|
||||||
positional: true,
|
n: '*',
|
||||||
description: 'Command to run',
|
positional: true,
|
||||||
}),
|
description: 'Command arguments',
|
||||||
args: arg('string[]', {
|
}),
|
||||||
n: '*',
|
help: arg('boolean', {alias: 'h'}),
|
||||||
positional: true,
|
})
|
||||||
description: 'Command arguments',
|
const args = parse(argv)
|
||||||
}),
|
const command = args.command as keyof typeof commands
|
||||||
help: arg('boolean', {alias: 'h'}),
|
commands[command](bootstrap, [args.command, ...args.args])
|
||||||
})
|
|
||||||
const args = parse(argv)
|
|
||||||
const command = args.command as keyof typeof commands
|
|
||||||
commands[command](this.bootstrap, [args.command, ...args.args])
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const commands = {
|
const commands = {
|
||||||
@ -39,6 +33,7 @@ const commands = {
|
|||||||
description: 'Socket to listen on',
|
description: 'Socket to listen on',
|
||||||
}),
|
}),
|
||||||
port: arg('number', {
|
port: arg('number', {
|
||||||
|
default: 3000,
|
||||||
alias: 'p',
|
alias: 'p',
|
||||||
description: 'Port to listen on',
|
description: 'Port to listen on',
|
||||||
}),
|
}),
|
||||||
@ -19,8 +19,8 @@ import * as rpc from './rpc'
|
|||||||
export {rpc}
|
export {rpc}
|
||||||
|
|
||||||
import bootstrap from './bootstrap'
|
import bootstrap from './bootstrap'
|
||||||
import { CLI } from './cli'
|
import {run} from './cli'
|
||||||
|
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
new CLI(bootstrap).execute(process.argv.slice(1))
|
run(bootstrap, process.argv.slice(1))
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user