How to use mri - 10 common examples

To help you get started, we’ve selected a few mri 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 cacjs / cac / src / CAC.ts View on Github external
// All added options
    const cliOptions = [
      ...this.globalCommand.options,
      ...(command ? command.options : [])
    ]
    const mriOptions = getMriOptions(cliOptions)

    // Extract everything after `--` since mri doesn't support it
    let argsAfterDoubleDashes: string[] = []
    const doubleDashesIndex = argv.indexOf('--')
    if (doubleDashesIndex > -1) {
      argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1)
      argv = argv.slice(0, doubleDashesIndex)
    }

    const parsed = mri(argv, mriOptions)

    const args = parsed._
    delete parsed._

    const options: { [k: string]: any } = {
      '--': argsAfterDoubleDashes
    }

    // Set option default value
    const ignoreDefault =
      command && command.config.ignoreOptionDefaultValue
        ? command.config.ignoreOptionDefaultValue
        : this.globalCommand.config.ignoreOptionDefaultValue

    let transforms = Object.create(null)
github zeit / now / packages / now-cli / src / commands / projects.js View on Github external
const main = async ctx => {
  argv = mri(ctx.argv.slice(2), {
    boolean: ['help'],
    alias: {
      help: 'h',
    },
  });

  argv._ = argv._.slice(1);

  debug = argv.debug;
  apiUrl = ctx.apiUrl;
  subcommand = argv._[0];

  if (argv.help || !subcommand) {
    help();
    await exit(0);
  }
github zeit / now / src / commands / whoami.js View on Github external
const main = async ctx => {
  argv = mri(ctx.argv.slice(2), {
    boolean: ['help', 'debug', 'all'],
    alias: {
      help: 'h',
      debug: 'd'
    }
  });

  argv._ = argv._.slice(1);

  if (argv.help || argv._[0] === 'help') {
    help();
    process.exit(0);
  }

  const debug = argv['--debug'];
  const { authConfig: { token }, apiUrl } = ctx;
github zeit / now / packages / now-cli / src / commands / logout.js View on Github external
const main = async ctx => {
  argv = mri(ctx.argv.slice(2), {
    boolean: ['help'],
    alias: {
      help: 'h'
    }
  });

  apiUrl = ctx.apiUrl;
  argv._ = argv._.slice(1);

  if (argv.help || argv._[0] === 'help') {
    help();
    await exit(0);
  }

  logout();
};
github WeAreGenki / minna-ui / utils / build-css / src / index.ts View on Github external
export async function run(
  env: NodeJS.ProcessEnv,
  argv: string[] = [],
): Promise {
  const args = mri(argv.slice(ARGS_START), {
    alias: { b: 'banner', h: 'help', m: 'sourcemap' },
    boolean: ['banner', 'help', 'sourcemap'],
    default: { b: true, m: true },
  });
  const { help, banner: hasBanner, sourcemap } = args;

  if (help) {
    console.log(`
Build CSS. Typically zero additional configuration is required because your
package.json is the config.

USAGE:
  build-css [src] [dest] [options]

OPTIONS
  -h --help       Print this help message and exit.
github vutran / dslint / src / utils / utils.ts View on Github external
export function getConfig(): DSLint.Configuration {
  const argv = process.argv.slice(2);
  const args = mri(argv);
  return {
    fileKey: args._.join(''),
    teamId: args.teamId,
  };
}
github Rich-Harris / degit / src / bin.js View on Github external
import fs from 'fs';
import path from 'path';
import chalk from 'chalk';
import mri from 'mri';
import degit from 'degit';

const args = mri(process.argv.slice(2), {
	alias: {
		f: 'force',
		c: 'cache',
		v: 'verbose'
	},
	boolean: ['force', 'cache', 'verbose']
});

const [src, dest = '.'] = args._;

if (args.help || !src) {
	const help = fs.readFileSync(path.join(__dirname, 'help.md'), 'utf-8')
		.replace(/^(\s*)#+ (.+)/gm, (m, s, _) => s + chalk.bold(_))
		.replace(/_([^_]+)_/g, (m, _) => chalk.underline(_))
		.replace(/`([^`]+)`/g, (m, _) => chalk.cyan(_));
github zeit / now / packages / now-cli / src / commands / teams.js View on Github external
const main = async ctx => {
  argv = mri(ctx.argv.slice(2), {
    boolean: ['help', 'debug'],
    alias: {
      help: 'h',
      debug: 'd',
      switch: 'change'
    }
  });

  debug = argv.debug;
  apiUrl = ctx.apiUrl;

  const isSwitch = argv._[0] && argv._[0] === 'switch';

  argv._ = argv._.slice(1);

  if (isSwitch) {
github zeit / now / packages / now-cli / src / commands / secrets.js View on Github external
const main = async ctx => {
  argv = mri(ctx.argv.slice(2), {
    boolean: ['help', 'debug', 'yes'],
    alias: {
      help: 'h',
      debug: 'd',
      yes: 'y',
    },
  });

  argv._ = argv._.slice(1);

  debug = argv.debug;
  apiUrl = ctx.apiUrl;
  subcommand = argv._[0];

  if (argv.help || !subcommand) {
    help();

mri

Quickly scan for CLI flags and arguments

MIT
Latest version published 3 years ago

Package Health Score

67 / 100
Full package analysis

Popular mri functions