@ionic/cli-utils
Advanced tools
Comparing version 0.0.1-alpha.1b3573c8 to 0.0.1-alpha.22dc0bf8
@@ -33,2 +33,3 @@ /// <reference types="inquirer" /> | ||
app_id: string; | ||
v2: boolean; | ||
} | ||
@@ -94,2 +95,3 @@ export interface AppDetails { | ||
options?: CommandOption[]; | ||
fullName?: string; | ||
} | ||
@@ -171,2 +173,3 @@ export interface ISession { | ||
namespace: INamespace; | ||
pluginName: string | undefined; | ||
} | ||
@@ -173,0 +176,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>; |
"use strict"; | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -17,3 +25,2 @@ return new (P || (P = Promise))(function (resolve, reject) { | ||
const logger_1 = require("../utils/logger"); | ||
const errors_1 = require("../errors"); | ||
const app_1 = require("../app"); | ||
@@ -36,7 +43,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 fullName = (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(__assign({}, command.metadata, { fullName }))); | ||
} | ||
@@ -54,3 +63,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 +93,4 @@ const argv = minimist(pargv); | ||
shell, | ||
namespace | ||
namespace, | ||
pluginName | ||
}; | ||
@@ -87,0 +97,0 @@ return commandEnvironment; |
@@ -8,1 +8,2 @@ export declare const ICON_SUCCESS = "✔"; | ||
export declare function indent(n?: number): string; | ||
export declare function generateFillSpaceStringList(list: string[], optimalLength: number, fillCharacter?: string): string[]; |
@@ -23,4 +23,11 @@ "use strict"; | ||
function indent(n = 4) { | ||
return new Array(n).fill(' ').reduce((a, b) => a + b); | ||
return new Array(n).fill(' ').join(''); | ||
} | ||
exports.indent = indent; | ||
function generateFillSpaceStringList(list, optimalLength, fillCharacter = ' ') { | ||
const longestItem = Math.max(...list.map((item) => item.replace(exports.STRIP_ANSI_REGEX, '').length)); | ||
const fullLength = longestItem > optimalLength ? longestItem + 1 : optimalLength; | ||
const fullLengthString = Array(fullLength).fill(fillCharacter).join(''); | ||
return list.map(item => fullLengthString.substr(0, fullLength - item.length)); | ||
} | ||
exports.generateFillSpaceStringList = generateFillSpaceStringList; |
@@ -6,1 +6,2 @@ import { CommandData } from '../../definitions'; | ||
export declare function formatCommandHelp(cmdMetadata: CommandData): string; | ||
export declare function getListOfCommandDetails(cmdMetadataList: CommandData[]): string[]; |
@@ -10,12 +10,20 @@ "use strict"; | ||
let description = cmdMetadata.description.split('\n').join('\n '); | ||
let fullName = cmdMetadata.fullName || cmdMetadata.name; | ||
return ` | ||
${chalk.bold(description)} | ||
${formatUsage(cmdMetadata)}${formatInputs(cmdMetadata.inputs)}${formatOptions(cmdMetadata.options)}${formatExamples(cmdMetadata)} | ||
`; | ||
` + | ||
formatCommandUsage(cmdMetadata.inputs, fullName) + | ||
formatCommandInputs(cmdMetadata.inputs) + | ||
formatCommandOptions(cmdMetadata.options) + | ||
formatCommandExamples(cmdMetadata.exampleCommands, fullName); | ||
} | ||
exports.formatCommandHelp = formatCommandHelp; | ||
function formatUsage({ name, inputs }) { | ||
function getListOfCommandDetails(cmdMetadataList) { | ||
const fillStringArray = format_1.generateFillSpaceStringList(cmdMetadataList.map(cmdMd => cmdMd.fullName || cmdMd.name), 25, '.'); | ||
return cmdMetadataList.map((cmdMd, index) => `${chalk.green(cmdMd.fullName || '')} ${fillStringArray[index]} ${cmdMd.description}`); | ||
} | ||
exports.getListOfCommandDetails = getListOfCommandDetails; | ||
function formatCommandUsage(inputs = [], commandName) { | ||
const headerLine = chalk.bold(`Usage`); | ||
const usageLine = `$ ionic ${name} ${(inputs || []) | ||
const usageLine = `$ ionic ${commandName} ${(inputs || []) | ||
.map(input => { | ||
@@ -33,12 +41,11 @@ if (input.validators && input.validators.includes(validators_1.validators.required)) { | ||
} | ||
function formatInputs(inputs) { | ||
if (!Array.isArray(inputs) || inputs.length === 0) { | ||
function formatCommandInputs(inputs = []) { | ||
if (inputs.length === 0) { | ||
return ''; | ||
} | ||
const headerLine = chalk.bold(`Inputs`); | ||
function inputLineFn({ name, description }) { | ||
const fillStrings = format_1.generateFillSpaceStringList(inputs.map(input => input.name), 25, '.'); | ||
function inputLineFn({ name, description }, index) { | ||
const optionList = chalk.green(`${name}`); | ||
const optionListLength = optionList.replace(format_1.STRIP_ANSI_REGEX, '').length; | ||
const fullLength = optionListLength > 25 ? optionListLength + 1 : 25; | ||
return `${optionList} ${Array(fullLength - optionListLength).fill('.').join('')} ${description}`; | ||
return `${optionList} ${fillStrings[index]} ${description}`; | ||
} | ||
@@ -52,4 +59,4 @@ ; | ||
} | ||
function formatOptions(options) { | ||
if (!Array.isArray(options) || options.length === 0) { | ||
function formatCommandOptions(options = []) { | ||
if (options.length === 0) { | ||
return ''; | ||
@@ -75,3 +82,3 @@ } | ||
} | ||
function formatExamples({ name, exampleCommands }) { | ||
function formatCommandExamples(exampleCommands, commandName) { | ||
if (!Array.isArray(exampleCommands)) { | ||
@@ -81,3 +88,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 +91,0 @@ ${headerLine} |
{ | ||
"name": "@ionic/cli-utils", | ||
"version": "0.0.1-alpha.1b3573c8", | ||
"version": "0.0.1-alpha.22dc0bf8", | ||
"description": "Ionic CLI Utils", | ||
@@ -5,0 +5,0 @@ "homepage": "https://ionic.io/", |
78847
2125