export function listBucketMetrics() {
    commander
        .version('0.0.1')
        .option('-a, --access-key <accessKey>', 'Access key id')
        .option('-k, --secret-key <secretKey>', 'Secret access key')
        .option('-b, --buckets <buckets>', 'Name of bucket(s)' +
        'with a comma separator if more than one')
        .option('-s, --start <start>', 'Start of time range')
        .option('-e --end <end>', 'End of time range')
        .option('-h, --host <host>', 'Host of the server')
        .option('-p, --port <port>', 'Port of the server')
        .option('--ssl', 'Enable ssl')
        .option('-v, --verbose')
        .parse(process.argv);

    const { host, port, accessKey, secretKey, start, end,
        buckets, verbose, ssl } =
        commander;
    const requiredOptions = { host, port, accessKey, secretKey, buckets,
        start };
    Object.keys(requiredOptions).forEach(option => {
        if (!requiredOptions[option]) {
            logger.error(`missing required option: ${option}`);
            commander.outputHelp();
            process.exit(1);
            return;
        }
    });

    const numStart = Number.parseInt(start, 10);
    if (!numStart) {
        logger.error('start must be a number');
        commander.outputHelp();
        process.exit(1);
    }

    const timeRange = [numStart];

    if (end) {
        const numEnd = Number.parseInt(end, 10);
        if (!numEnd) {
            logger.error('if provide end, end must be a number');
            commander.outputHelp();
            process.exit(1);
        }
        timeRange.push(numEnd);
    }

    const bucketArr = buckets.split(',');
    _listBucketMetrics(host, port, bucketArr, timeRange,
        accessKey, secretKey, verbose, ssl);
}
function parseParameters() {
    if (!process.argv.slice(2).length) {
        program.outputHelp()
        return
    }

    if (program.json)
        helpers.setJson(program.json)
    if (program.force)
        global.force = program.force

    try {
        var authdata = helpers.getAuthData()
        pbclient.pbauth(authdata)
    } catch (err) {
        console.log("Please run 'profitbricks setup' to set up your authentication data.")
        process.exit(code = 0)
    }

    if (program.setup)
        authenticate()

    else if (program.datacenter)
        datacenter.process(program)
    else if (program.server)
        server.process(program)
    else if (program.volume)
        volume.process(program)
    else if (program.snapshot)
        snapshot.process(program)
    else if (program.loadbalancer)
        loadbalancer.process(program)
    else if (program.nic)
        nic.process(program)
    else if (program.ipblock)
        ipblock.process(program)
    else if (program.lan)
        lan.process(program)
    else if (program.drives)
        drives.process(program)
    else if (program.image)
        images.process(program)
    else if (program.request)
        request.process(program)
    else if (program.location){
        location.process(program)
        }
    else
        program.outputHelp()
}
Example #3
0
function displayErrorAndDie(msg, showhelp)
{
    if(showhelp == undefined || showhelp)
        commander.outputHelp();
    console.log(msg.red);
    process.exit();
}
Example #4
0
export default function importjs(argv: Array<string>) {
  program.parse(argv);

  if (!argv.slice(2).length) {
    program.outputHelp();
  }
}
function outputHelp(error_message) {
    program.outputHelp(str => {
        console.error(color.red(`  ERROR: ${error_message}`));
        console.error(str);
        process.exit(0);
    });
}
Example #6
0
async function runCommand(command) {
  try {
    if (command === 'check') {
      let config = await resolveConfig(commander);
      await check(config);
    } else if (command === 'convert') {
      let config = await resolveConfig(commander, {needsJscodeshift: true, needsEslint: true});
      await convert(config);
    } else if (command === 'modernize-js') {
      let config = await resolveConfig(commander, {needsJscodeshift: true, needsEslint: true});
      await modernizeJS(config);
    } else if (command === 'view-errors') {
      await viewErrors();
    } else if (command === 'clean') {
      await clean();
    } else if (command === 'land') {
      let config = await resolveConfig(commander);
      await land(config);
    } else {
      commander.outputHelp();
    }
  } catch (e) {
    process.exitCode = 1;
    console.error(CLIError.formatError(e));
  }
}
 .action((dbConfig, options) => {
     ran = true;
     if (!dbConfig) {
         commander.outputHelp();
     } else {
         let dir;
         try {
             dbConfig = require(path.resolve(dbConfig));
         } catch (fileNotFound) {
             return log.error('could not find file:', dbConfig);
         }
         assert(commander.name.length > 0, 'the --name is required');
         assert(!!dbConfig[commander.name], 'the --name should match a property in your configuration file');
         dbConfig = dbConfig[commander.name];
         assert(commander.directory.length > 0, 'the --directory is required');
         dir = path.join(commander.directory, commander.name);
         assert(fs.existsSync(dir), '--directory does not exist ' + dir);
         run({
             dbConfig: dbConfig,
             name: commander.name,
             changesetDirectory: dir,
             targetFile: commander.target,
             updateFile: commander.update,
             verbose: commander.verbose,
             debug: commander.debug
         });
     }
 })
