nest-console
Advanced tools
Comparing version 6.7.3 to 6.10.1
import { INestApplication } from '@nestjs/common'; | ||
import { ModulesContainer } from '@nestjs/core/injector'; | ||
import { MetadataScanner } from '@nestjs/core/metadata-scanner'; | ||
import { Command } from 'commander'; | ||
import { Constructor } from '@nestjs/common/utils/merge-with-values.util'; | ||
@@ -15,3 +16,3 @@ import { Module } from '@nestjs/core/injector/module'; | ||
runP(options: Omit<ConsoleRunOptions, 'callback'>): Promise<unknown>; | ||
addCommand(app: INestApplication, prog: Caporal, commandClass: Constructor<any>, module: Module): Caporal; | ||
addCommand(app: INestApplication, prog: Command, commandClass: Constructor<any>, module: Module): Command; | ||
} |
@@ -7,3 +7,3 @@ "use strict"; | ||
const metadata_scanner_1 = require("@nestjs/core/metadata-scanner"); | ||
const caporal = require("caporal"); | ||
const commander_1 = require("commander"); | ||
const lodash_1 = require("lodash"); | ||
@@ -19,8 +19,12 @@ const decorators_1 = require("./decorators"); | ||
run(options) { | ||
const { app, name, version = 'v0.1.0', logger = console, args = process.argv, callback } = options; | ||
const { app, name, version = 'v0.1.0', args = process.argv, callback } = options; | ||
const program = new commander_1.Command(); | ||
this.callback = callback; | ||
caporal | ||
program | ||
.name(name) | ||
.version(version) | ||
.logger(logger); | ||
.configureOutput({ | ||
writeOut: (str) => console.log(str), | ||
writeErr: (str) => console.error(str), | ||
}); | ||
this.modulesContainer.forEach((module) => { | ||
@@ -34,6 +38,6 @@ const commands = Reflect.getMetadata(decorators_1.META_MODULE_COMMANDS, module.metatype); | ||
module.addInjectable(component); | ||
this.addCommand(app, caporal, component, module); | ||
this.addCommand(app, program, component, module); | ||
}); | ||
}); | ||
caporal.parse(args); | ||
program.parse(args); | ||
} | ||
@@ -63,2 +67,4 @@ runP(options) { | ||
if (argumentsMeta) { | ||
if (!prog.args) | ||
prog.args = []; | ||
for (const argumentMeta of lodash_1.sortBy(argumentsMeta, 'parameterIndex')) { | ||
@@ -69,3 +75,6 @@ argsInfo.push({ | ||
}); | ||
command.argument(argumentMeta.name, argumentMeta.description, undefined, argumentMeta.defaultValue); | ||
command.arguments(argumentMeta.name).description('', { | ||
[argumentMeta.name]: argumentMeta.description, | ||
}); | ||
prog.args[argumentMeta.parameterIndex] = argumentMeta.defaultValue; | ||
} | ||
@@ -80,3 +89,8 @@ } | ||
}); | ||
command.option(`--${optionMeta.name} <${optionMeta.name}>`, optionMeta.description, undefined, optionMeta.defaultValue, optionMeta.required); | ||
if (optionMeta.required) { | ||
command.requiredOption(`--${optionMeta.name} <${optionMeta.name}>`, optionMeta.description, optionMeta.defaultValue); | ||
} | ||
else { | ||
command.option(`--${optionMeta.name} <${optionMeta.name}>`, optionMeta.description, optionMeta.defaultValue); | ||
} | ||
} | ||
@@ -83,0 +97,0 @@ } |
{ | ||
"name": "nest-console", | ||
"version": "6.7.3", | ||
"version": "6.10.1", | ||
"description": "The nest console module eases the creation of beautiful and testable command line interfaces for applications base on nestjs framework.", | ||
@@ -20,2 +20,3 @@ "keywords": [ | ||
"caporal": "^1.2.0", | ||
"commander": "^7.1.0", | ||
"inquirer": "^6.5.0", | ||
@@ -22,0 +23,0 @@ "lodash": "^4.17.14", |
Sorry, the diff of this file is not supported yet
28804
395
8
+ Addedcommander@^7.1.0
+ Addedcommander@7.2.0(transitive)