2021-09-21 18:42:06 +00:00
|
|
|
import {ContainerBlueprint, Instantiable, isInstantiableOf} from '../di'
|
|
|
|
import {CommandLine} from './service'
|
|
|
|
import {Directive} from './Directive'
|
|
|
|
import {logIfDebugging} from '../util'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register a class as a command-line Directive.
|
|
|
|
* The class must extend Directive.
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
export const CLIDirective = (): ClassDecorator => {
|
|
|
|
return (target) => {
|
|
|
|
if ( isInstantiableOf(target, Directive) ) {
|
|
|
|
logIfDebugging('extollo.cli.decorators', 'Registering CLIDirective blueprint:', target)
|
|
|
|
ContainerBlueprint.getContainerBlueprint()
|
2022-01-27 01:37:54 +00:00
|
|
|
.onResolve<CommandLine>(CommandLine, (cli: CommandLine) => {
|
2021-09-21 18:42:06 +00:00
|
|
|
cli.registerDirective(target as Instantiable<Directive>)
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
logIfDebugging('extollo.cli.decorators', 'Skipping CLIDirective blueprint:', target)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|