Commander Mp Command

0 views
Skip to first unread message

Pernilla Gendron

unread,
Aug 5, 2024, 12:08:22 AM8/5/24
to tioprocemne
Hereis a more complete program using a subcommand and with descriptions for the help. In a multi-command program, you have an action handler for each command (or stand-alone executables for the commands).

Options are defined with the .option() method, also serving as documentation for the options. Each option can have a short flag (single character) and a long name, separated by a comma or space or vertical bar ('').


The two most used option types are a boolean option, and an option which takes its valuefrom the following argument (declared with angle brackets like --expect ). Both are undefined unless specified on command line.


Multiple boolean short options may be combined following the dash, and may be followed by a single short option taking a value.For example -d -s -p cheese may be written as -ds -p cheese or even -dsp cheese.


Options with an optional option-argument are not greedy and will ignore arguments starting with a dash.So id behaves as a boolean option for --id -5, but you can use a combined form if needed like --id=-5.


You may specify a required (mandatory) option using .requiredOption(). The option must have a value after parsing, usually specified on the command line, or perhaps from a default value (say from environment). The method is otherwise the same as .option() in format, taking flags and description, and optional default value or custom processing.


You may make an option variadic by appending ... to the value placeholder when declaring the option. On the command line youcan then specify multiple option-arguments, and the parsed option value will be an array. The extra argumentsare read until the first argument starting with a dash. The special argument -- stops option processing entirely. If a valueis specified in the same argument as the option then no further values are read.


You may specify a function to do custom processing of option-arguments. The callback function receives two parameters,the user specified option-argument and the previous value for the option. It returns the new value for the option.


You can specify (sub)commands using .command() or .addCommand(). There are two ways these can be implemented: using an action handler attached to the command, or as a stand-alone executable file (described in more detail later). The subcommands may be nested (example).


In the first parameter to .command() you specify the command name. You may append the command-arguments after the command name, or specify them separately using .argument(). The arguments may be or [optional], and the last argument may also be variadic....


Configuration options can be passed with the call to .command() and .addCommand(). Specifying hidden: true willremove the command from the generated help output. Specifying isDefault: true will run the subcommand if no othersubcommand is specified (example).


.command() automatically copies the inherited settings from the parent command to the newly created subcommand. This is only done during creation, any later setting changes to the parent are not inherited.


For subcommands, you can specify the argument syntax in the call to .command() (as shown above). Thisis the only method usable for subcommands implemented using a stand-alone executable, but for other subcommandsyou can instead use the following method.


To configure a command, you can use .argument() to specify each expected command-argument.You supply the argument name and an optional description. The argument may be or [optional].You can specify a default value for an optional command-argument.


The last argument of a command can be variadic, and only the last argument. To make an argument variadic youappend ... to the argument name. A variadic argument is passed to the action handler as an array. For example:


You may specify a function to do custom processing of command-arguments (like for option-arguments).The callback function receives two parameters, the user specified command-argument and the previous value for the argument.It returns the new value for the argument.


If you prefer, you can work with the command directly and skip declaring the parameters for the action handler. The this keyword is set to the running command and can be used from a function expression (but not from an arrow function).


A command's options and arguments on the command line are validated when the command is used. Any unknown options or missing arguments will be reported as an error. You can suppress the unknown option checks with .allowUnknownOption(). By default, it is not an error topass more arguments than declared, but you can make this an error with .allowExcessArguments(false).


When .command() is invoked with a description argument, this tells Commander that you're going to use stand-alone executables for subcommands.Commander will search the files in the directory of the entry script for a file with the name combination command-subcommand, like pm-install or pm-search in the example below. The search includes trying common file extensions, like .js.You may specify a custom name (and path) with the executableFile configuration option.You may specify a custom search directory for subcommands with .executableDir().


A help command is added by default if your command has subcommands. It can be used alone, or with a subcommand name to showfurther help for the subcommand. These are effectively the same if the shell program has implicit help:


You may specify the program name using .name() or in the Command constructor. For the program, Commander willfall back to using the script name from the full arguments passed into .parse(). However, the script name variesdepending on how your program is launched, so you may wish to specify it explicitly.


The built-in help is formatted using the Help class.You can configure the Help behaviour by modifying data properties and methods using .configureHelp(), or by subclassing using .createHelp() if you prefer.


You can override any method on the Help class. There are methods getting the visible lists of arguments, options, and subcommands. There are methods for formatting the items in the lists, with each item having a term and description. Take a look at .formatHelp() to see how they are used.


By default, program options are recognised before and after subcommands. To only look for program options before subcommands, use .enablePositionalOptions(). This lets you usean option for a different purpose in subcommands.


By default, options are recognised before and after command-arguments. To only process options that comebefore the command-arguments, use .passThroughOptions(). This lets you pass the arguments and following options through to another programwithout needing to use -- to end the option processing.To use pass through options in a subcommand, the program needs to enable positional options.


By default, the option processing shows an error for an unknown option. To have an unknown option treated as an ordinary command-argument and continue looking for options, use .allowUnknownOption(). This lets you mix known and unknown options.


Before Commander 7, the option values were stored as properties on the command.This was convenient to code, but the downside was possible clashes withexisting properties of Command. You can revert to the old behaviour to run unmodified legacy code by using .storeOptionsAsProperties().


extra-typings: There is an optional project to infer extra type information from the option and argument definitions.This adds strong typing to the options returned by .opts() and the parameters to .action().See commander-js/extra-typings for more.


createCommand is also a method of the Command object, and creates a new command rather than a subcommand. This gets used internallywhen creating subcommands using .command(), and you may override it tocustomise the new subcommand (example file custom-command-class.js).


By default, when you call your program using run-script, npm will parse any options on the command-line and they will not reach your program. Use-- to stop the npm option parsing and pass through all the arguments.


By default, Commander calls process.exit when it detects errors, or after displaying the help or version. You can overridethis behaviour and optionally supply a callback. The default override throws a CommanderError.


The override callback is passed a CommanderError with properties exitCode number, code string, and message.Commander expects the callback to terminate the normal program flow, and will call process.exit if the callback returns.The normal display of error messages or version or help is not affected by the override which is called after the display.


By default, Commander is configured for a command-line application and writes to stdout and stderr.You can modify this behaviour for custom applications. In addition, you can modify the display of error messages.


The maintainers of Commander and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.


Wilsbach comes to ACC from Pacific Air Forces in Hawaii, where he served as commander since July 2020. As the commander of ACC, he now oversees more than 156,000 Total Force Airmen and civilians operating around the world.


ACC is the primary force provider of combat airpower to America's warfighting commands. ACC organizes, trains, equips and maintains combat-ready forces for rapid deployment and employment while ensuring strategic air defense forces are ready to meet the challenges of peacetime air sovereignty and wartime air defense.


Prior to commanding 7th Fleet, Thomas served as the assistant deputy chief of naval operations, plans, and strategy, a role Kacher also held. Thomas began his career as an E-2C Hawkeye aviator, and he commanded a carrier airborne early warning squadron, two aircraft carriers and the forward-deployed Carrier Strike Group in Japan. His follow-on assignment will be the deputy chief of naval operations for information warfare.

3a8082e126
Reply all
Reply to author
Forward
0 new messages