当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Argv.command方法代码示例

本文整理汇总了TypeScript中yargs.Argv.command方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Argv.command方法的具体用法?TypeScript Argv.command怎么用?TypeScript Argv.command使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yargs.Argv的用法示例。


在下文中一共展示了Argv.command方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
			}
		);
	});
开发者ID:dojo,项目名称:cli,代码行数:34,代码来源:registerCommands.ts

示例2: 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);
			}
		}
	);
}
开发者ID:dojo,项目名称:cli,代码行数:41,代码来源:registerCommands.ts

示例3: 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;
  });
};
开发者ID:agneta,项目名称:platform,代码行数:39,代码来源:index.ts


注:本文中的yargs.Argv.command方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。