當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript getopts.default函數代碼示例

本文整理匯總了TypeScript中getopts.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了default函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getFlags

export function getFlags(argv: string[], options: Options): Flags {
  const unexpected: string[] = [];
  const flagOpts = options.flags || {};

  const { verbose, quiet, silent, debug, help, _, ...others } = getopts(argv, {
    string: flagOpts.string,
    boolean: [...(flagOpts.boolean || []), 'verbose', 'quiet', 'silent', 'debug', 'help'],
    alias: {
      ...(flagOpts.alias || {}),
      v: 'verbose',
    },
    default: flagOpts.default,
    unknown: (name: string) => {
      unexpected.push(name);

      if (options.flags && options.flags.allowUnexpected) {
        return true;
      }

      return false;
    },
  } as any);

  return {
    verbose,
    quiet,
    silent,
    debug,
    help,
    _,
    unexpected,
    ...others,
  };
}
開發者ID:njd5475,項目名稱:kibana,代碼行數:34,代碼來源:flags.ts

示例2: runTypeCheckCli

export function runTypeCheckCli() {
  const extraFlags: string[] = [];
  const opts = getopts(process.argv.slice(2), {
    boolean: ['skip-lib-check', 'help'],
    default: {
      project: undefined,
    },
    unknown(name) {
      extraFlags.push(name);
      return false;
    },
  });

  const log = new ToolingLog({
    level: 'info',
    writeTo: process.stdout,
  });

  if (extraFlags.length) {
    for (const flag of extraFlags) {
      log.error(`Unknown flag: ${flag}`);
    }

    process.exitCode = 1;
    opts.help = true;
  }

  if (opts.help) {
    process.stdout.write(
      dedent(chalk`
        {dim usage:} node scripts/type_check [...options]

        Run the TypeScript compiler without emitting files so that it can check
        types during development.

        Examples:

          {dim # check types in all projects}
          {dim $} node scripts/type_check

          {dim # check types in a single project}
          {dim $} node scripts/type_check --project packages/kbn-pm/tsconfig.json

        Options:

          --project [path]    {dim Path to a tsconfig.json file determines the project to check}
          --skip-lib-check    {dim Skip type checking of all declaration files (*.d.ts)}
          --help              {dim Show this message}
      `)
    );
    process.stdout.write('\n');
    process.exit();
  }

  const tscArgs = ['--noEmit', '--pretty', ...(opts['skip-lib-check'] ? ['--skipLibCheck'] : [])];
  const projects = filterProjectsByFlag(opts.project);

  if (!projects.length) {
    log.error(`Unable to find project at ${opts.project}`);
    process.exit(1);
  }

  execInProjects(log, projects, 'tsc', project => ['--project', project.tsConfigPath, ...tscArgs]);
}
開發者ID:austec-automation,項目名稱:kibana,代碼行數:64,代碼來源:run_type_check_cli.ts

示例3: run

async function run(folder: string): Promise<boolean> {
  const log = new ToolingLog({
    level: 'info',
    writeTo: process.stdout,
  });

  const extraFlags: string[] = [];
  const opts = getopts(process.argv.slice(2), {
    boolean: ['accept', 'docs', 'help'],
    default: {
      project: undefined,
    },
    unknown(name) {
      extraFlags.push(name);
      return false;
    },
  });

  if (extraFlags.length > 0) {
    for (const flag of extraFlags) {
      log.error(`Unknown flag: ${flag}`);
    }

    opts.help = true;
  }

  if (opts.help) {
    process.stdout.write(
      dedent(chalk`
        {dim usage:} node scripts/check_core_api_changes [...options]

        Checks for any changes to the Kibana Core API

        Examples:

          {dim # Checks for any changes to the Kibana Core API}
          {dim $} node scripts/check_core_api_changes

          {dim # Checks for any changes to the Kibana Core API and updates the documentation}
          {dim $} node scripts/check_core_api_changes --docs

          {dim # Checks for and automatically accepts and updates documentation for any changes to the Kibana Core API}
          {dim $} node scripts/check_core_api_changes --accept

        Options:
          --accept    {dim Accepts all changes by updating the API Review files and documentation}
          --docs      {dim Updates the Core API documentation}
          --help      {dim Show this message}
      `)
    );
    process.stdout.write('\n');
    return !(extraFlags.length > 0);
  }

  log.info(`Core ${folder} API: checking for changes in API signature...`);

  try {
    await runBuildTypes();
  } catch (e) {
    log.error(e);
    return false;
  }

  const { apiReportChanged, succeeded } = runApiExtractor(log, folder, opts.accept);

  // If we're not accepting changes and there's a failure, exit.
  if (!opts.accept && !succeeded) {
    return false;
  }

  // Attempt to generate docs even if api-extractor didn't succeed
  if ((opts.accept && apiReportChanged) || opts.docs) {
    try {
      await renameExtractedApiPackageName(folder);
      await runApiDocumenter(folder);
    } catch (e) {
      log.error(e);
      return false;
    }
    log.info(`Core ${folder} API: updated documentation ✔`);
  }

  // If any errors or warnings occured, exit with an error
  return succeeded;
}
開發者ID:horacimacias,項目名稱:kibana,代碼行數:85,代碼來源:run_check_core_api_changes.ts

示例4: getopts

import getopts, { ParsedOptions, Options } from "getopts"

const options: Options = {
  alias: {
    w: "warp",
    t: "turbo"
  },
  boolean: ["turbo"],
  default: {
    turbo: true
  }
}

const parsedOptions: ParsedOptions = getopts(["-w10"], options)

console.log(parsedOptions)
開發者ID:bucaran,項目名稱:parsec,代碼行數:16,代碼來源:index.ts

示例5: readCliArgs

