How to use the parse function from commander

Find comprehensive JavaScript commander.parse code examples handpicked from public code repositorys.

30
31
32
33
34
35
36
37
38
39
        .option('-l, --log [debug]', 'logLevel')
        .usage(cmd.usage)
        .description(cmd.desc)
    );
  })
  commander.parse(argv);
}

function version() {
  console.log(`${cmlpackage.name}@${cmlpackage.version}`)
fork icon699
star icon0
watch icon239

+ 19 other calls in file

214
215
216
217
218
219
        });

if (require.main === module) {
        require('pretty-error').start();

        program.parse(process.argv);
fork icon574
star icon0
watch icon1

99
100
101
102
103
104
105
106
107
108
      process.exit(1);
    }
  }
  metadata = metadataModule.retrieveMetadata(sparqlTemplate);
  if (metadata.option && !opts.resetOption) {
    program.parse(process.argv.concat(metadata.option.split(/\s+/)));
    opts = program.opts();
  }
  templateFileSpecified = true;
}
fork icon2
star icon4
watch icon4

131
132
133
134
135
136
137
138
139
140
        code: false
    };
}
if (program.parse) {
    if (!program.parse.acorn && !program.parse.spidermonkey) {
        options.parse = program.parse;
    } else if (program.sourceMap && program.sourceMap.content == "inline") {
        fatal("ERROR: inline source map only works with built-in parser");
    }
}
fork icon0
star icon1
watch icon1

+ 35 other calls in file

93
94
95
96
97
98
99
100
101
102
  }
  // dynamically set up custom options
  Object.keys(opts.checks).forEach(generateCheckOptions);
}

const files = program.parse(process.argv).args;
// 'parse' is a commander.js edge case:
const shouldParse = Object.keys(program).indexOf('parse') !== -1;

const hasTextArg = args.some(arg => arg.startsWith('--text'));
fork icon212
star icon0
watch icon86

+ 19 other calls in file

501
502
503
504
505
506
507
508
509
510
511
    return program.args[0]
  }
}


const main = async () => {
  program.parse(process.argv)
  // Check for unknown commands
  const commands = keyBy(program.commands, '_name')
  const command = findCommand(program)
  if (!commands[command]) {
fork icon4
star icon3
watch icon8

+ 6 other calls in file

93
94
95
96
97
98
99
100
101
102
if (error) {
  logger.error(error);
  return;
}

program.parse(args);

var validCommand = program.commands.some(function(cmd) {
  return cmd.name() === command || cmd.alias() === command;
});
fork icon474
star icon0
watch icon135

+ 15 other calls in file

38
39
40
41
42
43
44
45
46
47
commander
  .storeOptionsAsProperties(false)
  .passCommandToAction(false)
  .allowUnknownOption()
  .requiredOption(`--action <type>`, "Action to run")
commander.parse(process.argv)

const {action} = commander.opts()

const file = fs.readFileSync(`./${action}/action.yml`)
fork icon2
star icon5
watch icon21

+ 3 other calls in file

46
47
48
49
50
51
52
53
54
55
56
57
58


const publishModule = async(version, workDir) =>
  await execCommand(`yarn publish --new-version ${version}`, workDir);


const runCLI = () => {
  commander.parse(process.argv);


  const moduleDir = process.cwd();
  const packageFile = path.join(moduleDir, 'package.json');
  const moduleContent = fs.readFileSync(packageFile, { encoding: 'UTF-8' });
fork icon89
star icon97
watch icon0

54
55
56
57
58
59
60
61
62
 * 判断参数是否为空
 * 如果为空调用上面注册的 help命令
 * 输出提示
 */
function help () {
  program.parse(process.argv)  //commander 用来处理 命令行里面的参数, 这边的process是node的一个全局变量不明白的可以查一下资料
  if (program.args.length < 1) return program.help()
}
help()
fork icon3
star icon10
watch icon1

59
60
61
62
63
64
65
66
67
68
69
70
  .option('-d, --max-distance <distance>', 'Maximum trust distance from viewpoint', parseInt)
  .option('-l, --limit <limit>', 'Limit the amount of results', parseInt)
  .option('-o, --offset <offset>', 'Offset of results list', parseInt);


function runIdentifi() {
  identifi.parse(process.argv);


  if (!process.argv.slice(2).length) {
    identifi.outputHelp();
    return;
fork icon3
star icon2
watch icon0

174
175
176
177
178
179
180
181
182
183
                        return input.coerce(value);
                };
                commander.option(flag, input.description, coerce, input.default);
        });

        return commander.parse(argv);
}

function coerceBoolean(value) {
        return !['false', 'no', '0'].includes(value.toLowerCase());
fork icon169
star icon792
watch icon10

84
85
86
87
88
89
90
91
92
93

  if (argv.length <= 2) {
    argv.push('deploy')
  }

  program.parse(argv)
}

if (!module.parent) {
  module.exports(process.argv)
fork icon99
star icon0
watch icon0

+ 9 other calls in file

16
17
18
19
20
21
22
  });

program.parse(process.argv);

if (program.args.length < 1) {
  program.parse(['', '', 'list']);
}
fork icon24
star icon88
watch icon5

+ 3 other calls in file

95
96
97
98
99
100
101
102
103
// This is not the case when running from a packaged Electron app. Here you have the first value appname and then args.
const normalizedArgv = ('' + process.argv[0]).indexOf(pkg.name) >= 0
    ? ['node', pkg.name, ...process.argv.slice(1)]
    : process.argv;
if (normalizedArgv.length > 1) {
    program.parse(normalizedArgv);
}

const options = program.opts();
fork icon22
star icon102
watch icon11

+ 5 other calls in file

31
32
33
34
35
36
37
38
39
40
  });
}

// If running this module directly then call the main function.
if (require.main === module) {
  options.parse(process.argv);
  main(options.args);
}

module.exports = main;
fork icon45
star icon59
watch icon27

97
98
99
100
101
102
103
104
    .action(function (cmd) {
        console.log('destroying: ', cmd);
    });

if (process.argv.length == 2)
    program.parse(['', '', '-h']);
else
    program.parse(process.argv);
fork icon11
star icon61
watch icon8

+ 3 other calls in file

36
37
38
39
40
41
42
43
44
}

exports.command = function(args) {
  loadCommands()

  commander.parse(args)

  var rawArgs = commander.rawArgs
  // rawArgs示例:[ 'node', '/usr/local/bin/ckstyle', 'demo' ]
fork icon8
star icon61
watch icon8

39
40
41
42
43
44
45
// it should be an invisible command
if (process.argv.slice(2)[0] === 'completion') {
  const env = autoComplete.parseEnv(process.env);
  autoComplete.completion(env, program);
} else {
  program.parse();
}
fork icon6
star icon17
watch icon3

100
101
102
103
104
105
106
107
108
109
        program.errorMessageSave(msg);
        deferred.reject(new Error(msg));
    };

    // Execute the command (asynchronously).
    program.parse(argv);

    // Return the promise for this command.
    return deferred.promise;
};
fork icon6
star icon11
watch icon8

Other functions in commander

Sorted by popularity

function icon

commander.Option is the most popular function in commander (1786 examples)