@tsed/cli-core
Version:
Build your CLI with TypeScript and Decorators
34 lines (33 loc) • 941 B
JavaScript
import { injectable } from "@tsed/di";
import { JsonSchema } from "@tsed/schema";
JsonSchema.add("prompt", function prompt(label) {
this.customKey("x-label", label);
return this;
})
.add("when", function when(fn) {
this.customKey("x-when", fn);
return this;
})
.add("opt", function opt(v) {
this.customKey("x-opt", v);
return this;
})
.add("choices", function choices(choices) {
this.customKey("x-choices", choices);
return this;
});
export function command(options) {
if (!options.token) {
return injectable(Symbol.for(`COMMAND_${options.name}`))
.type("command")
.set("command", options)
.factory(() => {
return {
...options,
$prompt: options.prompt,
$exec: options.handler
};
});
}
return injectable(options.token).type("command").set("command", options);
}