How to use the commander.Command 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 NetsBlox / NetsBlox / bin / netsblox-persist.js View on Github external
/* eslint-disable no-console*/
require('epipebomb')();  // Allow piping to 'head'

var Command = require('commander').Command,
    storage = require('../src/server/storage/storage'),
    Logger = require('../src/server/logger'),
    Projects = require('../src/server/storage/projects'),
    logger = new Logger('netsblox:cli:persist'),
    program = new Command();

program
    .arguments(' ')
    .parse(process.argv);

if (!program.args.length === 2) {
    console.log('usage: netsblox persist  ');
    process.exit(1);
}

storage.connect()
    .then(() => {
        logger.trace('About to print projects for ' + program.args[0]);

        return Projects.get(program.args[0], program.args[1]);
    })
github NetsBlox / NetsBlox / bin / netsblox-export-project.js View on Github external
/* eslint-disable no-console*/
require('epipebomb')();  // Allow piping to 'head'

var Command = require('commander').Command,
    Logger = require('../src/server/logger'),
    Projects = require('../src/server/storage/projects'),
    logger = new Logger('netsblox:cli:export'),
    fs = require('fs'),
    program = new Command(),
    runWithStorage = require('./utils').runWithStorage;

program
    .arguments(' ')
    .parse(process.argv);

if (program.args.length !== 2) {
    console.log('usage: netsblox export-project  ');
    process.exit(1);
}

var [owner, name] = program.args;

async function exportProject(owner, projectName) {
    logger.trace(`About to get project: ${owner} ${projectName}`);
    const project = await Projects.get(owner, projectName);
github seymoe / mieo / index.js View on Github external
initProgram() {
    this.program = new commander.Command()
    // CLI 的版本信息
    this.program
      .version(pkg.version)
    // init 命令
    this.program
      .command('init <dir>')
      .description('Init a project by choosing template.')
      .action((dir) =&gt; initScript(this, dir))
    // 提供系统参数来给 commander 解析
    this.program.parse(process.argv)
  }
</dir>
github cypress-io / cypress / cli / lib / cli.js View on Github external
init (args) {
    if (!args) {
      args = process.argv
    }

    if (!util.isValidCypressEnvValue(process.env.CYPRESS_ENV)) {
      debug('invalid CYPRESS_ENV value', process.env.CYPRESS_ENV)

      return errors.exitWithError(errors.errors.invalidCypressEnv)(
        `CYPRESS_ENV=${process.env.CYPRESS_ENV}`
      )
    }

    const program = new commander.Command()

    // bug in commaner not printing name
    // in usage help docs
    program._name = 'cypress'

    program.usage(' [options]')

    program
    .command('help')
    .description('Shows CLI help and exits')
    .action(() =&gt; {
      program.help()
    })

    program
    .option('-v, --version', text('version'))
github DevExpress / testcafe / src / cli / argument-parser.ts View on Github external
public constructor (cwd: string) {
        this.program      = new Command('testcafe');
        this.experimental = new Command('testcafe-experimental');
        this.cwd          = cwd || process.cwd();
        this.remoteCount  = 0;
        this.opts         = {};
        this.args         = [];

        this._describeProgram();
    }
github halfnelson / svelte-type-checker / src / index.ts View on Github external
export function cli() {
    const program = new Command()
    program.version(pkg.version);

    program
        .description('Runs the type checker over the files and their dependencies. [the glob defaults to ./**/*.svelte]')
        .arguments('[rootFilesGlob]')
        .option('-d --config-dir <dir>', 'tsconfig/jsconfig directory', process.cwd())
        .option('-e --emit-tsx', 'emit compiled .tsx file for debugging', false)
        .action((rootFilesGlob, opts) =&gt; {
            let glob = rootFilesGlob || './**/*.svelte'
            console.log(chalk`\n{underline svelte-type-checker ${pkg.version}}\n`)

            if (opts.dir &amp;&amp; !ts.sys.directoryExists(opts.dir)) {
                console.error(`Couldn't find the provided tsconfig directory: ${opts.dir}`);
                process.exit(1);
            }
</dir>
github elastic / kibana / src / es_archiver / cli.js View on Github external
*
 *************************************************************/

import { resolve } from 'path';
import { readFileSync } from 'fs';
import { format as formatUrl } from 'url';
import readline from 'readline';

import { Command } from 'commander';
import elasticsearch from 'elasticsearch';

import { EsArchiver } from './es_archiver';
import { ToolingLog } from '@kbn/dev-utils';
import { readConfigFile } from '@kbn/test';

const cmd = new Command('node scripts/es_archiver');

const resolveConfigPath = v => resolve(process.cwd(), v);
const defaultConfigPath = resolveConfigPath('test/functional/config.js');

cmd
  .description(`CLI to manage archiving/restoring data in elasticsearch`)
  .option('--es-url [url]', 'url for elasticsearch')
  .option('--kibana-url [url]', 'url for kibana (only necessary if using "load" or "unload" methods)')
  .option(`--dir [path]`, 'where archives are stored')
  .option('--verbose', 'turn on verbose logging')
  .option('--config [path]', 'path to a functional test config file to use for default values', resolveConfigPath, defaultConfigPath)
  .on('--help', () => {
    console.log(readFileSync(resolve(__dirname, './cli_help.txt'), 'utf8'));
  });

cmd
github webgme / webgme / src / bin / reassign_relids.js View on Github external
main = function (argv) {
    var mainDeferred = Q.defer(),
        Command = require('commander').Command,
        program = new Command(),
        outputPath,
        params,
        finishUp = function (error) {
            var ended = function () {
                if (error) {
                    mainDeferred.reject(error);
                    return;
                }
                mainDeferred.resolve();
            };

            if (gmeAuth) {
                gmeAuth.unload();
            }
            if (cliStorage) {
                cliStorage.closeDatabase()
github evmar / webtreemap / src / cli.ts View on Github external
async function main() {
  const args = new Command()
                   .description(`Generate web-based treemaps.

  Reads a series of
    size path
  lines from stdin, splits path on '/' and outputs HTML for a treemap.
`)
                   .option('-o, --output [path]', 'output to file, not stdout')
                   .option('--title [string]', 'title of output HTML')
                   .parse(process.argv);
  const node = treeFromLines(await readLines());
  const treemapJS = await readFile(__dirname + '/../webtreemap.js');
  const title = args.title || 'webtreemap';

  let output = `
<title>${title}</title>
<style></style>