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
new HelpOption: Allow full subcommand flag display #306
Open
keilin-anz
wants to merge
5
commits into
alecthomas:master
Choose a base branch
from
keilin-anz:feature/optionally-show-subcommand-flags
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
new HelpOption: Allow full subcommand flag display #306
keilin-anz
wants to merge
5
commits into
alecthomas:master
from
keilin-anz:feature/optionally-show-subcommand-flags
Commits on Mar 5, 2024
-
feat: Allow full subcommand flag display
By default, only `required` flags are displayed for subcommands For applications with a lot of simple subcommands this obscures basic usage flags == Mitigation - Add a new `HelpOption` called `IncludeOptionalFlagsInSummary` - Move `Node.Summary()` functionality into `Node.SummaryWithOptions(bool)` - Retain `Node.Summary()` as a default usage (forwards default value to `Node.SummaryWithOptions(bool)`) - Modify `help.go@printCommandSummary()` to forward the `HelpOption` to `Node.SummaryWithOptions()` instead of calling `Node.Summary()` - Add tests for default and optional behaviour == Caveats The main issue with this implementation is due to the `Node` receiver functions doing display logic internally. This makes sense for most of the use cases (application error logic), but overly restricts the help configurability As a result: - Must pass awkward `bool` value down from the help context - `FlagSummary()` ends up having to explicitly exclude the `help` flag. == Potential improvements to be made - Remove explicit exclusion of `help` from `FlagSummary()` - Potentially add an equivalent `Node` receiver which just returns an array of flag summaries to be displayed by `help@printCommandSummary`
Configuration menu - View commit details
-
Copy full SHA for 6140b4d - Browse repository at this point
Copy the full SHA 6140b4dView commit details -
fix: Improve subcommand optional flag summary logic
- Adds `Parent` field to `Value`, allowing us to easily check whether a value originated with a given `Node` - Renames the new `HelpOption` to `SubcommandsWithOptionalFlags` - When the option is enabled - Groups required flags - Groups optional flags (by checking if the flag originated on the current Node) - Prints required flags followed by optional flags surrounded by brackets, eg. `--mandatory [ --optional1 --optional2 ]` - Removes janky check if a flag is `help` - Now just checks if the flag is our own - Added criteria to the test suite to confirm: - Ancestor's optional flags are not included - Ancestor's required flags are included
Configuration menu - View commit details
-
Copy full SHA for 913732a - Browse repository at this point
Copy the full SHA 913732aView commit details -
Configuration menu - View commit details
-
Copy full SHA for 86b234f - Browse repository at this point
Copy the full SHA 86b234fView commit details -
Rework changes to avoid breaking API changes
Addresses requested change here: https://github.com/alecthomas/kong/pull/306/files#r975322296
Configuration menu - View commit details
-
Copy full SHA for 2f0bdbb - Browse repository at this point
Copy the full SHA 2f0bdbbView commit details -
Update test to use new assert package
original PR was from prior to the switch from `require` to `assert` for tests (in this commit 8b82618) Just change to using `assert` in keeping with the rebase
Configuration menu - View commit details
-
Copy full SHA for 3957ac6 - Browse repository at this point
Copy the full SHA 3957ac6View commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.