Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple arguments description from command description #1192

Closed
sergejostir opened this issue Feb 14, 2020 · 4 comments
Closed

Decouple arguments description from command description #1192

sergejostir opened this issue Feb 14, 2020 · 4 comments

Comments

@sergejostir
Copy link

sergejostir commented Feb 14, 2020

commander.js/index.js

Lines 1398 to 1416 in 516a14c

if (this._description) {
desc = [
this._description,
''
];
const argsDescription = this._argsDescription;
if (argsDescription && this._args.length) {
const width = this.padWidth();
const columns = process.stdout.columns || 80;
const descriptionWidth = columns - width - 5;
desc.push('Arguments:');
desc.push('');
this._args.forEach((arg) => {
desc.push(' ' + pad(arg.name, width) + ' ' + wrap(argsDescription[arg.name], descriptionWidth, width + 4));
});
desc.push('');
}
}

Hello.

Is there a special reason why we cannot only describe command arguments without the command itself?

@shadowspawn
Copy link
Collaborator

I think no special reason. That code matches the way they are specified, where the description is an expected parameter and the argsDescription is an optional parameter.

   * @param {string} str
   * @param {Object} [argsDescription]
...
  description(str, argsDescription)

(The argsDescription parameter is currently undocumented.)

@sergejostir
Copy link
Author

I see, but the current implementation makes it impossible to avoid adding command description, when you only want to describe arguments.

For example, when you have a self explanatory command, but want to provide some additional description for the arguments.

My proposal is to change that, so this._argsDescription will be displayed regardless of the this._description. Optionally the description() method could also be adjusted, so if the first argument (str) is an object then it would swap the arguments (so you don't need to explicitly make str null or ''.

@shadowspawn
Copy link
Collaborator

Given the arguments descriptions are not currently documented, I don't this this issue will affect many people. No further activity in a month. Closing.

My proposal is to change that, so this._argsDescription will be displayed regardless of the this._description.

PR for this is welcome if someone does want to fix it.

Optionally the description() method could also be adjusted, so if the first argument (str) is an object then it would swap the arguments (so you don't need to explicitly make str null or ''.

No, I do not want to complicate the method signature for a rare case.
Feel free to open a new issue if it comes up again, with new information and renewed interest.

Thank you for your contributions.

@shadowspawn
Copy link
Collaborator

In Commander 7, you can pass an empty string for the command description and supply an arguments description to add just arguments description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants