本文整理汇总了TypeScript中yargs.Argv类的典型用法代码示例。如果您正苦于以下问题:TypeScript Argv类的具体用法?TypeScript Argv怎么用?TypeScript Argv使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Argv类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Map
[...commandMap.values()].forEach((command: CommandWrapper) => {
const { name, register, run } = command;
let aliases: Aliases = {};
const groupMap = new Map().set(groupName, commandMap);
yargs.command(
name,
false,
(optionsYargs: Argv) => {
register((key: string, options: Options) => {
aliases = parseAliases(aliases, key, options.alias);
optionsYargs.option(key, { ...options, ...requireOptions });
}, helper.sandbox(groupName, name));
return optionsYargs.showHelpOnFail(false, formatHelp({ _: [groupName, name] }, groupMap)).strict();
},
async (argv: any) => {
if (argv.h || argv.help) {
console.log(formatHelp(argv, groupMap));
return Promise.resolve({});
}
const config = helper.sandbox(groupName, name).configuration.get();
const args = getOptions(aliases, config, argv);
if (typeof command.validate === 'function') {
const valid = await command.validate(helper.sandbox(groupName, command.name));
if (!valid) {
return;
}
}
return run(helper.sandbox(groupName, name), args).catch(reportError);
}
);
});
示例2: parseAliases
(optionsYargs: Argv) => {
register((key: string, options: Options) => {
aliases = parseAliases(aliases, key, options.alias);
optionsYargs.option(key, { ...options, ...requireOptions });
}, helper.sandbox(groupName, name));
return optionsYargs.showHelpOnFail(false, formatHelp({ _: [groupName, name] }, groupMap)).strict();
},
示例3: registerGroups
function registerGroups(yargs: Argv, helper: HelperFactory, groupName: string, commandMap: CommandMap): void {
const groupMap = new Map().set(groupName, commandMap);
const defaultCommand = getCommand(groupMap, groupName);
let aliases: Aliases = {};
yargs.command(
groupName,
false,
(subYargs: Argv) => {
defaultCommand.register((key: string, options: Options) => {
aliases = parseAliases(aliases, key, options.alias);
subYargs.option(key, { ...options, ...requireOptions });
}, helper.sandbox(groupName, defaultCommand.name));
registerCommands(subYargs, helper, groupName, commandMap);
return subYargs
.option('h', {
alias: 'help'
})
.showHelpOnFail(false, formatHelp({ _: [groupName] }, groupMap))
.strict();
},
async (argv: any) => {
if (defaultCommand && argv._.length === 1) {
if (argv.h || argv.help) {
console.log(formatHelp(argv, groupMap));
return Promise.resolve({});
}
const config = helper.sandbox(groupName, defaultCommand.name).configuration.get();
const args = getOptions(aliases, config, argv);
if (typeof defaultCommand.validate === 'function') {
const valid = await defaultCommand.validate(helper.sandbox(groupName, defaultCommand.name));
if (!valid) {
return;
}
}
return defaultCommand.run(helper.sandbox(groupName, defaultCommand.name), args).catch(reportError);
}
}
);
}
示例4: function
module.exports = function(yargs: Argv) {
yargs.command('cluster', 'Check your clusters', function(
yargsCluster: Argv,
): Argv {
const configFile = process.env.HOME + '/.kube/config';
if (!fs.existsSync(configFile)) {
return;
}
const kc = new k8s.KubeConfig();
kc.loadFromFile(configFile);
const k8sApiCore = new k8s.Core_v1Api(kc.getCurrentCluster().server);
const k8sApiApps = new k8s.Apps_v1beta1Api(kc.getCurrentCluster().server);
k8sApiCore.setDefaultAuthentication(kc);
k8sApiApps.setDefaultAuthentication(kc);
k8sApiApps
.createNamespacedStatefulSet('default', loadState('mongodb'))
.then(function(value) {
console.log(value);
return;
})
.catch(function(err) {
console.error(err);
});
function loadState(name: string): V1beta2StatefulSet {
const state = new k8s.V1beta2StatefulSet();
const file = path.join(__dirname, 'stateful-set', `${name}.yml`);
const data = yaml.safeLoad(fs.readFileSync(file, 'utf8'));
_.extend(state, data);
return state;
}
return;
});
};
示例5: Error
> /* istanbul ignore next */ = (
yargs: Argv<PwArgvOptions>,
): Argv<PwHandlerOptions> =>
yargs
.positional('password', {
type: 'string',
})
.demand('password')
.check(argv => {
if (!argv.password.length) {
throw new Error('The password argument must not be empty.');
}
return true;
})
.option('r', {
alias: 'raw',
describe: 'disable the console spinner',
type: 'boolean',
default: false,
})
.group(['r'], 'Command Options:')
.group(['h', 'v'], 'Global Options:');
示例6: function
export default function(yargs: Argv, groupMap: GroupMap): void {
const helperContext = {};
const commandHelper = new CommandHelper(groupMap, helperContext, configurationHelperFactory);
const validateHelper = { validate: builtInCommandValidation }; // Provide the default validation helper
const helperFactory = new HelperFactory(
commandHelper,
yargs,
helperContext,
configurationHelperFactory,
validateHelper
);
groupMap.forEach((commandMap, group) => {
registerGroups(yargs, helperFactory, group, commandMap);
});
yargs
.demand(1, '')
.command(
'$0',
false,
(dojoYargs: Argv) => {
dojoYargs.option('h', {
alias: 'help'
});
return dojoYargs;
},
(argv: any) => {
console.log(formatHelp(argv, groupMap));
}
)
.check(createOptionValidator(groupMap), true)
.help(false)
.showHelpOnFail(false)
.strict().argv;
}
示例7:
(dojoYargs: Argv) => {
dojoYargs.option('h', {
alias: 'help'
});
return dojoYargs;
},