本文整理汇总了TypeScript中yargs-parser类的典型用法代码示例。如果您正苦于以下问题:TypeScript yargs-parser类的具体用法?TypeScript yargs-parser怎么用?TypeScript yargs-parser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了yargs-parser类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: runHelp
export async function runCommand(commandMap: CommandMap,
args: string[],
logger: logging.Logger,
context: CommandContext): Promise<any> {
// if not args supplied, just run the help command.
if (!args || args.length === 0) {
args = ['help'];
}
const rawOptions = yargsParser(args, { alias: { help: ['h'] }, boolean: [ 'help' ] });
let commandName = rawOptions._[0];
// remove the command name
rawOptions._ = rawOptions._.slice(1);
const executionScope = context.project.isEmberCLIProject()
? CommandScope.inProject
: CommandScope.outsideProject;
let Cmd: CommandConstructor;
Cmd = findCommand(commandMap, commandName);
if (!Cmd && !commandName && (rawOptions.v || rawOptions.version)) {
commandName = 'version';
Cmd = findCommand(commandMap, commandName);
}
if (!Cmd && rawOptions.help) {
commandName = 'help';
Cmd = findCommand(commandMap, commandName);
}
if (!Cmd) {
logger.error(oneLine`The specified command (${commandName}) is invalid.
For a list of available options, run \`ng help\`.`);
throw '';
}
const command = new Cmd(context, logger);
args = await command.initializeRaw(args);
let options = parseOptions(args, command.options, command.arguments, command.argStrategy);
await command.initialize(options);
options = parseOptions(args, command.options, command.arguments, command.argStrategy);
if (commandName === 'help') {
options.commandMap = commandMap;
}
if (options.help) {
return await runHelp(command, options);
} else {
verifyCommandInScope(command, executionScope);
delete options.h;
delete options.help;
return await validateAndRunCommand(command, options);
}
}
开发者ID:samsif,项目名称:angular-cli,代码行数:56,代码来源:command-runner.ts
示例2: command
export async function runCommand(commandMap: CommandMap,
args: string[],
logger: logging.Logger,
context: CommandContext): Promise<number | void> {
// if not args supplied, just run the help command.
if (!args || args.length === 0) {
args = ['help'];
}
const rawOptions = yargsParser(args, { alias: { help: ['h'] }, boolean: [ 'help' ] });
let commandName = rawOptions._[0];
// remove the command name
rawOptions._ = rawOptions._.slice(1);
const executionScope = insideProject()
? CommandScope.inProject
: CommandScope.outsideProject;
let Cmd: CommandConstructor | null;
Cmd = findCommand(commandMap, commandName);
if (!Cmd && !commandName && (rawOptions.v || rawOptions.version)) {
commandName = 'version';
Cmd = findCommand(commandMap, commandName);
}
if (!Cmd && rawOptions.help) {
commandName = 'help';
Cmd = findCommand(commandMap, commandName);
}
if (!Cmd) {
const commandsDistance = {} as { [name: string]: number };
const allCommands = listAllCommandNames(commandMap).sort((a, b) => {
if (!(a in commandsDistance)) {
commandsDistance[a] = levenshtein(a, commandName);
}
if (!(b in commandsDistance)) {
commandsDistance[b] = levenshtein(b, commandName);
}
return commandsDistance[a] - commandsDistance[b];
});
logger.error(tags.stripIndent`
The specified command ("${commandName}") is invalid. For a list of available options,
run "ng help".
Did you mean "${allCommands[0]}"?
`);
return 1;
}
const command = new Cmd(context, logger);
args = await command.initializeRaw(args);
let options = parseOptions(args, command.options, command.arguments, command.argStrategy);
await command.initialize(options);
options = parseOptions(args, command.options, command.arguments, command.argStrategy);
if (commandName === 'help') {
options.commandMap = commandMap;
}
if (options.help) {
command.printHelp(options);
return;
} else {
if (Cmd.scope !== undefined && Cmd.scope !== CommandScope.everywhere) {
if (Cmd.scope !== executionScope) {
let errorMessage;
if (Cmd.scope === CommandScope.inProject) {
errorMessage = `This command can only be run inside of a CLI project.`;
} else {
errorMessage = `This command can not be run inside of a CLI project.`;
}
logger.fatal(errorMessage);
return 1;
}
if (Cmd.scope === CommandScope.inProject) {
if (!context.project.configFile) {
logger.fatal('Invalid project: missing workspace file.');
return 1;
}
if (['.angular-cli.json', 'angular-cli.json'].includes(context.project.configFile)) {
// --------------------------------------------------------------------------------
// If changing this message, please update the same message in
// `packages/@angular/cli/bin/ng-update-message.js`
const message = tags.stripIndent`
The Angular CLI configuration format has been changed, and your existing configuration
can be updated automatically by running the following command:
ng update @angular/cli
`;
//.........这里部分代码省略.........
开发者ID:rexebin,项目名称:angular-cli,代码行数:101,代码来源:command-runner.ts
示例3: levenshtein
export async function runCommand(commandMap: CommandMap,
args: string[],
logger: logging.Logger,
context: CommandContext): Promise<number | void> {
// if not args supplied, just run the help command.
if (!args || args.length === 0) {
args = ['help'];
}
const rawOptions = yargsParser(args, { alias: { help: ['h'] }, boolean: [ 'help' ] });
let commandName = rawOptions._[0];
// remove the command name
rawOptions._ = rawOptions._.slice(1);
const executionScope = context.project.isEmberCLIProject()
? CommandScope.inProject
: CommandScope.outsideProject;
let Cmd: CommandConstructor;
Cmd = findCommand(commandMap, commandName);
if (!Cmd && !commandName && (rawOptions.v || rawOptions.version)) {
commandName = 'version';
Cmd = findCommand(commandMap, commandName);
}
if (!Cmd && rawOptions.help) {
commandName = 'help';
Cmd = findCommand(commandMap, commandName);
}
if (!Cmd) {
function levenshtein(a: string, b: string): number {
if (a.length === 0) {
return b.length;
}
if (b.length === 0) {
return a.length;
}
if (a.length > b.length) {
let tmp = a;
a = b;
b = tmp;
}
const row = Array(a.length);
for (let i = 0; i <= a.length; i++) {
row[i] = i;
}
let result: number;
for (let i = 1; i <= b.length; i++) {
result = i;
for (let j = 1; j <= a.length; j++) {
let tmp = row[j - 1];
row[j - 1] = result;
result = b[i - 1] === a[j - 1]
? tmp
: Math.min(tmp + 1, Math.min(result + 1, row[j] + 1));
}
}
return result;
}
const commandsDistance = {} as { [name: string]: number };
const allCommands = listAllCommandNames(commandMap).sort((a, b) => {
if (!(a in commandsDistance)) {
commandsDistance[a] = levenshtein(a, commandName);
}
if (!(b in commandsDistance)) {
commandsDistance[b] = levenshtein(b, commandName);
}
return commandsDistance[a] - commandsDistance[b];
});
logger.error(tags.stripIndent`
The specified command ("${commandName}") is invalid. For a list of available options,
run "ng help".
Did you mean "${allCommands[0]}"?
`);
return 1;
}
const command = new Cmd(context, logger);
args = await command.initializeRaw(args);
let options = parseOptions(args, command.options, command.arguments, command.argStrategy);
await command.initialize(options);
options = parseOptions(args, command.options, command.arguments, command.argStrategy);
if (commandName === 'help') {
options.commandMap = commandMap;
}
if (options.help) {
return await runHelp(command, options);
//.........这里部分代码省略.........
开发者ID:nickroberts,项目名称:angular-cli,代码行数:101,代码来源:command-runner.ts
注:本文中的yargs-parser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论