MCPcopy
hub / github.com/tj/commander.js / command

Method command

lib/command.js:156–181  ·  view source on GitHub ↗

* Define a command. * * There are two styles of command: pay attention to where to put the description. * * @example * // Command implemented using action handler (description is supplied separately to `.command`) * program * .command('clone [destination]') * .de

(nameAndArgs, actionOptsOrExecDesc, execOpts)

Source from the content-addressed store, hash-verified

154 */
155
156 command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
157 let desc = actionOptsOrExecDesc;
158 let opts = execOpts;
159 if (typeof desc === 'object' && desc !== null) {
160 opts = desc;
161 desc = null;
162 }
163 opts = opts || {};
164 const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
165
166 const cmd = this.createCommand(name);
167 if (desc) {
168 cmd.description(desc);
169 cmd._executableHandler = true;
170 }
171 if (opts.isDefault) this._defaultCommandName = cmd._name;
172 cmd._hidden = !!(opts.noHelp || opts.hidden); // noHelp is deprecated old name for hidden
173 cmd._executableFile = opts.executableFile || null; // Custom name for executable file, set missing to null to match constructor
174 if (args) cmd.arguments(args);
175 this._registerCommand(cmd);
176 cmd.parent = this;
177 cmd.copyInheritedSettings(this);
178
179 if (desc) return this;
180 return cmd;
181 }
182
183 /**
184 * Factory routine to create a new unattached command.

Callers 15

makeProgramFunction · 0.95
makeProgramFunction · 0.95
makeProgramFunction · 0.95
createProgram1032Function · 0.95
makeHeatCommandFunction · 0.95
negatives.test.jsFile · 0.80

Calls 5

createCommandMethod · 0.95
_registerCommandMethod · 0.95
descriptionMethod · 0.80
argumentsMethod · 0.80
copyInheritedSettingsMethod · 0.80

Tested by 9

makeProgramFunction · 0.76
makeProgramFunction · 0.76
makeProgramFunction · 0.76
createProgram1032Function · 0.76
getSingleArgCasesFunction · 0.64
getMultipleArgCasesFunction · 0.64
makeProgramFunction · 0.64
makeProgramFunction · 0.64
createProgramFunction · 0.64