From c8d22278a5bff164a5874c67101a438c14f4fa2f Mon Sep 17 00:00:00 2001 From: Jerko Steiner Date: Tue, 17 Sep 2019 11:30:16 +0700 Subject: [PATCH] Use run() instead of CLI class --- packages/server/src/cli/index.ts | 2 +- packages/server/src/cli/{CLI.ts => run.ts} | 45 ++++++++++------------ packages/server/src/index.ts | 4 +- 3 files changed, 23 insertions(+), 28 deletions(-) rename packages/server/src/cli/{CLI.ts => run.ts} (62%) diff --git a/packages/server/src/cli/index.ts b/packages/server/src/cli/index.ts index 8abad35..b8492c1 100644 --- a/packages/server/src/cli/index.ts +++ b/packages/server/src/cli/index.ts @@ -1 +1 @@ -export * from './CLI' +export * from './run' diff --git a/packages/server/src/cli/CLI.ts b/packages/server/src/cli/run.ts similarity index 62% rename from packages/server/src/cli/CLI.ts rename to packages/server/src/cli/run.ts index 34ca154..b292f1a 100644 --- a/packages/server/src/cli/CLI.ts +++ b/packages/server/src/cli/run.ts @@ -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 = ['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 = ['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', }), diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index ac228bb..6a93d84 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -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)) }