How to use the yargs-parser function in yargs-parser

To help you get started, we’ve selected a few yargs-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github umijs / umi / packages / umi / src / scripts / realDev.js View on Github external
// kill(2) Ctrl-C
process.once('SIGINT', () => onSignal('SIGINT'));
// kill(3) Ctrl-\
process.once('SIGQUIT', () => onSignal('SIGQUIT'));
// kill(15) default
process.once('SIGTERM', () => onSignal('SIGTERM'));

function onSignal() {
  if (closed) return;
  closed = true;
  process.exit(0);
}

process.env.NODE_ENV = 'development';

const args = yParser(process.argv.slice(2));
const Service = require('umi-build-dev/lib/Service').default;
new Service(buildDevOpts(args)).run('dev', args);
github umijs / umi / packages / umi / src / cli.js View on Github external
import { dirname } from 'path';
import yParser from 'yargs-parser';
import signale from 'signale';
import semver from 'semver';
import ora from 'ora';
import buildDevOpts from './buildDevOpts';

const spinner = ora();

const script = process.argv[2];
const args = yParser(process.argv.slice(3));

// Node version check
const nodeVersion = process.versions.node;
if (semver.satisfies(nodeVersion, '<6.5')) {
  signale.error(`Node version must >= 6.5, but got ${nodeVersion}`);
  process.exit(1);
}
spinner.start('🏃 parsing parameters');

// Notify update when process exits
const updater = require('update-notifier');
const pkg = require('../package.json');
updater({ pkg }).notify({ defer: true });

process.env.UMI_DIR = dirname(require.resolve('../package'));
process.env.UMI_VERSION = pkg.version;
github magicmark / composerize / src / index.js View on Github external
export default (input: string): ?string => {
    const formattedInput = input.replace(/(\s)+/g, ' ').trim();
    const parsedInput: {
        +_: Array,
        +[flag: string]: RawValue,
    } = parser(formattedInput);
    const { _: command, ...params } = parsedInput;

    if (
        command[0] !== 'docker' ||
        (command[1] !== 'run' && command[1] !== 'create')
    ) {
        throw new SyntaxError('must be a valid docker run/create command');
    }

    // The service object that we'll update
    let service = {};

    // Loop through the tokens and append to the service object
    Object.entries(params).forEach(
        // https://github.com/facebook/flow/issues/2174
        // $FlowFixMe: Object.entries wipes out types ATOW
github milesj / build-tool-config / rollup.js View on Github external
/* eslint-disable no-param-reassign, comma-dangle, no-magic-numbers, dot-notation */

import fs from 'fs';
import path from 'path';
import JSON5 from 'json5';
import babel from 'rollup-plugin-babel';
import common from 'rollup-plugin-commonjs';
import json from 'rollup-plugin-json';
import replace from 'rollup-plugin-replace';
import resolve from 'rollup-plugin-node-resolve';
import uglify from 'rollup-plugin-uglify';
import yargs from 'yargs-parser';

const options = yargs(process.argv.slice(2));
const extensions = ['.js', '.jsx', '.json'];

// Modify Babel config a bit
const babelConfig = JSON5.parse(fs.readFileSync(
  path.join(__dirname, `babel${options.node ? '.node' : ''}.json5`)
));

babelConfig.presets.forEach((preset) => {
  if (Array.isArray(preset) && preset[0] === 'env') {
    preset[1].modules = false;
  }
});

babelConfig.exclude = 'node_modules/**';
babelConfig.runtimeHelpers = (babelConfig.plugins.indexOf('transform-runtime') >= 0);
github beemojs / beemo / packages / core / src / testUtils.ts View on Github external
export function applyContext(context: T): T {
  context.args = parseArgs(['-a', '--foo', 'bar', 'baz']);
  context.argv = ['-a', '--foo', 'bar', 'baz'];
  context.cwd = BEEMO_TEST_ROOT;
  context.moduleRoot = BEEMO_TEST_ROOT;
  context.workspaceRoot = BEEMO_TEST_ROOT;
  context.workspaces = [];

  return context;
}
github beemojs / beemo / tests / helpers.ts View on Github external
export function applyContext(context: T): T {
  context.args = parseArgs(['-a', '--foo', 'bar', 'baz']);
  context.argv = ['-a', '--foo', 'bar', 'baz'];
  context.cwd = __dirname;
  context.moduleRoot = __dirname;
  context.workspaceRoot = __dirname;
  context.workspaces = [];

  return context;
}
github krakenjs / grabthar / test / lib / mocks.js View on Github external
mockChildProcessExec = (command, opts, callback) => {
        let { _ : args, ...options } = yargsParser(command);
        let cmd = { args, opts: options };

        let res = async (text) => {
            if (!callback) {
                throw new Error(`Expected callback to be passed`);
            }
            callback(null, text, '');
            await nextTick();
        };

        let err = async (message) => {
            if (!callback) {
                throw new Error(`Expected callback to be passed`);
            }
            callback(null, '', message);
            await nextTick();
github csegames / Camelot-Unchained / game / hud / src / services / initialization / slashCommands / utils.ts View on Github external
export const parseArgs = (args: string): any => yargs(args);
export const systemMessage = (message: string | Object): void => {
github Fitbit / webpack-config / src / ConfigArgv.js View on Github external
import argvParser from 'yargs-parser';

/**
 * @private
 * @type {Object}
 */
const argv = argvParser(process.argv.slice(2));

export default argv;

yargs-parser

the mighty option parser used by yargs

ISC
Latest version published 2 years ago

Package Health Score

77 / 100
Full package analysis