How to use subarg - 9 common examples

To help you get started, we’ve selected a few subarg 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 alekseykulikov / browserify-test / src / cli.js View on Github external
// cli

program
.version(pkg.version)
.usage('[options] [./test/*.js ...]')
.option('-w, --watch', 'run watch server on http://localhost:7357')
.option('-t, --transform ', 'add browserify transforms')
.option('-p, --plugins ', 'add browserify plugins')
.option('-b, --browserifyOptions ', 'add browserifyOptions', JSON.parse)
.option('--testem, --testemOptions ', 'add testemOptions', JSON.parse)
.parse(process.argv)

// prepare files

const argv = subarg(process.argv.slice(2), {
  alias: { t: 'transform', transforms: 'transform', p: 'plugins', w: 'watch', testem: 'testemOptions' },
  boolean: ['watch']
})
const files = []
if (!argv._.length) argv._ = ['./test/*.js']
argv._.forEach((p) => files.push(...glob.sync(p)))

// parse transforms

const transform = []
if (argv.transform) {
  if (!Array.isArray(argv.transform)) argv.transform = [argv.transform]
  argv.transform.forEach((tr) => {
    if (typeof tr === 'string') {
      transform.push(tr)
    } else if (Array.isArray(tr._)) {
github mysticatea / cpx / src / command.js View on Github external
`;

// {Shorname: Fullname}
const OPTIONS = {
  "c": "command",
  "C": "clean",
  "h": "help",
  "t": "transform",
  "v": "verbose",
  "V": "version",
  "w": "watch"
};

//------------------------------------------------------------------------------
// Parse arguments.
const args = subarg(process.argv.slice(2), {
  boolean: ["clean", "help", "verbose", "version", "watch"],
  alias: OPTIONS
});

//------------------------------------------------------------------------------
// Validate Options.
const knowns = new Set(["_"]);
for (let key in OPTIONS) {
  knowns.add(key);
  knowns.add(OPTIONS[key]);
}
const unknowns = Object.keys(args).filter(key => !knowns.has(key));
if (unknowns.length > 0) {
  console.error(`Unknown option(s): ${unknowns.join(", ")}`);
  process.exit(1);
}
github radiovisual / timecard / lib / cli.js View on Github external
if (_cmd.is('print')) {
		command = timecard.print;
	}

  // Now we are clear to call the API.
	command.call(timecard, message).then(response => {
		console.log(response);
	}).catch(err => {
		console.log(err);
	});
}

updateNotifier({pkg: cli.pkg}).notify();

init(subarg(cli.input)._, cli.flags);
github forivall / tacoscript / packages / tacoscript / src / cli / commands / _node.js View on Github external
const opts = cloneDeep(baseArgs);
  opts.boolean.push();
  opts.string.push("extensions");
  opts.alias["extensions"] = ["x"];
  opts.alias["plugin"] = ["p"];
  opts.alias["eval"] = ["e", "exec"];
  opts.alias["compile"] = ["c"];
  opts.alias["print"] = ["o"];
  opts.default = omit(defaults, "_");
  opts.unknown = (arg) => {
    const match = /^--([^=]+)=/.exec(arg) || /^--(?:no-)(.+)/.exec(arg);
    if (match) comalUnknownOptionNames.push(match[1]);
  };
  opts.stopEarly = true;

  const args = subarg(argv, argsWithComalOpts(comalCoreOptions, opts));

  const comalOpts = camelize(pick(args, comalCoreOptionNames, comalUnknownOptionNames));

  if (args.plugin) {
    try { comalOpts.plugins = convertPluginOpts(args.plugin) }
    catch (e) { return cb(e); }
  }

  if (args.extensions) {
    comalOpts.only = (comalOpts.only ? comalOpts.only + "," : "") +
      map(args.extensions.split(","), (e) => "*" + e).join(",");
  }

  comalOpts.compile = args.compile;

  /// RUN
github forivall / tacoscript / packages / tacoscript / src / cli / transform.js View on Github external
run(argv, cb) {
    if (includes(argv, "--help") || includes(argv, "-h")) {
      if (subarg(argv, {alias: {"help": ["h"]}}).help === "advanced") {
        return usageAdvanced(comalCoreOptions, cb);
      } else {
        return usage(this.name, cb);
      }
    }

    this.parseArgs(argv);
    const args = this.args;

    // normalize input arguments
    this.infiles = args._;
    const useStdin = this.infiles.length === 0;

    // normalize output arguments
    this.outfiles = args.outfile == null ? [] : [].concat(args.outfile);
    const useStdout = this.outfiles.length === 0;
github forivall / tacoscript / packages / tacoscript / src / cli / commands / node.js View on Github external
export default function(defaults, argv, cb) {
  if (includes(argv, "--help") || includes(argv, "-h")) {
    if (subarg(argv, {alias: {"help": ["h"]}}).help === "advanced") {
      return usageAdvanced(comalCoreOptions, cb);
    } else {
      return usage("node", cb);
    }
  }

  const cmd = [scriptPath];

  // convert defaults into appropriate arguments
  if (defaults["debug-internal"]) cmd.push("--debug-internal");
  if (defaults["verbose"]) cmd.push("--verbose");
  if (defaults["quiet"]) cmd.push("--quiet");

  const nodeFlags = [];
  const argSeparator = argv.indexOf("--");
  const combinedArgs = argSeparator > -1 ? argv.slice(argSeparator) : argv;
github forivall / tacoscript / packages / tacoscript / src / cli / transform.js View on Github external
parseArgs(argv) {
    const comalUnknownOptionNames = [];
    const minimistOpts = argsWithComalOpts(comalCoreOptions, {
      ...this.opts,
      default: {...this.defaults, ...this.opts.default},
      unknown(arg) {
        const match = /^--([^=]+)=/.exec(arg) || /^--(?:no-)?(.+)/.exec(arg);
        if (match) comalUnknownOptionNames.push(match[1]);
      }
    });
    const args = this.args = subarg(argv, minimistOpts);

    this.comalOpts = camelize(pick(args, comalCoreOptionNames, comalUnknownOptionNames));
  }
github mike-engel / bkmrkd / server.js View on Github external
import helmet from 'helmet'
import rethink from 'rethinkdb'
import React from 'react'
import { renderToString } from 'react-dom/server'
import { createStore, compose, combineReducers } from 'redux'
import { Provider } from 'react-redux'
import { ReduxRouter, routerStateReducer } from 'redux-router'
import { match, reduxReactRouter } from 'redux-router/server'
import escape from 'lodash.escape'
import subarg from 'subarg'
import defaultConfig from './config/environments'
import bkmrkdRoutes from './src/js/main'
import { bookmarks, endOfBookmarks, networkState, page, toaster } from './src/js/helpers/reducers'

const env = process.env.NODE_ENV || 'development'
const args = subarg(process.argv.slice(2))
const config = args.c || args.config || process.env.BKMRKD_CONFIG_PATH ? readConfig() : defaultConfig
const port = config[env].port || args.p || args.port || 3000
const spdyOptions = {
  key: fs.readFileSync(config[env].certKey),
  cert: fs.readFileSync(config[env].cert)
}

export const app = express()
export const server = spdy.createServer(spdyOptions, app)
const io = socketIO(server)

let connection
let bkmrkd

function readConfig () {
  return fs.readFileSync(path.resolve(process.cwd(), args.c || args.config || process.env.BKMRKD_CONFIG_PATH), {
github mike-engel / bkmrkd / helpers / config.js View on Github external
import fs from 'fs'
import path from 'path'
import subarg from 'subarg'
import defaultConfig from '../config/environments'

export const args = subarg(process.argv.slice(2))

function readConfig () {
  return JSON.parse(fs.readFileSync(path.resolve(process.cwd(), args.c || args.config || process.env.BKMRKD_CONFIG_PATH), {
    encoding: 'utf8'
  }))
}

export default (args.c || args.config || process.env.BKMRKD_CONFIG_PATH ? readConfig() : defaultConfig)

subarg

parse arguments with recursive contexts

MIT
Latest version published 10 years ago

Package Health Score

65 / 100
Full package analysis

Popular subarg functions