How to use argparse - 10 common examples

To help you get started, we’ve selected a few argparse 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 TypeStrong / atom-typescript / node_modules / tsconfig / node_modules / js-yaml / node_modules / argparse / examples / testformatters.js View on Github external
var assert = require('assert');
var _ = require('underscore');
_.str = require('underscore.string');
var print = function () {
    return console.log.apply(console, arguments);
  };
// print = function () {};

var argparse = require('argparse');

print("TEST argparse.ArgumentDefaultsHelpFormatter");

parser = new argparse.ArgumentParser({
  debug: true,
  formatterClass: argparse.ArgumentDefaultsHelpFormatter,
  description: 'description'
});

parser.addArgument(['--foo'], {
  help: 'foo help - oh and by the way, %(defaultValue)s'
});

parser.addArgument(['--bar'], {
  action: 'storeTrue',
  help: 'bar help'
});

parser.addArgument(['spam'], {
  help: 'spam help'
});
github nodeca / argparse / examples / testformatters.js View on Github external
var assert = require('assert');


function print() {
  return console.log.apply(console, arguments);
}
// print = function () {};

var argparse = require('argparse');

print('TEST argparse.ArgumentDefaultsHelpFormatter');

parser = new argparse.ArgumentParser({
  debug: true,
  formatterClass: argparse.ArgumentDefaultsHelpFormatter,
  description: 'description'
});

parser.addArgument([ '--foo' ], {
  help: 'foo help - oh and by the way, %(defaultValue)s'
});

parser.addArgument([ '--bar' ], {
  action: 'storeTrue',
  help: 'bar help'
});

