diff --git a/src/directive/RunDirective.ts b/src/directive/RunDirective.ts new file mode 100644 index 0000000..61b50c1 --- /dev/null +++ b/src/directive/RunDirective.ts @@ -0,0 +1,26 @@ +import {Directive} from "../Directive" +import {Injectable} from "@extollo/di" +import {Unit} from "@extollo/lib" +import {ErrorWithContext} from "@extollo/util" +import {CommandLineApplication} from "../service" + +@Injectable() +export class RunDirective extends Directive { + getDescription(): string { + return 'run the application normally' + } + + getKeywords(): string | string[] { + return ['run', 'up'] + } + + async handle(): Promise { + if ( !CommandLineApplication.getReplacement() ) { + throw new ErrorWithContext(`Cannot run application: no run target specified.`) + } + + const unit = this.make(CommandLineApplication.getReplacement()) + await this.app().startUnit(unit) + await this.app().stopUnit(unit) + } +} diff --git a/src/directive/ShellDirective.ts b/src/directive/ShellDirective.ts index 688afc9..141261d 100644 --- a/src/directive/ShellDirective.ts +++ b/src/directive/ShellDirective.ts @@ -1,3 +1,4 @@ +import {DependencyKey} from "@extollo/di" import {Directive} from "../Directive" import * as colors from "colors/safe" import * as repl from 'repl' @@ -25,8 +26,7 @@ export class ShellDirective extends Directive { async handle(): Promise { const state: any = { app: this.app(), - make: this.make, - container: this.container, + make: (target: DependencyKey, ...parameters: any[]) => this.make(target, ...parameters), } await new Promise(res => { diff --git a/src/service/CommandLine.ts b/src/service/CommandLine.ts index cf9856b..b43407a 100644 --- a/src/service/CommandLine.ts +++ b/src/service/CommandLine.ts @@ -35,12 +35,14 @@ export class CommandLine extends Unit { } public getASCIILogo() { - return ` ______ _ _ _ - | ____| | | | | | - | |__ __ _| |_ ___ | | | ___ - | __| \\ \\/ / __/ _ \\| | |/ _ \\ - | |____ > <| || (_) | | | (_) | - |______/_/\\_\\\\__\\___/|_|_|\\___/` + return ` _ + / /\\ ______ _ _ _ + / / \\ | ____| | | | | | + / / /\\ \\ | |__ __ _| |_ ___ | | | ___ + / / /\\ \\ \\ | __| \\ \\/ / __/ _ \\| | |/ _ \\ +/ / / \\ \\_\\ | |____ > <| || (_) | | | (_) | +\\/_/ \\/_/ |______/_/\\_\\\\__\\___/|_|_|\\___/ +` } public registerDirective(directiveClass: Instantiable) { diff --git a/src/service/CommandLineApplication.ts b/src/service/CommandLineApplication.ts index 1e40d3e..e6b1da5 100644 --- a/src/service/CommandLineApplication.ts +++ b/src/service/CommandLineApplication.ts @@ -5,6 +5,7 @@ import {UsageDirective} from "../directive/UsageDirective"; import {Directive} from "../Directive"; import {ShellDirective} from "../directive/ShellDirective"; import {TemplateDirective} from "../directive/TemplateDirective"; +import {RunDirective} from "../directive/RunDirective"; @Singleton() export class CommandLineApplication extends Unit { @@ -13,6 +14,10 @@ export class CommandLineApplication extends Unit { this.replacement = unitClass } + public static getReplacement() { + return this.replacement + } + @Inject() protected readonly cli!: CommandLine @@ -25,6 +30,7 @@ export class CommandLineApplication extends Unit { this.cli.registerDirective(UsageDirective) this.cli.registerDirective(ShellDirective) this.cli.registerDirective(TemplateDirective) + this.cli.registerDirective(RunDirective) const argv = process.argv.slice(2) const match = this.cli.getDirectives()