-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
bugCommander is not working as intendedCommander is not working as intended
Milestone
Description
Hi - noticed something that maybe isn't desired behaviour with the above two methods. Since copyInheritedSettings sets this._outputConfiguration = sourceCommand._outputConfiguration and configureOutput does Object.assign(...) - this means that one command can change another command's settings unexpectedly:
import {program, Command} from 'commander'
const one = new Command('one')
.description('A very very very very very very very very very very very very very very very very very very very very very very very very long description')
.action(() => console.log('hi i am one'))
.configureOutput({
writeOut: str => console.log(str + '🚀🚀🚀🚀'),
getOutHelpWidth: () => 70,
})
const two = new Command('two')
.copyInheritedSettings(one)
.description('Another very very very very very very very very very very very very very very very very very very very very very very very very long description')
.action(() => console.log('hi i am two'))
.configureOutput({
getOutHelpWidth: () => 200,
})
program
.addCommand(one)
.addCommand(two)
program.parse()When you do mycommand one --help it uses 200 for the help width, not 70 as I'd expect. (Note: mycommand two --help prints the 🚀🚀🚀🚀 at the bottom, which is correct/expected, IMO).
Suggested solution: use a spread operator in either/both of the methods.
Metadata
Metadata
Assignees
Labels
bugCommander is not working as intendedCommander is not working as intended