本文整理匯總了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,
},
});