@ionic/cli-utils
Advanced tools
Comparing version 0.0.1-alpha.63f24da1 to 0.0.1-alpha.6a2e9ddb
@@ -170,2 +170,3 @@ /// <reference types="inquirer" /> | ||
namespace: INamespace; | ||
pluginName: string | undefined; | ||
} | ||
@@ -172,0 +173,0 @@ export interface INamespace { |
@@ -11,2 +11,2 @@ import { INamespace, CommandEnvironment } from '../../definitions'; | ||
[k: string]: string; | ||
}, namespace: INamespace): Promise<CommandEnvironment>; | ||
}, namespace: INamespace, pluginName?: string): Promise<CommandEnvironment>; |
@@ -17,3 +17,2 @@ "use strict"; | ||
const logger_1 = require("../utils/logger"); | ||
const errors_1 = require("../errors"); | ||
const app_1 = require("../app"); | ||
@@ -36,7 +35,9 @@ const config_1 = require("../config"); | ||
let [inputs, command] = primaryNamespace.locateCommand(argv._); | ||
// If the command was not found throw | ||
if (command === undefined) { | ||
throw new errors_1.FatalException(`Command not found: ${chalk.bold(argv._.join(' '))}.`); | ||
throw `Command not found: ${chalk.bold(argv._.join(' '))}.`; | ||
} | ||
const commandName = (commandEnvironment.pluginName) ? `${commandEnvironment.pluginName}:command` : command.metadata.name; | ||
if (argv['help'] || argv['h']) { | ||
return console.log(help_1.formatCommandHelp(command.metadata)); | ||
return console.log(help_1.formatCommandHelp(command.metadata, commandName)); | ||
} | ||
@@ -54,3 +55,3 @@ command.env = commandEnvironment; | ||
*/ | ||
function createCommandEnvironment(pargv, env, namespace) { | ||
function createCommandEnvironment(pargv, env, namespace, pluginName) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -84,3 +85,4 @@ const argv = minimist(pargv); | ||
shell, | ||
namespace | ||
namespace, | ||
pluginName | ||
}; | ||
@@ -87,0 +89,0 @@ return commandEnvironment; |
@@ -5,2 +5,2 @@ import { CommandData } from '../../definitions'; | ||
*/ | ||
export declare function formatCommandHelp(cmdMetadata: CommandData): string; | ||
export declare function formatCommandHelp(cmdMetadata: CommandData, commandName: string): string; |
@@ -8,14 +8,16 @@ "use strict"; | ||
*/ | ||
function formatCommandHelp(cmdMetadata) { | ||
function formatCommandHelp(cmdMetadata, commandName) { | ||
let description = cmdMetadata.description.split('\n').join('\n '); | ||
return ` | ||
${chalk.bold(description)} | ||
${formatUsage(cmdMetadata)}${formatInputs(cmdMetadata.inputs)}${formatOptions(cmdMetadata.options)}${formatExamples(cmdMetadata)} | ||
`; | ||
` + | ||
formatUsage(cmdMetadata.inputs, commandName) + | ||
formatInputs(cmdMetadata.inputs) + | ||
formatOptions(cmdMetadata.options) + | ||
formatExamples(cmdMetadata, commandName); | ||
} | ||
exports.formatCommandHelp = formatCommandHelp; | ||
function formatUsage({ name, inputs }) { | ||
function formatUsage(inputs = [], commandName) { | ||
const headerLine = chalk.bold(`Usage`); | ||
const usageLine = `$ ionic ${name} ${(inputs || []) | ||
const usageLine = `$ ionic ${commandName} ${(inputs || []) | ||
.map(input => { | ||
@@ -33,4 +35,4 @@ if (input.validators && input.validators.includes(validators_1.validators.required)) { | ||
} | ||
function formatInputs(inputs) { | ||
if (!Array.isArray(inputs) || inputs.length === 0) { | ||
function formatInputs(inputs = []) { | ||
if (inputs.length === 0) { | ||
return ''; | ||
@@ -52,4 +54,4 @@ } | ||
} | ||
function formatOptions(options) { | ||
if (!Array.isArray(options) || options.length === 0) { | ||
function formatOptions(options = []) { | ||
if (options.length === 0) { | ||
return ''; | ||
@@ -75,3 +77,3 @@ } | ||
} | ||
function formatExamples({ name, exampleCommands }) { | ||
function formatExamples({ exampleCommands }, commandName) { | ||
if (!Array.isArray(exampleCommands)) { | ||
@@ -81,3 +83,3 @@ return ''; | ||
const headerLine = chalk.bold(`Examples`); | ||
const exampleLines = exampleCommands.map(cmd => `$ ionic ${name} ${cmd} `); | ||
const exampleLines = exampleCommands.map(cmd => `$ ionic ${commandName} ${cmd} `); | ||
return ` | ||
@@ -84,0 +86,0 @@ ${headerLine} |
{ | ||
"name": "@ionic/cli-utils", | ||
"version": "0.0.1-alpha.63f24da1", | ||
"version": "0.0.1-alpha.6a2e9ddb", | ||
"description": "Ionic CLI Utils", | ||
@@ -5,0 +5,0 @@ "homepage": "https://ionic.io/", |
77448
2102