-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Refactor getCommandAndParents()
into Command._getCommandAndAncestors()
and use consistently
#1939
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,10 +101,10 @@ class Help { | |
if (!this.showGlobalOptions) return []; | ||
|
||
const globalOptions = []; | ||
for (let parentCmd = cmd.parent; parentCmd; parentCmd = parentCmd.parent) { | ||
const visibleOptions = parentCmd.options.filter((option) => !option.hidden); | ||
cmd._getCommandAndAncestors().slice(1).forEach((ancestorCmd) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. Having to use the slice makes this too subtle for my liking. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Ok with the active variable changing to |
||
const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden); | ||
globalOptions.push(...visibleOptions); | ||
} | ||
}); | ||
if (this.sortOptions) { | ||
globalOptions.sort(this.compareOptions); | ||
} | ||
|
@@ -240,11 +240,11 @@ class Help { | |
if (cmd._aliases[0]) { | ||
cmdName = cmdName + '|' + cmd._aliases[0]; | ||
} | ||
let parentCmdNames = ''; | ||
for (let parentCmd = cmd.parent; parentCmd; parentCmd = parentCmd.parent) { | ||
parentCmdNames = parentCmd.name() + ' ' + parentCmdNames; | ||
} | ||
return parentCmdNames + cmdName + ' ' + cmd.usage(); | ||
let ancestorCmdNames = ''; | ||
cmd._getCommandAndAncestors().slice(1).forEach((ancestorCmd) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. Having to use the slice makes this too subtle for my liking. |
||
ancestorCmdNames = ancestorCmd.name() + ' ' + ancestorCmdNames; | ||
}); | ||
return ancestorCmdNames + cmdName + ' ' + cmd.usage(); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be a
forEach
? (I don't like thefor ( of )
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be if not for the early exit that is impossible with
forEach
. I guess this is one of the cases where iterating manually via.parent
is more appropriate.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