export function readCliArgs(argv: string[]): ParsedArgs {
  const unknownFlags: string[] = [];
  const flags = getopts(argv, {
    boolean: [
      'oss',
      'no-oss',
      'skip-archives',
      'skip-os-packages',
      'rpm',
      'deb',
      'docker',
      'release',
      'skip-node-download',
      'verbose',
      'debug',
      'all-platforms',
      'verbose',
      'quiet',
      'silent',
      'debug',
      'help',
    ],
    alias: {
      v: 'verbose',
      d: 'debug',
    },
    default: {
      debug: true,
      rpm: null,
      deb: null,
      docker: null,
      oss: null,
      'version-qualifier': '',
    },
    unknown: flag => {
      unknownFlags.push(flag);
      return false;
    },
  });

  if (unknownFlags.length || flags.help) {
    return {
      showHelp: true,
      unknownFlags,
    };
  }

  // In order to build a docker image we always need
  // to generate all the platforms
  if (flags.docker) {
    flags['all-platforms'] = true;
  }

  const log = new ToolingLog({
    level: pickLevelFromFlags(flags, {
      default: flags.debug === false ? 'info' : 'debug',
    }),
    writeTo: process.stdout,
  });

  function isOsPackageDesired(name: string) {
    if (flags['skip-os-packages'] || !flags['all-platforms']) {
      return false;
    }

    // build all if no flags specified
    if (flags.rpm === null && flags.deb === null && flags.docker === null) {
      return true;
    }

    return Boolean(flags[name]);
  }

  return {
    showHelp: false,
    unknownFlags: [],
    log,
    buildArgs: {
      isRelease: Boolean(flags.release),
      versionQualifier: flags['version-qualifier'],
      buildOssDist: flags.oss !== false,
      buildDefaultDist: !flags.oss,
      downloadFreshNode: !Boolean(flags['skip-node-download']),
      createArchives: !Boolean(flags['skip-archives']),
      createRpmPackage: isOsPackageDesired('rpm'),
      createDebPackage: isOsPackageDesired('deb'),
      createDockerPackage: isOsPackageDesired('docker'),
      targetAllPlatforms: Boolean(flags['all-platforms']),
    },
  };
}
開發者ID:elastic,項目名稱:kibana,代碼行數:91,代碼來源:args.ts

示例6: runTslintCli

export function runTslintCli(projects = PROJECTS) {
  const log = createToolingLog('info');
  log.pipe(process.stdout);

  const opts = getopts(process.argv.slice(2));

  if (!opts.format) {
    process.argv.push('--format', 'stylish');
  }

  const list = new Listr(
    projects
      .filter(project => {
        if (!opts.project) {
          return true;
        }

        return resolve(opts.project) === project.tsConfigPath;
      })
      .map(project => ({
        task: () =>
          execa('tslint', [...process.argv.slice(2), '--project', project.tsConfigPath], {
            cwd: project.directory,
            env: chalk.enabled ? { FORCE_COLOR: 'true' } : {},
            stdio: ['ignore', 'pipe', 'pipe'],
          }).catch(error => {
            throw new LintFailure(project, error);
          }),
        title: project.name,
      })),
    {
      concurrent: true,
      exitOnError: false,
    }
  );

  list.run().catch((error: any) => {
    process.exitCode = 1;

    if (!error.errors) {
      log.error('Unhandled execption!');
      log.error(error);
      process.exit();
    }

    for (const e of error.errors) {
      if (e instanceof LintFailure) {
        log.write('');
        log.error(`${e.project.name} failed\n${e.error.stdout}`);
      } else {
        log.error(e);
      }
    }
  });
}
開發者ID:Jaaess,項目名稱:kibana,代碼行數:55,代碼來源:run_tslint_cli.ts

示例7: runCommand

export async function run(argv: string[]) {
  // We can simplify this setup (and remove this extra handling) once Yarn
  // starts forwarding the `--` directly to this script, see
  // https://github.com/yarnpkg/yarn/blob/b2d3e1a8fe45ef376b716d597cc79b38702a9320/src/cli/index.js#L174-L182
  if (argv.includes('--')) {
    console.log(
      chalk.red(
        `Using "--" is not allowed, as it doesn't work with 'yarn kbn'.`
      )
    );
    process.exit(1);
  }

  const options = getopts(argv, {
    alias: {
      h: 'help',
      i: 'include',
      e: 'exclude',
    },
  });

  const args = options._;

  if (options.help || args.length === 0) {
    help();
    return;
  }

  // This `rootPath` is relative to `./dist/` as that's the location of the
  // built version of this tool.
  const rootPath = resolve(__dirname, '../../../');

  const commandName = args[0];
  const extraArgs = args.slice(1);

  const commandOptions = { options, extraArgs, rootPath };

  const command = commands[commandName];
  if (command === undefined) {
    console.log(
      chalk.red(`[${commandName}] is not a valid command, see 'kbn --help'`)
    );
    process.exit(1);
  }

  await runCommand(command, commandOptions);
}
開發者ID:cccnam5158,項目名稱:kibana,代碼行數:47,代碼來源:cli.ts

示例8: runTslintCli

export function runTslintCli(projects?: Project[]) {
  const log = new ToolingLog({
    level: 'info',
    writeTo: process.stdout,
  });

  const opts = getopts(process.argv.slice(2));
  projects = projects || filterProjectsByFlag(opts.project);

  if (!opts.format) {
    process.argv.push('--format', 'stylish');
  }

  const getProjectArgs = (project: Project) => [
    ...process.argv.slice(2),
    '--project',
    project.tsConfigPath,
  ];

  execInProjects(log, projects, 'tslint', getProjectArgs);
}
開發者ID:austec-automation,項目名稱:kibana,代碼行數:21,代碼來源:run_tslint_cli.ts


注:本文中的getopts.default函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。