Example #8
0
/**
 * Main entry point into the command line tool. This is called from index.js.
 */
function main() {
  program.version('0.1.0')
      .usage('[options] <fileOrUrlOrMinus ...>')
      .option(
          '--validator_js <fileOrUrl>',
          'The Validator Javascript. Latest published version by ' +
              'default, or dist/validator_minified.js (built with ' +
              'build.py) for development.',
          'https://cdn.ampproject.org/v0/validator.js')
      .parse(process.argv);
  if (program.args.length == 0) {
    program.outputHelp();
    process.exit(1);
  }
  readFileOrDownload(
      program.validator_js,
      (validatorScript) => {
        vm.runInThisContext(validatorScript);
        validateFiles(program.args);
      },
      (errorMessage) => {
        console.error('Could not fetch validator.js: ' + errorMessage);
        process.exitCode = 1;
      });
}
Example #9
0
function program() {
  var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];

  if ($skypager && _yargs.argv.debugPaths) {
    console.log((0, _stringify2.default)($skypager, null, 2));

    process.exit(0);
  }

  var commander = require('commander');

  commander.version(_package2.default.version).option('--debug', 'enable debugging').option('--env <env>', 'the application environment', process.env.NODE_ENV || 'development').option('--project <path>', 'the folder contains the project you wish to work with');

  configure(commander, options.mode || 'full', options.frameworkHost || 'skypager-project');

  if (!requestedCommand || commander.commands.map(function (c) {
    return c._name;
  }).indexOf(requestedCommand) < 0) {
    // dont duplicate the output
    if (!_yargs.argv.help) {
      commander.outputHelp();
    }
  }

  return function () {
    return commander.parse(process.argv);
  };
}
Example #10
0
function enforceRequiredArgument(name) {
	if (!program[name]) {
		console.error("You must specify <%s>", name);
		program.outputHelp();
		process.exit(1);
	}
}
Example #11
0
File: text.js Project: elad/text
function main() {
  commander
    .version('0.0.1')
    .option('-c, --config [file]', 'Configuration file [$HOME/.textrc.json]', process.env.HOME + '/.textrc.json')
    .option('-s, --service [name]', 'Service name (supported: ' + _.keys(handlers).join(', ') + ')')
    .option('-m, --message [message]', 'Message text')
    .option('-t, --to [destination]', 'To destination (phone number, etc.)')
    .parse(process.argv);

  try {
    config = JSON.parse(fs.readFileSync(commander.config));
    if (!config) {
      throw config;
    }
  } catch (ex) {
    console.log('could not read configuration file', commander.config);
    return;
  }

  if (!commander.service) {
    commander.outputHelp();
    return;
  }
  var handler = handlers[commander.service];
  if (!handler) {
    console.log('unrecognized service:', commander.service);
    return;
  }

  return handler();
}
Example #12
0
/**
 * Checks that the given input is defined.  If it is defined, this is a no-op.  Else
 * this prints the error message and halts the program with exit code 1.
 * @param {input} input - The input to check
 * @param {message} txt - The text to display if the check fails
 */
function check_input(input, message) {
  if (!input) {
    error('\n  Error: ' + message);
    program.outputHelp(colors.red);
    process.exit(1);
  }
}
Example #13
0
export default function (argv) {
  program.parse(process.argv);
  if (!process.argv.slice(2).length) {
    program.outputHelp();
    process.exit(0);
  }
};
Example #14
0
function generate(defaultRootPath) {
	program
		.version('1.0.8')
		.option('-P, --presentational', 'Create Inline function component')
		.option('-C, --container', 'Create class-based component')
		.arguments('<filename> <directory>')
		.action(function(filename, directory) {
			if (program.presentational) {
				writeFileP(`./${defaultRootPath}/${directory}/${filename}.js`, require('./templates/presentional.js')(filename), (error, info) => {
					if (error) {
						console.error('Failed', error);
					} else {
						console.log(`${filename}.js component(presentaional) has been created to ${defaultRootPath}/${directory}/`.yellow);
					}
				});
			}

			if (program.container) {
				writeFileP(`./${defaultRootPath}/${directory}/${filename}.js`, require('./templates/container.js')(filename), (error, info) => {
					if (error) {
						console.error('Failed', error);
					} else {
						console.log(`${filename}.js component(container) has been created to ${defaultRootPath}/${directory}/`.yellow);
					}
				});
			}
		}).parse(process.argv);

		// Default
		if (!process.argv.slice(2).length) {
			program.outputHelp();
		}
}
Example #15
0
		.action(function(command, options) {
			command
				? cmdr.emit(command, null, ['--help'])
				: cmdr.outputHelp()
			;
			process.exit();
		});
Example #16
0
export default function cli() {
  commander.version(version);

  commander.command(
    'watch'
  ).action(() => {
    server();
  });

  commander.command(
    'scaffold'
  ).action(() => {
    scaffold();
  });

  commander.command(
    'dist'
  ).action(() => {
    distribute();
  });

  commander.parse(process.argv);

  if (!process.argv.slice(2).length) {
    commander.outputHelp();
  }
}
Example #17
0
const printMissing = message => {
  commander.outputHelp()
  if (message) {
    console.error(colors.red(message))
  }
  process.exit(1)
}
Example #18
0
index.getBaseOptions(function(err, options) {
    logger.debug(options);
    var promises = [];
    if (program.lcovs && program.lcovs.length > 0) {
        promises = promises.concat(program.lcovs.map(function(lcov) {
            return Q.nfcall(index.convertLcovToCoveralls, fs.readFileSync(lcov, {encoding: 'utf8'}), options);
        }));
    }
    if (program.coveralls && program.coveralls.length > 0) {
        promises = promises.concat(program.coveralls.map(function(coverall) {
            return new Q(JSON.parse(fs.readFileSync(coverall, {encoding: 'utf8'})));
        }));
    }
    if (!promises.length){
        program.outputHelp();
        return;
    }
    Q.all(promises).then(function() {
        console.log('sending coveralls.json to coveralls.io');
        var sourceFiles = _.flatten(_.pluck(Array.prototype.slice.apply(arguments)[0], 'source_files'));
        var coverallsJson = arguments[0][0];
        coverallsJson.source_files = sourceFiles;
        return Q.nfcall(index.sendToCoveralls, coverallsJson).spread(function(resp, body) {
            body = JSON.parse(body);
            console.log(body.message);
            console.log(body.url);
        });
    }, function(err) {
        logger.error('failed', err);
    });
});
Example #19
0
function broccoliCLI () {
  var actionPerformed = false
  program
    .version(JSON.parse(fs.readFileSync(__dirname + '/../package.json', 'utf8')).version)
    .usage('[options] <command> [<args ...>]')

  program.command('serve')
    .description('start a broccoli server')
    .option('--port <port>', 'the port to bind to [4200]', 4200)
    .option('--host <host>', 'the host to bind to [localhost]', 'localhost')
    .option('--cors', 'allow cross-origin resource sharing', false)
    .option('--live-reload-port <port>', 'the port to start LiveReload on [35729]', 35729)
    .action(function(options) {
      actionPerformed = true
      broccoli.server.serve(getBuilder(), options)
    })

  program.command('build <target>')
    .description('output files to target directory')
    .action(function(outputDir) {
      actionPerformed = true
      var builder = getBuilder()
      builder.build()
        .then(function (hash) {
          try {
            fs.mkdirSync(outputDir)
          } catch (err) {
            if (err.code !== 'EEXIST') throw err
            console.error('Error: Directory "' + outputDir + '" already exists. Refusing to overwrite files.')
            process.exit(1)
          }
          var dir = hash.directory
          return RSVP.denodeify(ncp)(dir, outputDir, {
            clobber: false,
            stopOnErr: true
          })
        })
        .finally(function () {
          builder.cleanup()
        })
        .then(function () {
          process.exit(0)
        })
        .catch(function (err) {
          // Should show file and line/col if present
          if (err.file) {
            console.error('File: ' + err.file)
          }
          console.error(err.stack)
          console.error('\nBuild failed')
          process.exit(1)
        })
    })

  program.parse(process.argv)
  if(!actionPerformed) {
    program.outputHelp()
    process.exit(1)
  }
}
Example #20
0
 Object.keys(requiredOptions).forEach(option => {
     if (!requiredOptions[option]) {
         logger.error(`missing required option: ${option}`);
         commander.outputHelp();
         process.exit(1);
         return;
     }
 });
