Use run() instead of CLI class
This commit is contained in:
parent
f51b41c576
commit
c8d22278a5
@ -1 +1 @@
|
|||||||
export * from './CLI'
|
export * from './run'
|
||||||
|
|||||||
@ -1,11 +1,7 @@
|
|||||||
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) {
|
|
||||||
}
|
|
||||||
|
|
||||||
execute(argv: string[]) {
|
|
||||||
const choices: Array<keyof typeof commands> = ['start', 'migrate']
|
const choices: Array<keyof typeof commands> = ['start', 'migrate']
|
||||||
const {parse} = argparse({
|
const {parse} = argparse({
|
||||||
command: arg('string', {
|
command: arg('string', {
|
||||||
@ -23,9 +19,7 @@ export class CLI {
|
|||||||
})
|
})
|
||||||
const args = parse(argv)
|
const args = parse(argv)
|
||||||
const command = args.command as keyof typeof commands
|
const command = args.command as keyof typeof commands
|
||||||
commands[command](this.bootstrap, [args.command, ...args.args])
|
commands[command](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