parser.addArgument([ 'spam' ], {
  help: 'spam help'
});
github material-components / material-components-web / test / screenshot / infra / lib / cli.js View on Github external
constructor() {
    /**
     * @type {!ArgumentParser}
     * @private
     */
    this.rootParser_ = new argparse.ArgumentParser({
      // argparse throws an error if `process.argv[1]` is undefined, which happens when you run `node --interactive`.
      prog: process.argv[1] || 'node',
    });

    /**
     * @type {!ActionSubparsers}
     * @private
     */
    this.commandParsers_ = this.rootParser_.addSubparsers({
      title: 'Commands',
    });

    this.initApproveCommand_();
    this.initBuildCommand_();
    this.initCleanCommand_();
    this.initDemoCommand_();
github SRA-SiliconValley / jalangi / src / js / commands / direct2.js View on Github external
// Author: Koushik Sen

/*jslint node: true */
/*global process */
/*global J$ */

var argparse = require('argparse');
var parser = new argparse.ArgumentParser({
    addHelp: true,
    description: "Command-line utility to perform Jalangi's analysis2"
});
parser.addArgument(['--analysis'], { help: "absolute path to analysis file to run", action:'append'});
parser.addArgument(['--initParam'], { help: "initialization parameter for analysis, specified as key:value", action:'append'});
parser.addArgument(['script_and_args'], {
    help: "script to record and CLI arguments for that script",
    nargs: argparse.Const.REMAINDER
});
var args = parser.parseArgs();

function runAnalysis(initParam) {
    if (args.script_and_args.length === 0) {
        console.error("must provide script to record");
        process.exit(1);
    }
    // we shift here so we can use the rest of the array later when
    // hacking process.argv; see below
    var script = args.script_and_args.shift();

    var path = require('path');
    var Headers = require('./../Headers2');
    Headers.headerSources.forEach(function(src){
        require('./../../../'+src);
github SRA-SiliconValley / jalangi / src / js / commands / record.js View on Github external
/*jslint node: true */
/*global process */
/*global J$ */

var argparse = require('argparse');
var DEFAULT_TRACE_FILE_NAME = 'jalangi_trace';
var parser = new argparse.ArgumentParser({
    addHelp: true,
    description: "Command-line utility to perform Jalangi's record phase"
});
parser.addArgument(['--smemory'], { help: "Use shadow memory", action: 'storeTrue'});
parser.addArgument(['--tracefile'], { help: "Location to store trace file", defaultValue: DEFAULT_TRACE_FILE_NAME });
parser.addArgument(['--analysis'], { help: "absolute path to analysis file to run during record", action:"append"});
parser.addArgument(['script_and_args'], {
    help: "script to record and CLI arguments for that script",
    nargs: argparse.Const.REMAINDER
});
var args = parser.parseArgs();
if (args.script_and_args.length === 0) {
    console.error("must provide script to record");
    process.exit(1);
}
// we shift here so we can use the rest of the array later when
// hacking process.argv; see below
var script = args.script_and_args.shift();

global.JALANGI_MODE="record";
global.USE_SMEMORY=args.smemory;

var path = require('path');
var Headers = require('./../Headers');
Headers.headerSources.forEach(function(src){
github Samsung / jalangi2 / src / js / commands / branchJalangi.js View on Github external
// Author: Koushik Sen
// Author: Manu Sridharan

/*jslint node: true */
/*global process */
/*global J$ */

var argparse = require('argparse');
var parser = new argparse.ArgumentParser({
    addHelp: true,
    description: "Command-line utility to perform Jalangi2's instrumentation and analysis"
});
parser.addArgument(['--analysis'], {help: "absolute path to analysis file to run", action: 'append'});
parser.addArgument(['script_and_args'], {
    help: "script to record and CLI arguments for that script",
    nargs: argparse.Const.REMAINDER
});
var args = parser.parseArgs();

if (args.script_and_args.length === 0) {
    console.error("must provide script to record");
    process.exit(1);
}
// we shift here so we can use the rest of the array later when
// hacking process.argv; see below
var script = args.script_and_args.shift();

var Module = require('module');
var path = require('path');
var fs = require('fs');
var originalLoader = Module._extensions['.js'];
var FILESUFFIX1 = "_jalangi_";
github SRA-SiliconValley / jalangi / src / js / commands / symbolic.js View on Github external
// Author: Manu Sridharan

/*jslint node: true */
/*global J$ */

var argparse = require('argparse');
var parser = new argparse.ArgumentParser({
    addHelp: true,
    description: "Command-line utility to perform Jalangi's pure symbolic execution"
});
parser.addArgument(['analysis'], {
    help: "absolute path to symbolic execution code"
});
parser.addArgument(['script_and_args'], {
    help: "script to run symbolically and its arguments",
    nargs: argparse.Const.REMAINDER
});
var args = parser.parseArgs();
if (args.script_and_args.length === 0) {
    console.error("must provide script to record");
    process.exit(1);
}
// we shift here so we can use the rest of the array later when
// hacking process.argv; see below
var script = args.script_and_args.shift();


global.JALANGI_MODE="symbolic";
global.USE_SMEMORY=args.smemory;
global.ANALYSIS_SCRIPT=args.analysis;

var path = require('path');
github SRA-SiliconValley / jalangi / src / js / commands / direct.js View on Github external
/*jslint node: true */
/*global process */
/*global J$ */

var argparse = require('argparse');
var parser = new argparse.ArgumentParser({
    addHelp: true,
    description: "Command-line utility to perform Jalangi's direct analysis"
});
parser.addArgument(['--smemory'], { help: "Use shadow memory", action: 'storeTrue'});
parser.addArgument(['--analysis'], { help: "absolute path to analysis file to run", action:'append'});
parser.addArgument(['--initParam'], { help: "initialization parameter for analysis, specified as key:value", action:'append'});
parser.addArgument(['script_and_args'], {
    help: "script to record and CLI arguments for that script",
    nargs: argparse.Const.REMAINDER
});
var args = parser.parseArgs();

function runAnalysis(initParam) {
    if (args.script_and_args.length === 0) {
        console.error("must provide script to execute");
        process.exit(1);
    }
    // we shift here so we can use the rest of the array later when
    // hacking process.argv; see below
    var script = args.script_and_args.shift();

    global.JALANGI_MODE="inbrowser";
    global.USE_SMEMORY=args.smemory;

    var path = require('path');
github Samsung / jalangi2 / src / js / commands / jalangi.js View on Github external
/*global J$ */

var argparse = require('argparse');
var instUtil = require('../instrument/instUtil');
var parser = new argparse.ArgumentParser({
    addHelp: true,
    description: "Command-line utility to perform Jalangi2's instrumentation and analysis"
});
parser.addArgument(['--analysis'], {help: "absolute path to analysis file to run", action: 'append'});
parser.addArgument(['--initParam'], { help: "initialization parameter for analysis, specified as key:value", action:'append'});
parser.addArgument(['--inlineIID'], {help: "Inline IID to (beginLineNo, beginColNo, endLineNo, endColNo) in J$.iids in the instrumented file", action: 'storeTrue'});
parser.addArgument(['--inlineSource'], {help: "Inline original source as string in J$.iids.code in the instrumented file", action: 'storeTrue'});
parser.addArgument(['--astHandlerModule'], {help: "Path to a node module that exports a function to be used for additional AST handling after instrumentation"});
parser.addArgument(['script_and_args'], {
    help: "script to record and CLI arguments for that script",
    nargs: argparse.Const.REMAINDER
});
var args = parser.parseArgs();
var astHandler = null;
if (args.astHandlerModule) {
    astHandler = require(args.astHandlerModule);
}



if (args.script_and_args.length === 0) {
    console.error("must provide script to record");
    process.exit(1);
}
// we shift here so we can use the rest of the array later when
// hacking process.argv; see below
var script = args.script_and_args.shift();
github mozilla / DeepSpeech / native_client / javascript / client.js View on Github external
// These constants are tied to the shape of the graph used (changing them changes
// the geometry of the first layer), so make sure you use the same constants that
// were used during training

// Number of MFCC features to use
const N_FEATURES = 26;

// Size of the context window used for producing timesteps in the input vector
const N_CONTEXT = 9;

var VersionAction = function VersionAction(options) {
  options = options || {};
  options.nargs = 0;
  argparse.Action.call(this, options);
}
util.inherits(VersionAction, argparse.Action);

VersionAction.prototype.call = function(parser) {
  Ds.printVersions();
  process.exit(0);
}

var parser = new argparse.ArgumentParser({addHelp: true, description: 'Running DeepSpeech inference.'});
parser.addArgument(['--model'], {required: true, help: 'Path to the model (protocol buffer binary file)'});
parser.addArgument(['--alphabet'], {required: true, help: 'Path to the configuration file specifying the alphabet used by the network'});
parser.addArgument(['--lm'], {help: 'Path to the language model binary file', nargs: '?'});
parser.addArgument(['--trie'], {help: 'Path to the language model trie file created with native_client/generate_trie', nargs: '?'});
parser.addArgument(['--audio'], {required: true, help: 'Path to the audio file to run (WAV format)'});
parser.addArgument(['--version'], {action: VersionAction, help: 'Print version and exits'})
var args = parser.parseArgs();

function totalTime(hrtimeValue) {