-
Notifications
You must be signed in to change notification settings - Fork 6
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
script: Use pflag for command arguments #30
Conversation
3e5a42b
to
148a40a
Compare
Validated in |
5ec99e3
to
55b68a7
Compare
Embed the pflag FlagSet into the command creation so we can show decent help for the flags. Signed-off-by: Jussi Maki <[email protected]>
55b68a7
to
92e3445
Compare
Converted statedb to use this: cilium/statedb#70. That unfortunately won't be backwards compatible and will need to fix things up when StateDB will be bumped. |
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.
🚀
if len(args) > 0 && args[0] == "-q" { | ||
quiet = true | ||
args = args[1:] | ||
quiet, err := s.Flags.GetBool("quiet") |
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.
nit: would be nice to extract these as consts (quiet
)
fs.Bool("readonly", false, "File must not be writable") | ||
fs.Bool("exec", false, "File must not be executable") |
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.
nit: also these flags too, maybe? I was thinking to have a way to be able to re-use these flags that have high chance to be re-used across cmds.
@@ -637,26 +643,20 @@ func Grep() Cmd { | |||
}) | |||
} | |||
|
|||
const matchUsage = "[-count=N] [-q] 'pattern'" | |||
func matchFlags(fs *pflag.FlagSet) { |
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.
👍 nicely reused
Embed the pflag FlagSet into the command creation so we can show decent help for the flags.
The
CmdUsage
now contains aFlags
field of typefunc(*pflag.FlagSet)
(similar tocell.Flagger
!) thatallows registering the flags. These flags are then shown in the help summary, e.g.
[-q] [--quiet]
forfs.BoolP("quiet", "q", ...)
and also expanded in the verbose help.For example
help
now looks like: