本文整理汇总了TypeScript中commander.command函数的典型用法代码示例。如果您正苦于以下问题:TypeScript command函数的具体用法?TypeScript command怎么用?TypeScript command使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了command函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
return new Promise<void>(async (resolve, reject) => {
let packageData = await fs.readJson(packagePath);
commander.version(packageData.version);
commander.option('--no-headless', 'disables headless mode');
commander.command('create <url...>')
.description('creates series metadata')
.action(exec<string[]>(urls => mio.commands.createAsync(urls).then(resolve, reject)));
commander.command('download')
.description('download series')
.action(exec(() => mio.commands.downloadAsync().then(resolve, reject)));
commander.command('update <url...>')
.description('updates series metadata')
.action(exec<string[]>(urls => mio.commands.updateAsync(urls).then(resolve, reject)));
commander.parse(argv);
});
示例2: versionCommand
private versionCommand(): void {
commander
.command('version')
.alias('v')
.description('Shows the CLI-Version')
.action(async (): Promise<void> => {
this.version.init();
});
}
示例3: helpCommand
private helpCommand(): void {
commander
.command('help')
.alias('h')
.description('Help')
.action(async (): Promise<void> => {
this.helper.init();
});
}
示例4:
Object.keys(tasks).forEach(function(taskName){
const task = tasks[taskName];
const {alias,flags,help} = task;
const command = commander.command(taskName);
if(alias){
command.alias(alias);
}
if(help){
command.description(help);
}
if(flags && flags.length){
flags.forEach(function([f,[desc,def]]){
command.option(f,desc,def);
})
}
});
示例5: createCommand
private createCommand(): void {
commander
.command('create')
.alias('i')
.description('Creates a Resource from the List')
.action(async (cmd: any): Promise<void> => {
this.creater.init().then((resource) => {
if (resource === 'React') {
this.creater.react(cmd);
} else if (resource === 'Angular') {
this.creater.angular(cmd);
} else if (resource === 'Vue') {
this.creater.vue(cmd);
}
});
});
}
示例6: catch
commands.forEach(command => {
// create command
let cmd = program.command(command.name)
// set alias
if (command.alias) {
cmd.alias(command.alias)
}
// set usage
if (command.usage) {
cmd.usage(command.usage)
}
// set description
if (command.description) {
cmd.description(command.description)
}
// set options
if (command.options && command.options.length) {
let options: string[][] = command.options
options.forEach((option: string[]) => {
cmd.option(option[0], option[1])
})
}
// set on
if (_.isObject(command.on)) {
_.forIn(command.on, (value, key) => {
cmd.on(key, value)
})
}
// set action
if (command.action) {
cmd.action(async (...args) => {
try {
await command.action.apply(command, args)
} catch (err) {
log.error(err)
}
})
}
})
示例7: installCommand
private installCommand(): void {
commander
.command('install')
.alias('i')
.description('Install a Resource from the List')
.action(async (): Promise<void> => {
this.installer.init().then((resource) => {
if (resource === 'Typescript') {
this.installer.typescript();
} else if (resource === 'React') {
this.installer.react();
} else if (resource === 'Angular') {
this.installer.angular();
} else if (resource === 'Vue') {
this.installer.vue();
}
});
});
}
示例8: Conf
const config = new Conf();
let progressBar: ProgressBar<ProgressData>;
interface BinDownloadConfig extends DownloadConfig {
silent?: boolean;
limit?: string;
}
// Log any unhandled exceptions...
process.on('uncaughtException', err => log(`uncaughtException: ${err}`, err));
process.on('unhandledRejection', (err, promise) => log(`unhandledRejection: ${err}`, err, promise));
swapArgs('-v', '-V'); // Convert -v to -V so version works correctly...
swapArgs('/?', '-h'); // Convert /? to also show help info...
program
.command('download <url>').alias('dl')
.description('Downloads a video from the YouTube link.')
.option('-p, --preset <preset>', 'The preset format to download.')
.option('-d, --dir <dir>', 'The location to save the download.')
.option('-t, --template <template>', 'The format of the the filename, recursively creating missing subfolders.')
.option('-l, --limit <size>', 'The maximum filesize to download.')
.option('-s, --silent', 'Hides all output.')
.action(function (url: string, options: BinDownloadConfig) {
options.url = url;
return mergeOptions(options)
.then((options => {
return new Pully().download(options);
}))
.then((result: DownloadResults) => {
options.silent || logUpdate(`${chalk.magenta(result.format.data.videoTitle)} saved as
${chalk.green(result.path)} [${toHumanTime(result.duration / 1000)}]`);
示例9: LumberJack
#!/usr/bin/env node
import * as program from 'commander';
import { Translate } from './commands/Translate';
import { Check } from './commands/Check';
import { Update } from './commands/Update';
import { Extract } from './commands/Extract';
import { Convert } from './commands/Convert';
import { LumberJack } from './utils/LumberJack';
const logger = new LumberJack();
program
.version('0.0.1');
program
.command('translate [lang]')
.description('Translate source file to new language')
.option('-d, --dest <dest>', 'specify localization resources directory.')
.option('-f, --format <format>', 'specify output format. (json, xliff)')
.action((...args) => {
let command: Translate = new Translate();
command.run(...args);
});
program
.command('convert [lang] [to]')
.description('Convert translations to new format')
.option('-d, --dest <dest>', 'specify localization resources directory.')
.option('-f, --format <format>', 'specify output format. (json, namespaced-json, pot, xliff, xliff2)')
.action((...args) => {
let command: Convert = new Convert();
command.run(...args);
示例10:
#!/usr/bin/env node
import * as path from 'path';
import * as program from 'commander';
import * as commands from '../commands';
program
.version(require('../../package.json').version);
program
.command('create <name>')
.alias('new')
.description('create new monogatari')
.action(commands.create);
program
.command('play <monogatari>')
.description('execute monogatari')
.option('-f, --hostsfile <hostsfile>', 'hosts file', 'hosts.yml')
.option('-k, --private-key <id_rsa>', 'ssh private key', path.resolve(process.env.HOME, '.ssh/id_rsa'))
.action(commands.play);
program.parse(process.argv);