本文整理汇总了TypeScript中yargs-parser.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: registerSlashCommand
registerSlashCommand('joinWarband', 'Join an existing Warband.', (args: string) => {
let argv = yargs(args);
if (argv._.length === 1) {
// name only
webAPI.warbands.joinWarbandByName(client.shardID, argv._[0], client.characterID)
.then((response: any) => {
if (!response.ok) {
// something went wrong
console.error(response);
return;
}
// success
});
} else if (argv._.length === 2) {
// name and invite code
webAPI.warbands.joinWarbandByName(client.shardID, argv._[0], client.characterID, argv._[1])
.then((response: any) => {
if (!response.ok) {
// something went wrong
console.error(response);
return;
}
// success
});
} else {
systemMessage('Please provide a Warband name, or a Warband name and invite code in order to join a Warband.');
}
});
示例2: parseChromeFlags
export function parseChromeFlags(flags: string = '') {
const parsed = yargsParser(
flags, {configuration: {'camel-case-expansion': false, 'boolean-negation': false}});
return Object
.keys(parsed)
// Remove unnecessary _ item provided by yargs,
.filter(key => key !== '_')
// Avoid '=true', then reintroduce quotes
.map(key => {
if (parsed[key] === true) return `--${key}`;
return `--${key}="${parsed[key]}"`;
});
}
示例3: main
async function main(): Promise<void> {
const args = parseArgs(process.argv.slice(2), {boolean: ["profile"]});
const projectPath = args._[0];
const shouldProfile = args.profile;
const numTimes = args.times || 1;
const projectFiles = await loadProjectFiles(projectPath);
if (numTimes === 1) {
console.log(`Running Sucrase on ${projectPath}`);
} else {
console.log(`Running Sucrase ${numTimes} times on ${projectPath}`);
}
const totalLines = projectFiles
.map(({code}) => code.split("\n").length)
.reduce((a, b) => a + b, 0);
console.log(`Found ${projectFiles.length} files with ${totalLines} lines`);
if (shouldProfile) {
console.log(`Make sure you have Chrome DevTools for Node open.`);
// tslint:disable-next-line no-any
(console as any).profile(`Sucrase ${projectPath}`);
for (let i = 0; i < numTimes; i++) {
for (const fileInfo of projectFiles) {
runTransform(fileInfo);
}
}
// tslint:disable-next-line no-any
(console as any).profileEnd(`Sucrase ${projectPath}`);
} else {
const startTime = process.hrtime();
for (let i = 0; i < numTimes; i++) {
for (const fileInfo of projectFiles) {
runTransform(fileInfo);
}
}
const totalTime = process.hrtime(startTime);
const timeSeconds = totalTime[0] + totalTime[1] / 1e9;
console.log(`Time taken: ${Math.round(timeSeconds * 1000) / 1000}s`);
console.log(`Speed: ${Math.round((totalLines * numTimes) / timeSeconds)} lines per second`);
}
}
示例4: yargs
export const parseArgs = (args: string): any => yargs(args);
示例5:
import parse, { Arguments } from 'yargs-parser';
parse('--foo -bar');
parse(['--foo', '-bar']);
// prettier-ignore
// $ExpectError
parse(['--foo', '-bar'], {
string: 123,
});
parse(['--foo', '-bar'], {
// $ExpectError
unknown: ['b', 'a', 'r'],
});
// alias
parse(['--foo', '-bar'], {
alias: { foo: 'foo', bar: ['bar'] }
});
// array
parse(['--foo', '-bar'], {
array: ['foo', 'bar']
});
parse(['--foo', '-bar'], {
array: [{ key: 'foo', boolean: true }, { key: 'bar', number: true }],
示例6:
import parse, { Arguments } from 'yargs-parser';
parse('--foo -bar');
parse(['--foo', '-bar']);
parse(['--foo', '-bar'], {
boolean: ['b', 'a', 'r'],
});
// prettier-ignore
// $ExpectError
parse(['--foo', '-bar'], {
string: 123,
});
parse(['--foo', '-bar'], {
// $ExpectError
unknown: ['b', 'a', 'r'],
});
parse(['--foo', '-bar'], {
alias: { foo: 'foo', bar: ['bar'] },
'--': true,
});
parse(['--foo', '-bar'], {
configuration: {
'dot-notation': false,
},
});