Skip to content

Commit

Permalink
Split 'Command' & 'Help' (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
cravler committed Apr 17, 2021
1 parent fb8165d commit f78c4ee
Show file tree
Hide file tree
Showing 5 changed files with 435 additions and 388 deletions.
24 changes: 23 additions & 1 deletion index.js
@@ -1,10 +1,32 @@
const { Argument } = require('./src/argument');
const { Command, Help } = require('./src/command');
const { Command: BaseCommand } = require('./src/command');
const { CommanderError, InvalidOptionArgumentError } = require('./src/errors');
const { Option } = require('./src/option');
const { Help } = require('./src/help');

// @ts-check

class Command extends BaseCommand {
/**
* @inheritdoc
*/

createCommand(...args) {
return new Command(...args);
};

/**
* You can customise the help with a subclass of Help by overriding createHelp,
* or by overriding Help properties using configureHelp().
*
* @return {Help}
*/

createHelp() {
return Object.assign(new Help(), this.configureHelp());
};
}

/**
* Expose the root command.
*/
Expand Down
17 changes: 17 additions & 0 deletions src/argument.js
Expand Up @@ -46,4 +46,21 @@ class Argument {
};
}

/**
* Takes an argument and returns its human readable equivalent for help usage.
*
* @param {Argument} arg
* @return {string}
* @api private
*/

function humanReadableArgName(arg) {
const nameOutput = arg.name() + (arg.variadic === true ? '...' : '');

return arg.required
? '<' + nameOutput + '>'
: '[' + nameOutput + ']';
}

module.exports.Argument = Argument;
module.exports.humanReadableArgName = humanReadableArgName;

0 comments on commit f78c4ee

Please sign in to comment.