-
-
Notifications
You must be signed in to change notification settings - Fork 140
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
Closed
keilin-anz
wants to merge
5
commits into
alecthomas:master
from
keilin-anz:feature/optionally-show-subcommand-flags
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6140b4d
feat: Allow full subcommand flag display
keilin-anz 913732a
fix: Improve subcommand optional flag summary logic
keilin-anz 86b234f
Add example of SubcommandsWithOptionalFlags option
keilin-anz 2f0bdbb
Rework changes to avoid breaking API changes
keilin-anz 3957ac6
Update test to use new assert package
keilin-anz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/alecthomas/kong" | ||
) | ||
|
||
var cli struct { | ||
DryRun string `help:"optional dry run flag"` | ||
Mandatory bool `required:"" help:"mandatory global flag"` | ||
Resource struct { | ||
Create struct { | ||
Name string `required:"" help:"name of the resource"` | ||
} `cmd:"" help:"create a resource"` | ||
Delete struct { | ||
Scope string `required:"" help:"mandatory subcommand flag"` | ||
Labels []string `help:"labels to match when deleting"` | ||
Version string `help:"version to match when deleting"` | ||
} `cmd:"" help:"delete resource(s)"` | ||
} `cmd:"" help:"operate on resources"` | ||
} | ||
|
||
func main() { | ||
ctx := kong.Parse(&cli, | ||
kong.Name("help"), | ||
kong.Description("An app demonstrating SubcommandsWithOptionalFlags"), | ||
kong.UsageOnError(), | ||
kong.ConfigureHelp(kong.HelpOptions{ | ||
SubcommandsWithOptionalFlags: true, | ||
})) | ||
ctx.Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.
Sorry for the epically late response. Overall the change looks good, but I can't merge this as it's a breaking API change.
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.
All good! my turn this time, was on a short break :)
FlagSummary
is a fairly short function - so if you don't mind my duplicating it I could turn this into an additive change, ie.Node.FlagSummaryWithOptions(bool, bool)
Node.SummaryWithOptions()
callsNode.FlagSummaryWithOptions(bool, bool)
insteadNode.FlagSummary()
returns to its original arityNode.Summary()
goes back to callingNode.FlagSummary(bool)
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.
Actually - given the current PR is unacceptable, I'll just make the changes now and see what you think :)
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.
Rebased, reworked changes to avoid API modification (and attempting to minimise duplication where possible)
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.
Just extra explanation re. bonus change in b196f4d : appears that my rebase picked up some change which is invalid with the current golangci-lint (see previous execution here: https://github.com/alecthomas/kong/actions/runs/3126674306/jobs/5072442276)
Seem fine now