How to use the args.parser function in args

To help you get started, we’ve selected a few args 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 cwramsey / twitter-contest-winner / app.js View on Github external
twitter = require('twitter'),
    print = require('pretty-print'),
    tweet_helpers = require('./helpers/tweets'),
    keywords = require('./configs/keywords'),
    args = require('args');

var options = args.Options.parse([
  {
    name: 'percent',
    shortName: 'p',
    type: 'int',
    help: 'Percentage of tweets you want to retweet & follow. Lower number will keep your app from going over the API limits.'
  }
]);

var parsed_options = args.parser(process.argv).parse(options);

if (!parsed_options.percent) {
  console.log(options.getHelp());
  process.exit();
}

if (parsed_options.percent > 100) {
  parsed_options.percent = 100;
}

if (parsed_options.percent < 1) {
  parsed_options.percent = 1;
}

console.log('Processing %s% of tweets.'.yellow, parsed_options.percent);
console.log('Connecting to Twitter stream'.green);
github garden20 / gardener / lib / options.js View on Github external
exports.set_options = function(arg_array) {
    cached = args.parser(arg_array, { start: 0 }).parse(options);
    if (cached.user && (!cached.pass && !cached.stdinpass)) throw Error('A password must be provided with the user option');
    if (!cached.user && cached.pass) throw Error('A user must be provided with the password option');
};