How to use the Argument function from commander

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

commander.Argument is a class used to define and parse command-line arguments in Node.js applications using the Commander.js library.

9
10
11
12
13
14
15
16
17
18

/**
 * Expose classes. The FooT versions are just types, so return Commander original implementations!
 */

exports.Argument = commander.Argument;
exports.Command = commander.Command;
exports.CommanderError = commander.CommanderError;
exports.Help = commander.Help;
exports.InvalidArgumentError = commander.InvalidArgumentError;
fork icon4
star icon27
watch icon2

+ 7 other calls in file

24
25
26
27
28
29
// Here we roll our own, the way Commander might in future.
exports.createCommand = (name) => new commander.Command(name);
exports.createOption = (flags, description) =>
  new commander.Option(flags, description);
exports.createArgument = (name, description) =>
  new commander.Argument(name, description);
fork icon6
star icon7
watch icon0

+ 3 other calls in file

How does commander.Argument work?

commander.Argument is a class constructor provided by the commander package in Node.js, which is used to create a new command-line argument with a given name and description. When an instance of this class is created, it defines the name and description of the argument along with its optional and required values, and also provides options to customize its behavior. The created argument can be added to a command object to parse command-line arguments provided by the user.

0
1
2
3
4
5
6
7
8
9
10
#!/usr/bin/env node
const { program, Argument } = require('commander');
require('colors');


program.usage("input-folder [options]")
    .addArgument(new Argument('[string]', `folder path or pattern of ${'glob'.green}`.grey))
    .option(
        '-f, --format [string]',
        `format of spritesheet.\n`.grey +
        `[ json, jsonarray , phaser, cocos2d , cocos2d-v3 , pixi.js , easel.js , laya , egret , yaml , zebkit , starling , sparrow , css ]`.yellow)
fork icon1
star icon3
watch icon1

+ 5 other calls in file

162
163
164
165
166
167
168
169
170
171
172
    initClient(options);
  });


program
  .command('config')
  .addArgument(new Argument('<type>', 'config type').choices(['jwt', 'server', 'path']))
  .argument('<value>', 'config value')
  .option('-p --profile <string>', 'setting profile name', 'default')
  .action((type, value, options) => {
    const configDir = path.resolve(os.homedir(), '.lite-http-tunnel');
fork icon1
star icon2
watch icon0

Ai Example

1
2
3
4
5
6
7
8
const { Command } = require("commander");
const program = new Command();

program.arguments(" ").action((file) => {
  console.log("File:", file);
});

program.parse(process.argv);

In this example, commander.Argument is used internally by the .arguments() method to define a single positional argument named file. When the program is executed with a filename as the first argument, the file variable is set to the argument value and passed to the .action() callback function.

132
133
134
135
136
137
138
139
140
141
142


program
  .command('new')
  .description('Create new Feature or Element from starter files')
  .usage('<type> <name> [include]')
  .addArgument(new commander.Argument('<type>', 'Define the type of scaffold to create').choices(['feature', 'element']))
  .argument('<name>', 'Handleized name for the new element|feature')
  .argument('[include]', 'Comma-separated list of starter directories and files to include in your scaffold. Defaults to all if not provided. all,config,install,sections,snippets,schema,styles')
  .action((type, name, include, options, command) => {
    scriptMessage(command.name())
fork icon1
star icon1
watch icon0

+ 7 other calls in file

81
82
83
84
85
86
87
88
89
90
91
kafkaTopicCreateGennertator.destinationRoot('.');


const topicCreateCommand = new Command(createCommandName);
topicCreateCommand.description('Kafka Topic Command');
topicCreateCommand.alias('c');
topicCreateCommand.addArgument(new Argument('[name]', 'Topic name', ''));
topicCreateCommand.action((name) => {
	kafkaTopicCreateGennertator['topicName'] = name;
	kafkaTopicCreateGennertator.run();
});
fork icon0
star icon1
watch icon0

+ 9 other calls in file

33
34
35
36
37
38
39
40
41
42
43
topicGennertator.destinationRoot('.');


const topicCommand = new Command(topicCommandName);
topicCommand.description('create event topic');
topicCommand.alias('tp');
topicCommand.addArgument(new Argument('[name]', 'Topic name', ''));
topicCommand.action((name) => {
	topicGennertator['topicName'] = name;
	topicGennertator.run();
});
fork icon0
star icon1
watch icon0

+ 4 other calls in file

971
972
973
974
975
976
977
978
979
980
981
    void runOutputPackageVersion(dir);
  });


program.command('permissions')
  .description('Working with permissions in authorization microservice')
  .addArgument(new Argument('[action]', 'permissions action. export - dump from DB to files, sync - get microservices meta and update in schema DB').choices(['sync', 'export', 'import']))
  .option('--is-prod', 'run command in production', false)
  .action((action, { isProd }) => {
    void runAuthorizationPermissions(action, isProd);
  });
fork icon0
star icon0
watch icon1

+ 24 other calls in file

45
46
47
48
49
50
51
52
53
54
const cli_progress_1 = __importDefault(require("cli-progress"));
const bluebird_1 = require("bluebird");
const helpers_1 = require("./helpers");
const package_json_1 = require("./package.json");
commander_1.program
    .addArgument(new commander_1.Argument('<input_file>', 'File containing the locations (.csv or .txt)'))
    .addOption(new commander_1.Option('-o, --output [string]', 'Output file to save results'))
    .addOption(new commander_1.Option('--api-key [string]', 'HereAPI key to make the requests')
    .env('HEREAPI_KEY')
    .makeOptionMandatory())
fork icon0
star icon0
watch icon2

+ 4 other calls in file

Other functions in commander

Sorted by popularity

function icon

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