Example #21
0
        }).then(function () {
            cli.parse(process.argv);

            // 如果什么都没有输入就显示帮助
            if (!cli.args.length) {
                cli.outputHelp();
                process.exit(0);
            }
        }).fail(function (reason) {
Example #22
0
Venus.prototype.init = function (args) {

  // Define command line options
  program
    .version(require('./package').version);

  // init command
  program
    .command('init')
    .description(i18n('initialize new venus project directory'))
    .option('-l, --locale [locale]', i18n('Specify locale to use'))
    .option('-v, --verbose', i18n('Run in verbose mode'))
    .option('-d, --debug', i18n('Run in debug mode'))
    .action(_.bind(this.command(this.initProjectDirectory), this));

  // demo mode command
  program
    .command('demo')
    .description(i18n('run an example venus test'))
    .option('-l, --locale [locale]', i18n('Specify locale to use'))
    .option('-v, --verbose', i18n('Run in verbose mode'))
    .option('-d, --debug', i18n('Run in debug mode'))
    .action(_.bind(this.command(this.runDemo), this));

  // run command
  program
    .command('run')
    .description(i18n('Run tests'))
    .option('-t, --test [tests]', i18n('Comma separated string of tests to run'))
    .option('-p, --port [port]', i18n('port to run on'), function (value) { return parseInt(value, 10); })
    .option('-n, --phantom [path to binary]', i18n('Use phantomJS client to run browser tests'))
    .option('-s, --selenium [server url]', i18n('Use selenium client to run browser tests'))
    .option('--sauce-labs [server url]', i18n('Use sauce labs client to run browser tests'))
    .option('-l, --locale [locale]', i18n('Specify locale to use'))
    .option('-v, --verbose', i18n('Run in verbose mode'))
    .option('-d, --debug', i18n('Run in debug mode'))
    .option('-c, --coverage', i18n('Generate Code Coverage Report'))
    .option('--hostname', i18n('Set hostname for test URLs, defaults to your ip address'))
    .option('--require-annotations', i18n('Ignore JavaScript test files which do not contain a Venus annotation (@venus-*)'))

    .option('--browser [browser|version]', i18n('Browser name to request from selenium webdriver or sauce labs'))
    .option('--platform [platform]', i18n('Specify platform to use with sauce labs'))
    .option('--username [username]', i18n('Specify username to use with sauce labs'))
    .option('--access-key [accessKey]', i18n('Specify access key to use with sauce labs'))

    .option('-r, --selenium-server [url]', i18n('[deprecated] Specify selenium server to use'))
    .option('-b, --selenium-browser [browser]', i18n('[deprecated] Specify browser to use with selenium'))

    .action(_.bind(this.command(this.run), this));

  program.parse(args);

  if (this.noCommand) {
    program.outputHelp();
  }
};
Example #23
0
 .spread((rheactorjsCommands, ausgabenCommands) => {
   let commands = _concat(rheactorjsCommands, ausgabenCommands)
   if (!process.argv.slice(2).length || !commands.includes(process.argv.slice(2)[0])) {
     makeRed(backend.appName)
     program.outputHelp(makeRed)
     process.exit(1)
   } else {
     program.parse(process.argv)
   }
 })
Example #24
0
	.action(function (stage, host) {
		if (!["test", "prod", "local", "host", undefined].includes(stage)
			|| (stage !== "host" && host)
			|| (stage === "host" && !host)) {
			options.outputHelp()
			process.exit(1)
		}
		options.stage = stage || "local"
		options.host = host
	})
Example #25
0
var handleError = function handleError(error) {
  //TODO: explore better error handling. What if message changes in the future
  if(error.message === 'Argument invalid') {
    console.error(error.message);
    COMMANDER.outputHelp();
  }
  else {
    console.error(error.message);
  }
};
Example #26
0
function broccoliCLI () {
  var actionPerformed = false
  program
    .version(JSON.parse(fs.readFileSync(__dirname + '/../package.json', 'utf8')).version)
    .usage('[options] <command> [<args ...>]')

  program.command('serve')
    .description('start a broccoli server')
    .option('--port <port>', 'the port to bind to [4200]', 4200)
    .option('--host <host>', 'the host to bind to [localhost]', 'localhost')
    .option('--live-reload-port <port>', 'the port to start LiveReload on [35729]', 35729)
    .action(function(options) {
      actionPerformed = true
      broccoli.server.serve(getBuilder(), options)
    })

  program.command('build <target>')
    .description('output files to target directory')
    .action(function(outputDir) {
      actionPerformed = true
      var builder = getBuilder()
      builder.build()
        .then(function (hash) {
          var dir = hash.directory
          try {
            copyDereferenceSync(dir, outputDir)
          } catch (err) {
            if (err.code === 'EEXIST') err.message += ' (we cannot build into an existing directory)'
            throw err
          }
        })
        .finally(function () {
          return builder.cleanup()
        })
        .then(function () {
          process.exit(0)
        })
        .catch(function (err) {
          // Should show file and line/col if present
          if (err.file) {
            console.error('File: ' + err.file)
          }
          console.error(err.stack)
          console.error('\nBuild failed')
          process.exit(1)
        })
    })

  program.parse(process.argv)
  if(!actionPerformed) {
    program.outputHelp()
    process.exit(1)
  }
}
Example #27
0
 .action((cmd, presetDir, template) => {
   if (cmd === 'build-all') {
     buildAll()
   } else {
     if (!presetDir) {
       console.error(cmd + ' requires package directory as additional argument')
       program.outputHelp()
       process.exit(1)
     }
     if (cmd === 'bundle') {
       bundle(presetDir)
     } else if (cmd === 'serve') {
       serve(presetDir, template)
     } else if (cmd === 'build') {
       buildComponent(presetDir)
     } else {
       program.outputHelp()
     }
   }
 })
Example #28
0
    init: () => {
        if (process.argv.length < 3) {
            printInfo();
            commander.outputHelp();
            return exitAndLog();
        }

        commander
            .version(pkg.version)
            .parse(process.argv);
    }
Example #29
0
function constructWebsocketUrl (props) {
  const {host, port, channel, notSecure} = props
  const scheme = notSecure ? 'ws' : 'wss'

  if (!host || !channel) {
    program.outputHelp()
    return false
  }

  const path = (channel || '').replace(/^\/?/, '/')

  return `${scheme}://${host}${port ? `:${port}` : ''}${path}`
}
Example #30
0
function broccoliCLI () {
  var actionPerformed = false
  program
    .usage('[options] <command> [<args ...>]')

  program.command('serve')
    .description('start a broccoli server')
    .option('--port <port>', 'the port to bind to [4200]', 4200)
    .option('--host <host>', 'the host to bind to [localhost]', 'localhost')
    .option('--live-reload-port <port>', 'the port to start LiveReload on [35729]', 35729)
    .action(function(options) {
      actionPerformed = true
      broccoli.server.serve(getBuilder(), options)
    })

  program.command('build <target>')
    .description('output files to target directory')
    .action(function(outputDir) {
      actionPerformed = true
      var builder = getBuilder()
      builder.build()
        .then(function (dir) {
          try {
            fs.mkdirSync(outputDir)
          } catch (err) {
            if (err.code !== 'EEXIST') throw err
            console.error('Error: Directory "' + outputDir + '" already exists. Refusing to overwrite files.')
            process.exit(1)
          }
          return RSVP.denodeify(ncp)(dir, outputDir, {
            clobber: false,
            stopOnErr: true
          })
        })
        .then(function () {
          process.exit(0)
        })
        .catch(function (err) {
          // Should show file and line/col if present
          console.error(err.stack)
          console.error('\nBuild failed')
          process.exit(1)
        })
    })

  program.parse(process.argv)
  if(!actionPerformed) {
    program.outputHelp()
    process.exit(1)
  }
}