How to use the version function from commander
Find comprehensive JavaScript commander.version code examples handpicked from public code repositorys.
commander.version is a method in the Commander.js package for Node.js that specifies the version number of a command-line interface (CLI) tool.
100 101 102 103 104 105 106 107 108 109
}); } // global options addOptions( program.version(WebPageTest.version), [mapping.options.common, { 'out': { key: 'o', param: 'file',
+ 15 other calls in file
59 60 61 62 63 64 65 66 67
For larger programs which may use commander in multiple ways, including unit testing, it is better to create a local Command object to use. ```js const commander = require('commander'); const program = new commander.Command(); program.version('0.0.1'); ``` ## Options
How does commander.version work?
commander.version is a method in the Commander.js package for Node.js that specifies the version number of a command-line interface (CLI) tool. When you call commander.version, you pass in the version number of your CLI tool as a string. This version number will be displayed when users run the --version command, which is a common way for users to check the version of a CLI tool. By default, Commander.js includes a --version option that can be used to display the version number of the CLI tool. When this option is used, Commander.js will automatically print the version number specified by commander.version. In addition to specifying the version number, you can also customize the format of the version output using commander.versionOption. This method allows you to specify a custom version flag (e.g. -V instead of --version) and a custom version description. By using commander.version, you can make it easy for users to check the version of your CLI tool, ensuring that they are using the correct version and avoiding any potential compatibility issues.
GitHub: didi/chameleon
10 11 12 13 14 15 16 17 18 19
cml.log.notice(`current running chameleon(${cml.root})`) version(); } else { let extCommand = require('../commanders/ext/index.js').name; commander.usage('[command] [options]') commander.version(`${cmlpackage.name}@${cmlpackage.version}`) let cmdList = ['init', 'dev', 'build', 'server', 'web', 'weex', 'wx', 'baidu', 'alipay', 'qq', 'tt','info']; if (typeof extCommand === 'string') { cmdList.push('ext'); }
+ 19 other calls in file
GitHub: springernature/boomcatch
27 28 29 30 31 32 33 34 35 36
parseCommandLine(); runServer(); function parseCommandLine () { cli.version(packageInfo.version) .option('-n, --host <name>', 'host name to accept connections on, default is 0.0.0.0 (INADDR_ANY)') .option('-p, --port <port>', 'port to accept connections on, default is 80 for HTTP or 443 for HTTPS', parseInt) .option('-t, --https', 'start the server in HTTPS mode') .option('-x, --httpsPfx <string>', 'PFX/PKCX12 string containing private key, certificate and CA certs (HTTPS only)')
+ 9 other calls in file
Ai Example
1 2 3 4 5 6 7 8 9 10
const program = require("commander"); // Specify the version number of the CLI tool program.version("1.0.0"); // Define commands and options for the CLI tool // ... // Parse command-line arguments program.parse(process.argv);
In this example, we start by requiring the commander module and creating a new Commander.js program instance. We then call program.version to specify the version number of the CLI tool. In this case, we're using the version number 1.0.0. We can then define commands and options for our CLI tool using other methods in the program instance. Finally, we call program.parse to parse the command-line arguments and execute the appropriate commands and options. When a user runs the --version command, Commander.js will automatically display the version number specified by program.version. For example: css Copy code
GitHub: claudioc/jingo
93 94 95 96 97 98 99 100 101
http.createServer(app).listen(config.get('server').port, listenAddr, function () { console.log( new Date() + ' - Jingo%sserver v%s listening on port %s', config.get('server').localOnly ? ' (local) ' : ' ', program.version(), config.get('server').port ) })
+ 15 other calls in file
GitHub: ProofSuite/togen-cli
2 3 4 5 6 7 8 9 10 11
const Togen = require('../lib/togen') class Cmd { constructor() { program.version('0.1') this.togen = new Togen() } process(args) {
GitHub: ngx-metaui/rules
10 11 12 13 14 15 16 17 18 19
const devMode = process.argv.length > 0 && process.argv[1].indexOf('libs/rules/src/lib/resources/bin/oss.js') > 0; if (!devMode) { program.version(require('../../package').version); } program.option('-i, --in <oss-dir>', 'Input OSS file to be wrapped into .ts')
GitHub: DzyubSpirit/metatests
210 211 212 213 214 215 216 217 218 219
}); }; const getConfig = () => { const version = parseFile(path.resolve(__dirname, '../package.json')).version; program.version(version).usage('[options] -- <file ...>'); cliOptions.forEach(option => program.option(...option)); program.parse(process.argv); const config = program.config ? parseFile(program.config) : {};
+ 5 other calls in file
GitHub: thefeds/thundermole
28 29 30 31 32 33 34 35 36 37
configureProgram(program); runProgram(program); function configureProgram (program) { program.version(pkg.version) .option('-c, --config <path>', 'the directory to look for config files in') .option('-C, --cluster', 'create a cluster of workers for handling requests') .option('-p, --port <port>', 'the port to run on') .option('-w, --workers <num>', 'the number of workers to add to the cluster')
GitHub: duanewood/cloudli
56 57 58 59 60 61 62 63 64 65
* cloudli:traverseBatch * cloudli:elasticsearch */ function runCommands(commands) { program.version('1.4.4') const logger = getLogger() try {
+ 3 other calls in file
GitHub: clerie/jingo
62 63 64 65 66 67 68 69 70 71
}, get proxyPath () { return config.getProxyPath() }, get jingoVersion () { return program.version() }, get authentication () { return config.get('authentication') },
2 3 4 5 6 7 8 9 10 11 12
const program = require('commander'); module.exports = _ => { console.log(chalk.redBright('Prepare...')); console.time("Prepared"); program.version('1.2.64'); program.option('-f, --features [path]', 'location of features/[path]'); program.option('-s, --specs [files]', 'location pattern files'); program.option('-t, --tags [tags]', 'run features filtered by tags'); program.option('-r, --remote [host]', 'remote server [http://ex.com:4444]');
GitHub: homebridge/wifi-connect
35 36 37 38 39 40 41 42 43 44 45 46
}, 1000); } } function daemon() { program.version(pjson.version, "-v, --version", "output the current version"); program.option("-d, --debug", "turn on debug level logging", () => { log.debugging = true; }); program.command("start", { isDefault: true }) .description("start the portal service")
GitHub: Jaliborc/upmod
101 102 103 104 105 106 107 108 109 110 111 112
.catch(error) }) .catch(error) }) commander.version('2.0').parse(process.argv) } async function configuration() { answer = await inquirer.prompt([{
GitHub: kallioaleksi/slackstatus
32 33 34 35 36 37 38 39 40 41 42 43
} }, 100); }); function parseArgs(args) { program.version("1.0.0", "-v, --version"); program .command("token [token]") .description("Saves your token")
+ 3 other calls in file
GitHub: rafaapcode/cli
0 1 2 3 4 5 6 7 8 9 10
const Commander = require("commander"); const Database = require("./database"); const Heroi = require("./heroi"); async function main() { Commander.version("1.0.0") .option("-n, --nome [value]", "Nome do Heroi") .option("-p, --poder [value]", " Poder do Heroi") .option("-i, --id [value]", "ID do Heroi")
+ 17 other calls in file
20 21 22 23 24 25 26 27 28 29 30 31
const Logger = require('../Logger'); const utils = require('../utils'); const SIZES = new Set(['stat', 'parsed', 'gzip']); const program = commander.version(require('../../package.json').version).usage(`<bundleStatsFile> [bundleDir] [options] Arguments: bundleStatsFile Path to Webpack Stats JSON file.
+ 10 other calls in file
18 19 20 21 22 23 24 25 26 27 28 29
var viewer = require('../viewer'); var Logger = require('../Logger'); var SIZES = new Set(['stat', 'parsed', 'gzip']); var program = commander.version(require('../../package.json').version).usage(`<bundleStatsFile> [bundleDir] [options] Arguments: bundleStatsFile Path to Webpack Stats JSON file.
+ 9 other calls in file
6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347
format: myFormat })); } try { program.version('1.0.0', '--version'); program.command('word-counter <string>').description('Count number of words in a given string').action(string => { logger.info(`Your string has ${sentenceWordCounter(string)} word(s)`); }); program.parse(process.argv);
commander.Option is the most popular function in commander (1786 examples)