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 { argparse, arg } from "@rondo.dev/argparse";
|
||||
|
||||
export class CLI {
|
||||
constructor(readonly bootstrap: Bootstrap) {
|
||||
}
|
||||
|
||||
execute(argv: string[]) {
|
||||
const choices: Array<keyof typeof commands> = ['start', 'migrate']
|
||||
const {parse} = argparse({
|
||||
command: arg('string', {
|
||||
default: 'start',
|
||||
choices,
|
||||
positional: true,
|
||||
description: 'Command to run',
|
||||
}),
|
||||
args: arg('string[]', {
|
||||
n: '*',
|
||||
positional: true,
|
||||
description: 'Command arguments',
|
||||
}),
|
||||
help: arg('boolean', {alias: 'h'}),
|
||||
})
|
||||
const args = parse(argv)
|
||||
const command = args.command as keyof typeof commands
|
||||
commands[command](this.bootstrap, [args.command, ...args.args])
|
||||
}
|
||||
|
||||
export function run(bootstrap: Bootstrap, argv: string[]) {
|
||||
const choices: Array<keyof typeof commands> = ['start', 'migrate']
|
||||
const {parse} = argparse({
|
||||
command: arg('string', {
|
||||
default: 'start',
|
||||
choices,
|
||||
positional: true,
|
||||
description: 'Command to run',
|
||||
}),
|
||||
args: arg('string[]', {
|
||||
n: '*',
|
||||
positional: true,
|
||||
description: 'Command arguments',
|
||||
}),
|
||||
help: arg('boolean', {alias: 'h'}),
|
||||
})
|
||||
const args = parse(argv)
|
||||
const command = args.command as keyof typeof commands
|
||||
commands[command](bootstrap, [args.command, ...args.args])
|
||||
}
|
||||
|
||||
const commands = {
|
||||
@ -39,6 +33,7 @@ const commands = {
|
||||
description: 'Socket to listen on',
|
||||
}),
|
||||
port: arg('number', {
|
||||
default: 3000,
|
||||
alias: 'p',
|
||||
description: 'Port to listen on',
|
||||
}),
|
||||
@ -19,8 +19,8 @@ import * as rpc from './rpc'
|
||||
export {rpc}
|
||||
|
||||
import bootstrap from './bootstrap'
|
||||
import { CLI } from './cli'
|
||||
import {run} from './cli'
|
||||
|
||||
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