|
|
|
import {Unit, Logging} from "@extollo/lib"
|
|
|
|
import {Singleton, Instantiable, Inject} from "@extollo/di"
|
|
|
|
import {Collection} from "@extollo/util"
|
|
|
|
import {CommandLineApplication} from "./CommandLineApplication"
|
|
|
|
import {Directive} from "../Directive"
|
|
|
|
import {Template} from "../Template"
|
|
|
|
import {directive_template} from "../templates/directive"
|
|
|
|
|
|
|
|
@Singleton()
|
|
|
|
export class CommandLine extends Unit {
|
|
|
|
@Inject()
|
|
|
|
protected readonly logging!: Logging
|
|
|
|
|
|
|
|
protected directives: Collection<Instantiable<Directive>> = new Collection<Instantiable<Directive>>()
|
|
|
|
protected templates: Collection<Template> = new Collection<Template>()
|
|
|
|
|
|
|
|
constructor() { super() }
|
|
|
|
|
|
|
|
async up() {
|
|
|
|
this.registerTemplate(directive_template)
|
|
|
|
}
|
|
|
|
|
|
|
|
public isCLI() {
|
|
|
|
return this.app().hasUnit(CommandLineApplication)
|
|
|
|
}
|
|
|
|
|
|
|
|
public getASCIILogo() {
|
|
|
|
return ` ______ _ _ _
|
|
|
|
| ____| | | | | |
|
|
|
|
| |__ __ _| |_ ___ | | | ___
|
|
|
|
| __| \\ \\/ / __/ _ \\| | |/ _ \\
|
|
|
|
| |____ > <| || (_) | | | (_) |
|
|
|
|
|______/_/\\_\\\\__\\___/|_|_|\\___/`
|
|
|
|
}
|
|
|
|
|
|
|
|
public registerDirective(directiveClass: Instantiable<Directive>) {
|
|
|
|
if ( !this.directives.includes(directiveClass) ) {
|
|
|
|
this.directives.push(directiveClass)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public hasDirective(directiveClass: Instantiable<Directive>) {
|
|
|
|
return this.directives.includes(directiveClass)
|
|
|
|
}
|
|
|
|
|
|
|
|
public getDirectives() {
|
|
|
|
return this.directives.clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
public registerTemplate(template: Template) {
|
|
|
|
if ( !this.templates.firstWhere('name', '=', template.name) ) {
|
|
|
|
this.templates.push(template)
|
|
|
|
} else {
|
|
|
|
this.logging.warn(`Duplicate template will not be registered: ${template.name}`)
|
|
|
|
this.logging.debug(`Duplicate template registered at: ${(new Error()).stack}`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public hasTemplate(name: string) {
|
|
|
|
return !!this.templates.firstWhere('name', '=', name)
|
|
|
|
}
|
|
|
|
|
|
|
|
public getTemplate(name: string) {
|
|
|
|
return this.templates.firstWhere('name', '=', name)
|
|
|
|
}
|
|
|
|
|
|
|
|
public getTemplates() {
|
|
|
|
return this.templates.clone()
|
|
|
|
}
|
|
|
|
}
|