How to use the dashdash.createParser function in dashdash

To help you get started, we’ve selected a few dashdash 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 leapdao / solEVM-enforcer / challenger / cliArgs.js View on Github external
names: ['delay'],
    type: 'number',
    env: 'DELAY',
    help: 'Events handling delay (for temp setup)',
    default: 0,
  },
  {
    names: ['stupid'],
    type: 'bool',
    env: 'STUPID',
    help: 'Enables wrong results producing',
    default: false,
  },
];

const parser = dashdash.createParser({ options });

/**
 * @type {{
 *  ethProvider: string;
 *  walletPriv: string;
 *  enforcerAddr: string;
 *  delay: number;
 *  stupid: boolean;
 * }}
 */
const cliArgs = parser.parse(process.argv);

if (cliArgs.help) {
  console.log('Usage:');
  console.log(parser.help({ includeEnv: true }).trimRight());
  process.exit(0);
github sumanjs / suman / lib / runner-helpers / run-child.js View on Github external
var su = require("suman-utils");
var _suman = global.__suman = (global.__suman || {});
require('../helpers/add-suman-global-properties');
var constants = require('../../config/suman-constants').constants;
var fatalRequestReply = require('../helpers/general').fatalRequestReply;
if (process.env.NPM_COLORS === 'no') {
    process.argv.push('--no-color');
    console.log(' => Suman child process setting itself to be color-free (--no-colors)');
}
var sumanOpts = _suman.sumanOpts = _suman.sumanOpts || JSON.parse(process.env.SUMAN_OPTS);
var suman_options_1 = require("../parse-cmd-line-opts/suman-options");
var childArgs = sumanOpts.child_arg || [];
if (childArgs.length) {
    childArgs.unshift('foo');
    childArgs.unshift('baz');
    var opts = void 0, parser = dashdash.createParser({ options: suman_options_1.options });
    try {
        opts = parser.parse(childArgs);
    }
    catch (err) {
        console.error(chalk.red(' => Suman command line options error:'), err.message);
        console.error(' => Try "suman --help" or visit sumanjs.org');
        process.exit(constants.EXIT_CODES.BAD_COMMAND_LINE_OPTION);
    }
    sumanOpts = _suman.sumanOpts = Object.assign(sumanOpts, opts);
}
var usingRunner = _suman.usingRunner = true;
var projectRoot = _suman.projectRoot = process.env.SUMAN_PROJECT_ROOT;
process.send = process.send || function (data) {
    console.error(chalk.magenta('Suman warning:'));
    console.error('process.send() was not originally defined in this process.');
    console.error('(Perhaps we are using Istanbul?), we are logging the first argument to process.send() here => ');
github ThoughtWorksStudios / bobcat / index.js View on Github external
const Interpreter = require("./interpreter"),
  Scopes = require("./scope"),
  fs = require("fs"),
  dashdash = require("dashdash");

function die(message) {
  console.warn(message);
  process.exit(1);
}

var optParser = dashdash.createParser({
  options: [
    {
      names:["help", "h"],
      type: "bool",
      help: "Print usage and exit"
    },
    {
      names:["output", "o"],
      type: "string",
      help: "Output file",
      helpArg: "FILE",
      default: "entities.json"
    },
    {
      names: ["check", "c"],
      type: "bool",
github ORESoftware / npm-link-up / lib / commands / ls / index.ts View on Github external
import * as assert from "assert";
import * as fs from "fs";
import log from "../../logging";
import chalk from "chalk";
import {NLURunOpts} from "../run/cmd-line-opts";
import {EVCb, NluGlobalSettingsConf} from "../../index";
import options from "../run/cmd-line-opts";

const dashdash = require('dashdash');
import * as async from 'async';
import {handleConfigCLIOpt} from '../../utils';

const treeify = require('treeify');

const allowUnknown = process.argv.indexOf('--allow-unknown') > 0;
let opts: NLURunOpts, globalConf: NluGlobalSettingsConf, parser = dashdash.createParser({options, allowUnknown});

try {
  opts = parser.parse(process.argv);
} catch (e) {
  log.error(chalk.magenta('CLI parsing error:'), chalk.magentaBright.bold(e.message));
  process.exit(1);
}

if (opts.help) {
  let help = parser.help({includeEnv: true}).trimRight();
  console.log('usage: nlu run [OPTIONS]\n'
    + 'options:\n'
    + help);
  process.exit(0);
}
github ORESoftware / npm-link-up / lib / commands / init / index.ts View on Github external
import {makeFindProjects} from "./find-matching-projects";
import alwaysIgnore from './init-ignore';
import alwaysIgnoreThese from "../../always-ignore";
import {mapPaths} from "../../map-paths-with-env-vars";

process.once('exit', code => {
  log.info('Exiting with code:', code,'\n');
});

if (!root) {
  log.error('Cannot find a project root given your current working directory:', chalk.magenta(cwd));
  log.error(' => NLU could not find a package.json file within your cwd.');
  process.exit(1);
}

let opts: NLUInitOpts, parser = dashdash.createParser({options});

try {
  opts = parser.parse(process.argv);
} catch (e) {
  log.error(chalk.magenta(' => CLI parsing error:'), chalk.magentaBright.bold(e.message));
  process.exit(1);
}

if (opts.help) {
  let help = parser.help({includeEnv: true}).trimRight();
  console.log('usage: nlu init [OPTIONS]\n' + 'options:\n' + help);
  process.exit(0);
}

let pkgJSON: any;
github ORESoftware / npm-link-up / lib / commands / basic / index.ts View on Github external
});

if (!root) {
  log.error('Cannot find a project root given your current working directory:', chalk.magenta(cwd));
  log.error(' => NLU could not find a package.json file within your cwd.');
  process.exit(1);
}

const commands = [
  'nlu run',
  'nlu init',
  'nlu add'
];

const allowUnknown = process.argv.indexOf('--allow-unknown') > 0;
let opts: any, parser = dashdash.createParser({options, allowUnknown});

try {
  opts = parser.parse(process.argv);
} catch (e) {
  log.error(chalk.magenta('CLI parsing error:'), chalk.magentaBright.bold(e.message));
  log.warn(chalk.gray('Perhaps you meant to use on of these commands instead:', chalk.gray.bold(commands.join(', '))));
  process.exit(1);
}

if (opts.version) {
  if(opts.json){
    stdio.log(npmLinkUpPkg.version);
  }
  else{
    console.log(npmLinkUpPkg.version);
  }
github joyent / node-nfs / mount.js View on Github external
(function main() {
    var log;
    var opts;
    var parser = dashdash.createParser({options: CLI_OPTIONS});
    var server;

    try {
        opts = parser.parse(process.argv);
    } catch (e) {
        console.error('mount: error: %s', e.message);
        process.exit(1);
    }

    if (opts.help) {
        var help = parser.help({includeEnv: true}).trimRight();
        console.log('usage: mount [OPTIONS]\n options:\n' + help);
        process.exit(0);
    }

    log = bunyan.createLogger({
github ORESoftware / npm-link-up / lib / commands / run / index.ts View on Github external
import {createTree} from '../../create-visual-tree';
import {getCleanMap} from '../../get-clean-final-map';
import {q} from '../../search-queue';
import npmLinkUpPkg = require('../../../package.json');
import {EVCb, NluMap, NLURunOpts} from "../../npmlinkup";
import {determineIfReinstallIsNeeded, getDevKeys, getProdKeys, validateConfigFile, validateOptions} from "../../utils";

//////////////////////////////////////////////////////////////////////////

process.once('exit', function (code) {
  log.info('NLU is exiting with code:', code, '\n');
});

//////////////////////////////////////////////////////////////

let opts: NLURunOpts, parser = dashdash.createParser({options});

try {
  opts = parser.parse(process.argv);
} catch (e) {
  log.error(chalk.magenta(' => CLI parsing error:'), chalk.magentaBright.bold(e.message));
  process.exit(1);
}

if (opts.help) {
  let help = parser.help({includeEnv: true}).trimRight();
  console.log('usage: nlu run [OPTIONS]\n'
    + 'options:\n'
    + help);
  process.exit(0);
}
github DonutEspresso / base-n / bin / cli.js View on Github external
help: 'Optional. Set of characters to encode with'
    },
    {
        names: ['base'],
        type: 'number',
        help: 'Optional. The base to encode/decode with'
    },
    {
        names: ['length'],
        type: 'number',
        help: 'Optional. maximum length of encoded ouptut.'
    }
];


var parser = dashdash.createParser({
    allowUnknown: true,
    options: options
});

function showHelp(opts) {
    var help = parser.help({includeEnv: true}).trimRight();
    console.log('usage: basen [action] [value] [OPTIONS]\n\n'
            + 'action: encode | decode\n'
            + 'value: Number or string to encode/decode\n'
            + 'options:\n'
            + help);
}


try {
    var opts = parser.parse(process.argv);
github kapouer / node-webkitgtk / bin / webkitgtk.js View on Github external
#!/usr/bin/node

var dash = require('dashdash');
var repl = require('repl');
var URL = require('url');
var Path = require('path');
var chalk;
try {
	chalk = require('chalk');
} catch(e) {
	chalk = {};
	['gray', 'red', 'green', 'red'].forEach(function(col) {
		chalk[col] = function(str) { return str; };
	});
}
var parser = dash.createParser({options: [
	{
		names: ['help', 'h'],
		type: 'bool',
		help: 'Print this help and exit.'
	},
	{
		names: ['location', 'l'],
		type: 'bool',
		help: 'Sets only location without actually loading the page'
	},
	{
		names: ['allow-file-access-from-file-urls', 'local-access'],
		type: 'bool',
		help: 'Allow local access from file uris - useful to do local xhr'
	},
	{

dashdash

A light, featureful and explicit option parsing library.

MIT
Latest version published 4 years ago

Package Health Score

67 / 100
Full package analysis