How to use the parse function from commander
Find comprehensive JavaScript commander.parse code examples handpicked from public code repositorys.
GitHub: didi/chameleon
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}`)
699
0
239
+ 19 other calls in file
GitHub: case7026/synthetix
214 215 216 217 218 219
}); if (require.main === module) { require('pretty-error').start(); program.parse(process.argv);
574
0
1
GitHub: sparqling/spang
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; }
2
4
4
GitHub: dewbian/blot_2023
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"); } }
0
1
1
+ 35 other calls in file
GitHub: btford/write-good
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'));
212
0
86
+ 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]) {
4
3
8
+ 6 other calls in file
GitHub: brunch/brunch
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; });
474
0
135
+ 15 other calls in file
GitHub: railsware/github-actions
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`)
2
5
21
+ 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' });
89
97
0
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()
3
10
1
GitHub: irislib/iris-cli
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;
3
2
0
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());
169
792
10
GitHub: therealelyayo/saasify
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)
99
0
0
+ 9 other calls in file
GitHub: Hypercubed/todo-md
16 17 18 19 20 21 22
}); program.parse(process.argv); if (program.args.length < 1) { program.parse(['', '', 'list']); }
24
88
5
+ 3 other calls in file
GitHub: Sienci-Labs/gsender
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();
22
102
11
+ 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;
45
59
27
GitHub: tjanczuk/git-azure
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);
11
61
8
+ 3 other calls in file
GitHub: wangjeaf/ckstyle-node
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' ]
8
61
8
GitHub: Ephigenia/mite-cli
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(); }
6
17
3
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; };
6
11
8
commander.Option is the most popular function in commander (1786 examples)