當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。