yargs#Choices TypeScript Examples

The following examples show how to use yargs#Choices. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: module.app-args.ts    From multi-downloader-nx with MIT License 6 votes vote down vote up
getArgv = (cfg: { [key:string]: unknown }) => {
  const parseDefault = <T = unknown>(key: string, _default: T) : T=> {
    if (Object.prototype.hasOwnProperty.call(cfg, key)) {
      return cfg[key] as T;
    } else
      return _default;
  };
      
  const argv = yargs.parserConfiguration({
    'duplicate-arguments-array': false,
    'camel-case-expansion': false,
  })
    .wrap(yargs.terminalWidth())
    .usage('Usage: $0 [options]')
    .help(true).version(false);
  const data = args.map(a => {
    return {
      ...a,
      group: groups[a.group],
      default: typeof a.default === 'object' && !Array.isArray(a.default) ? 
        parseDefault(a.default.name || a.name, a.default.default) : a.default
    };
  });
  for (const item of data)
    argv.option(item.name, {
      ...item,
      choices: item.choices as unknown as Choices
    });
  return argv as unknown as yargs.Argv<typeof argvC>;
}