Update logo and add run directive

This commit is contained in:
Garrett Mills 2021-03-22 12:06:27 -05:00
parent 0d533c5d9d
commit 7cffc2a359
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
4 changed files with 42 additions and 8 deletions

View File

@ -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<void> {
if ( !CommandLineApplication.getReplacement() ) {
throw new ErrorWithContext(`Cannot run application: no run target specified.`)
}
const unit = <Unit> this.make(CommandLineApplication.getReplacement())
await this.app().startUnit(unit)
await this.app().stopUnit(unit)
}
}

View File

@ -1,3 +1,4 @@
import {DependencyKey} from "@extollo/di"
import {Directive} from "../Directive" import {Directive} from "../Directive"
import * as colors from "colors/safe" import * as colors from "colors/safe"
import * as repl from 'repl' import * as repl from 'repl'
@ -25,8 +26,7 @@ export class ShellDirective extends Directive {
async handle(): Promise<void> { async handle(): Promise<void> {
const state: any = { const state: any = {
app: this.app(), app: this.app(),
make: this.make, make: (target: DependencyKey, ...parameters: any[]) => this.make(target, ...parameters),
container: this.container,
} }
await new Promise<void>(res => { await new Promise<void>(res => {

View File

@ -35,12 +35,14 @@ export class CommandLine extends Unit {
} }
public getASCIILogo() { public getASCIILogo() {
return ` ______ _ _ _ return ` _
| ____| | | | | | / /\\ ______ _ _ _
| |__ __ _| |_ ___ | | | ___ / / \\ | ____| | | | | |
| __| \\ \\/ / __/ _ \\| | |/ _ \\ / / /\\ \\ | |__ __ _| |_ ___ | | | ___
| |____ > <| || (_) | | | (_) | / / /\\ \\ \\ | __| \\ \\/ / __/ _ \\| | |/ _ \\
|______/_/\\_\\\\__\\___/|_|_|\\___/` / / / \\ \\_\\ | |____ > <| || (_) | | | (_) |
\\/_/ \\/_/ |______/_/\\_\\\\__\\___/|_|_|\\___/
`
} }
public registerDirective(directiveClass: Instantiable<Directive>) { public registerDirective(directiveClass: Instantiable<Directive>) {

View File

@ -5,6 +5,7 @@ import {UsageDirective} from "../directive/UsageDirective";
import {Directive} from "../Directive"; import {Directive} from "../Directive";
import {ShellDirective} from "../directive/ShellDirective"; import {ShellDirective} from "../directive/ShellDirective";
import {TemplateDirective} from "../directive/TemplateDirective"; import {TemplateDirective} from "../directive/TemplateDirective";
import {RunDirective} from "../directive/RunDirective";
@Singleton() @Singleton()
export class CommandLineApplication extends Unit { export class CommandLineApplication extends Unit {
@ -13,6 +14,10 @@ export class CommandLineApplication extends Unit {
this.replacement = unitClass this.replacement = unitClass
} }
public static getReplacement() {
return this.replacement
}
@Inject() @Inject()
protected readonly cli!: CommandLine protected readonly cli!: CommandLine
@ -25,6 +30,7 @@ export class CommandLineApplication extends Unit {
this.cli.registerDirective(UsageDirective) this.cli.registerDirective(UsageDirective)
this.cli.registerDirective(ShellDirective) this.cli.registerDirective(ShellDirective)
this.cli.registerDirective(TemplateDirective) this.cli.registerDirective(TemplateDirective)
this.cli.registerDirective(RunDirective)
const argv = process.argv.slice(2) const argv = process.argv.slice(2)
const match = this.cli.getDirectives() const match = this.cli.getDirectives()