How to use the parse function from commander
Find comprehensive JavaScript commander.parse code examples handpicked from public code repositorys.
GitHub: didi/chameleon
![didi profile picture](/didi.png?size=40)
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}`)
+ 19 other calls in file
GitHub: case7026/synthetix
![case7026 profile picture](/case7026.png?size=40)
214 215 216 217 218 219
}); if (require.main === module) { require('pretty-error').start(); program.parse(process.argv);
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; }
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"); } }
+ 35 other calls in file
GitHub: btford/write-good
![btford profile picture](/btford.png?size=40)
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'));
+ 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]) {
+ 6 other calls in file
GitHub: brunch/brunch
![brunch profile picture](/brunch.png?size=40)
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; });
+ 15 other calls in file
GitHub: railsware/github-actions
![railsware profile picture](/railsware.png?size=40)
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`)
+ 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' });
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()
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;
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());
GitHub: therealelyayo/saasify
![therealelyayo profile picture](/therealelyayo.png?size=40)
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)
+ 9 other calls in file
GitHub: Hypercubed/todo-md
![Hypercubed profile picture](/Hypercubed.png?size=40)
16 17 18 19 20 21 22
}); program.parse(process.argv); if (program.args.length < 1) { program.parse(['', '', 'list']); }
+ 3 other calls in file
GitHub: Sienci-Labs/gsender
![Sienci-Labs profile picture](/Sienci-Labs.png?size=40)
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();
+ 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;
GitHub: tjanczuk/git-azure
![tjanczuk profile picture](/tjanczuk.png?size=40)
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);
+ 3 other calls in file
GitHub: wangjeaf/ckstyle-node
![wangjeaf profile picture](/wangjeaf.png?size=40)
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' ]
GitHub: Ephigenia/mite-cli
![Ephigenia profile picture](/Ephigenia.png?size=40)
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(); }
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; };
commander.Option is the most popular function in commander (1786 examples)