How to use the outputHelp function from commander
Find comprehensive JavaScript commander.outputHelp code examples handpicked from public code repositorys.
The commander.outputHelp method prints the help information for a command-line program to the console.
GitHub: instructure/canvas-ios
![instructure profile picture](/instructure.png?size=40)
39 40 41 42 43 44 45 46 47 48
if ( !program.skipPush && (!process.env.AWS_ACCESS_KEY_ID || !process.env.AWS_SECRET_ACCESS_KEY) ) { program.outputHelp() process.exit(1) } exportTranslations().catch(err => {
GitHub: klaemo/s3-website
![klaemo profile picture](/klaemo.png?size=40)
197 198 199 200 201 202
.action(function (env) { program.help() }) program.parse(process.argv) if (!program.args.length) program.outputHelp()
+ 9 other calls in file
How does commander.outputHelp work?
The commander.outputHelp method is part of the Commander.js library, which provides a framework for building command-line interfaces in Node.js. The method is called on a Commander.js program instance and prints the program's help information to the console. The help information includes a usage statement, options, and any command-specific help text that has been defined. By default, the help information is printed to the console using the console.log() method. However, the output can be redirected to a file or a stream by passing an optional argument to the method. The outputHelp() method is typically called when the user requests help for the program, either by passing the -h or --help option, or by invoking a specific command with the --help option. The format and content of the help information can be customized by setting various options and properties on the program instance, such as program.name, program.usage, program.description, program.option(), and program.command(). These properties define the program's name, usage statement, description, options, and commands, respectively. Overall, the outputHelp() method is a convenient way to provide users with information about how to use a command-line program and its options.
GitHub: dadaiwei/fe-deploy-cli
![dadaiwei profile picture](/dadaiwei.png?size=40)
33 34 35 36 37 38 39 40 41 42
deploy(); } // 无参数时默认输出help信息 if (!firstArg) { program.outputHelp(); } // 部署流程 function deploy() {
18 19 20 21 22 23 24 25 26 27
} if (!process.argv.slice(2).length) { (async () => { let str = colors.bold(await outLogo()) + colors.blue(` version: ${require('../package.json').version}\n`) program.outputHelp(() => str) })() } async function outLogo () {
+ 9 other calls in file
Ai Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
const { program } = require("commander"); program .name("myprogram") .usage("[options] ") .description("My awesome program that does cool stuff.") .option("-v, --verbose", "Enable verbose output") .option("-f, --force", "Force file overwrite") .command("create ", "Create a new project") .command("serve [port]", "Start the server") .action((file) => { console.log(`Processing file: ${file}`); }); // Parse the command-line arguments program.parse(process.argv); // Output the help information if requested if (program.help) { program.outputHelp(); }
In this example, we have defined a simple Commander.js program that has a few options and commands. At the end of the program, we check if the help option has been specified using program.help. If it has, we call the program.outputHelp() method to print the program's help information to the console. The resulting output will look something like this: sql Copy code
224 225 226 227 228 229 230 231 232 233
.usage('app.js [options]') .parse(process.argv); if (process.argv.length == 2) { commander.parse(process.argv); commander.outputHelp(); process.exit(0); } if (!commander.args[0]) {
41 42 43 44 45 46 47 48 49 50
program .command('show-boards [organizationId]') .description('List the boards belonging to an organization') .action((organization) => { if (!organization) { return program.outputHelp(); } trelloGet(`1/organizations/${organization}/boards`) .then(result => result.map(board => ({id: board.id, name: board.name}))) .then(console.log);
+ 19 other calls in file
GitHub: ryanlelek/Raneto
![ryanlelek profile picture](/ryanlelek.png?size=40)
149 150 151 152 153 154 155
} program.parse(process.argv); if (!process.argv.slice(2).length) { program.outputHelp(customHelp); }
+ 3 other calls in file
GitHub: fent/node-ytdl
![fent profile picture](/fent.png?size=40)
27 28 29 30 31 32 33 34 35 36
.parse(process.argv) ; const chalk = require('chalk'); if (!url) { opts.outputHelp((help) => { return chalk.red('\n url argument is required\n') + help; }); process.exit(1); }
13 14 15 16 17 18 19 20 21 22
.option('--stat', '生成dcloud_stat统计代码') .option('-p, --platform [platform]', '可选`quickapp`|`uniapp`,目前仅支持小程序向quickapp或uniapp转换') .parse(process.argv) if (Program.help === undefined) { Program.outputHelp() process.exit(0) } if (Program.version === undefined) {
+ 15 other calls in file
139 140 141 142 143 144 145 146 147 148
.version('0.0.1') .command('getstream [url]', 'get stream URL') .parse(process.argv); if (!process.argv.slice(2).length) { program.outputHelp(make_red); } function make_red(txt) { return colors.red(txt); // 在控制台上显示红色的帮助文本
+ 3 other calls in file
65 66 67 68 69 70 71 72 73 74
displayToConsole(msg.red); }; /* istanbul ignore next */ program.on('command:*', function () { program.outputHelp(); // NOSONAR program.errorMessage('Unknown Command: ' + program.args.join(' ')); // NOSONAR }); program.getSpinner = function(){
99 100 101 102 103 104
}); program.parse(process.argv); // Print Usage output to console when user doesn't provie any command if (!process.argv.slice(2).length) program.outputHelp();
+ 3 other calls in file
GitHub: irislib/iris-cli
62 63 64 65 66 67 68 69 70 71 72 73 74
function runIdentifi() { identifi.parse(process.argv); if (!process.argv.slice(2).length) { identifi.outputHelp(); return; } var queryOptions = {
+ 7 other calls in file
21 22 23 24 25 26 27 28 29 30 31 32
.parse(process.argv) const hasOauth2 = !!program.refreshToken && !!program.instanceUrl const hasUserPass = !!program.username && !!program.password if (hasOauth2 && hasUserPass) { program.outputHelp(txt => { throw Error('Username + password OR refreshToken + instanceUrl are mandatory\n' + txt) }) } if (!program.clientId && process.env.SFDY_CLIENT_ID) program.clientId = process.env.SFDY_CLIENT_ID if (!program.clientSecret && process.env.SFDY_CLIENT_SECRET) program.clientSecret = process.env.SFDY_CLIENT_SECRET
GitHub: Archive-42/Curiosity
54 55 56 57 58 59 60 61 62 63 64 65 66 67
// show help by default if (!_cli.args.length) { _cli.outputHelp(); process.exit(0); }
+ 2 other calls in file
GitHub: AVA-Vaishu15/Newrepo
53 54 55 56 57 58 59 60 61 62 63 64
commands.parse(process.argv); // If no sensible data passed in just print help and exit var fromStdin = !process.env.__DIRECT__ && !process.stdin.isTTY; if (!fromStdin && commands.args.length === 0) { commands.outputHelp(); return 0; } // Now coerce commands into CleanCSS configuration...
+ 4 other calls in file
GitHub: haelge/andromeda
49 50 51 52 53 54 55 56 57 58 59 60 61
.parse(process.argv); // Show help by default if (!process.argv.slice(2).length) { Program.outputHelp(); process.exit(1); } // Update the vendor folder
commander.Option is the most popular function in commander (1786 examples)