-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Centralize command-line parsing #2717
Conversation
Running this locally I don't actually see any of the command-specific options, just the generic ones. |
Oops, I had added a check just before committing for hiding the 'Command Options' section if it was empty (for force-leave) and NFlag() wasn't the right thing to use for that. |
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.
Noted a few things but I think the approach will work. Only case that we might also want to double check is something with subcommands like operator
or kv
to make sure we haven't missed anything.
command/configtest.go
Outdated
f.Var((*agent.AppendSliceValue)(&c.configFiles), "config-file", | ||
"Path to a JSON file to read configuration from. This can be specified multiple times.") | ||
f.Var((*agent.AppendSliceValue)(&c.configFiles), "config-dir", | ||
"Path to a directory to read configuration files from. This will read every file ending in "+ |
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.
Extra space in here.
command/lock.go
Outdated
"implementation switches from a lock to a semaphore when the value is "+ | ||
"greater than 1. The default value is 1.") | ||
f.IntVar(&c.monitorRetry, "monitor-retry", defaultMonitorRetry, | ||
"Number of times to retry Consul returns a 500 error while monitoring "+ |
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 Consul returns"
command/lock.go
Outdated
if limit == 1 { | ||
*lu, err = c.setupLock(client, prefix, name, oneshot, wait, retry) | ||
if c.limit == 1 { | ||
*lu, err = c.setupLock(client, prefix, c.name, oneshot, c.timeout, c.monitorRetry) |
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.
These ended up a little weird passing member variables to member functions. I'd probably make these all local variables.
command/meta.go
Outdated
FlagSetHTTP FlagSetFlags = iota << 1 | ||
) | ||
|
||
type Meta struct { |
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.
Let's add a comment about what Meta
does - it's bad enough we have a class called Meta
:-D
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.
should we rename it to CommandMeta
or something similar? I agree the name's not great
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.
It's in the command
package, so it's already command.Meta
to the outside - I couldn't think of a better name for it. CommonFlags
or StandardFlags
might be better, do either of those seem good to you?
command/meta.go
Outdated
panic("flags have not been parsed") | ||
} | ||
|
||
return api.NewClient(&api.Config{ |
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.
I don't think this will respect the environment variables such as for the token. I think we need to start with an api.DefaultConfig()
and then optionally poke in the command line variables if they are present. See #2610.
command/meta.go
Outdated
return skip | ||
} | ||
|
||
// wrapAtLength wraps the given text at the maxLineLength, taxing into account |
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.
"taking" into account
Let's update the website docs for each command as we convert. That'll get them synced up and serve as a good sanity check. |
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.
A few small things - otherwise LGTM!
command/base/command.go
Outdated
c.httpAddr.Merge(&config.Address) | ||
c.token.Merge(&config.Token) | ||
c.datacenter.Merge(&config.Datacenter) | ||
c.Ui.Info(fmt.Sprintf("client http addr: %s", config.Address)) |
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.
This'll add clutter to the command output - let's drop this print.
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.
oops, this was a debug print that got left in
command/base/config_util.go
Outdated
"time" | ||
|
||
"github.com/mitchellh/mapstructure" | ||
"os" |
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.
These are messed up - should move them up.
command/base/command.go
Outdated
type FlagSetFlags uint | ||
|
||
const ( | ||
FlagSetNone FlagSetFlags = iota << 1 |
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.
These should be 1 << iota
.
This picks up from #2412 and converts the
configtest
andforce-leave
commands to use the Meta struct.