本文整理汇总了TypeScript中yargs-parser.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript yargs-parser.default方法的具体用法?TypeScript yargs-parser.default怎么用?TypeScript yargs-parser.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yargs-parser
的用法示例。
在下文中一共展示了yargs-parser.default方法的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);
}
}
示例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
`;
//.........这里部分代码省略.........
示例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);
//.........这里部分代码省略.........