How to use the commander.args function in commander

To help you get started, we’ve selected a few commander 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 Azure / iothub-explorer / iothub-explorer-get-twin.js View on Github external
var inputError = require('./common.js').inputError;
var serviceError = require('./common.js').serviceError;
var getSas = require('./common.js').getSas;
var Registry = require('azure-iothub').Registry;
var showDeprecationText = require('./common.js').showDeprecationText;

showDeprecationText('az iot hub device-twin show');

program
  .description('Get the twin of the specified device')
  .usage('[options] ')
  .option('-l, --login ', 'use the connection string provided as argument to use to authenticate with your IoT Hub instance')
  .option('-r, --raw', 'use this flag to return raw output instead of pretty-printed output')
  .parse(process.argv);

var deviceId = program.args[0];
if(!deviceId) inputError('You must specify a deviceId.');

var sas = getSas(program.login);

var registry = Registry.fromSharedAccessSignature(sas);
registry.getTwin(deviceId, function (err, twin) {
  if (err) serviceError(err);
  else {
    // The _registry property that shouldn't be printed and make prettyjson crash.
    delete twin._registry;
    var output = program.raw ? JSON.stringify(twin) : prettyjson.render(twin);
    console.log(output);
  }
});
github DarkPark / FortNotes / bin / cli.js View on Github external
.action(initApi);

// extend default help info
program.on('--help', function () {
	console.log('  Examples:');
	console.log('');
	console.log('    $ fortnotes app --help');
	console.log('    $ fortnotes api --port 80');
	console.log('');
});

// parse and invoke commands when defined
program.parse(process.argv);

// no options were given
if ( !program.args.length ) {
	// show help and exit
	program.help();
}


// public export
module.exports = program;
github Digiturk / wface / cli / src / index.js View on Github external
});   


program.command("install").action(() => { install(); });     
program.command("link").action(() => { link(); });     
program.command("run").action(() => { run(); });     
program.command("uninstall").action(() => { uninstall(); });
program.command("update").action(() => { update(); });
program.command("unlink").action(() => { unlink(); });
program.command("version").action(() => { version(); });     
   
/*****************************************************************************************************************/

program.parse(process.argv);
// if program was called with no arguments, show help.
if (program.args.length === 0) program.help();
github baidu / openrasp / lib / check.js View on Github external
/* eslint-env node */
const fs = require('fs');
const path = require('path');
const program = require('commander');
const Mocha = require('mocha');
require('./buildenv');

program.usage('')
    .option('-t, --test-dir <dir>', 'specify a custom test cases directory')
    .parse(process.argv);

if (program.args.length &lt; 1) {
    return program.help();
}

let filename = program.args[0];
let filepath = path.resolve(process.cwd(), filename);
require(filepath);

let mocha = new Mocha({
    bail: true,
    useColors: true,
    slow: 20,
    reporter: 'list'
});

mocha.addFile(
    path.join(path.resolve(__dirname, 'case', 'code.test.js'))
);
mocha.addFile(
    path.join(path.resolve(__dirname, 'case', 'ability.test.js'))
);</dir>
github microsoft / botbuilder-tools / packages / DialogSchema / src / dialogSchema.ts View on Github external
console.error(chalk.default.redBright(`Unknown arguments: ${flag}`));
    program.outputHelp((str: string) =&gt; {
        console.error(chalk.default.redBright(str));
        return '';
    });
    process.exit(1);
};

program
    .version(pkg.version, '-v, --Version')
    .usage("[options] ")
    .option("-o, output 
github intel / intel-iot-services-orchestration-layer / add_header.js View on Github external
}
  return header;
}

try {
  var header = read_header(program.head);

  if (program.old) {
    var old = read_header(program.old);
  }
} catch(e) {
  console.error(e);
  process.exit(-1);
}

program.args.forEach(function(file) {
  var content = fs.readFileSync(file, 'utf8');
  if (header === content.slice(0, header.length)) {
    console.log(file, " [skiped]");
    return;
  }

  var replaced = false;
  if (old && old === content.slice(0, old.length)) {
    content = content.slice(old.length);
    replaced = true;
  }

  fs.writeFileSync(file, header + content, 'utf8');
  console.log(file, replaced ? " [replaced]": " [added]");
});
github mseminatore / TeslaJS / samples / setTemps.js View on Github external
function sampleMain(tjs, options) {
    var temp = program.args[0];
    if (!temp) {
        program.help();
    }

    tjs.setTemps(options, f2c(temp), null, function (err, result) {
        if (result.result) {
            var str = (temp + " Deg.F").green;
            console.log("\nTemperature successfully set to: " + str);
        } else {
            console.log(result.reason.red);
        }
    });
}
github protofire / solhint / solhint.js View on Github external
.action(execMainAction)

  program
    .command('stdin')
    .description('linting of source code data provided to STDIN')
    .option('--filename [file_name]', 'name of file received using STDIN')
    .action(processStdin)

  program
    .command('init-config')
    .description('create in current directory configuration file for solhint')
    .action(writeSampleConfigFile)

  program.parse(process.argv)

  if (program.args.length &lt; 1) {
    program.help()
  }
}
github babel / babel / packages / babel-cli / src / babel / options.js View on Github external
export default function parseArgv(args: Array): CmdOptions | null {
  //
  commander.parse(args);

  const errors = [];

  let filenames = commander.args.reduce(function(globbed, input) {
    let files = glob.sync(input);
    if (!files.length) files = [input];
    return globbed.concat(files);
  }, []);

  filenames = uniq(filenames);

  filenames.forEach(function(filename) {
    if (!fs.existsSync(filename)) {
      errors.push(filename + " does not exist");
    }
  });

  if (commander.outDir &amp;&amp; !filenames.length) {
    errors.push("--out-dir requires filenames");
  }