Skip to content
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 part 2 #2723

Merged
merged 9 commits into from
Feb 10, 2017
Merged

Centralize command-line parsing part 2 #2723

merged 9 commits into from
Feb 10, 2017

Conversation

kyhavlov
Copy link
Contributor

@kyhavlov kyhavlov commented Feb 9, 2017

This converts the commands up through kv to use the base.Command structure for parsing.

Fixes #2566

@kyhavlov kyhavlov requested a review from slackpad February 9, 2017 00:40
// Change 'value' to 'string' for consistency
if example == "value" {
example = "string"
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a little strange; having common flags show up as -http-addr=<value> looks weird, though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm - we should probably keep the default Go behavior here for consistency. Looking at UnquoteUsage you can fix -http-addr by putting string in backquotes in the help text:

The `address` to connect to...

This will make it do -http-addr=<address> and is probably a better way to customize. While in here I realized that the description for -http-addr doesn't address UNIX sockets at all, so we need to touch that up a bit.

@@ -130,6 +140,9 @@ func (c *Command) Parse(args []string) error {

// Help returns the help for this flagSet.
func (c *Command) Help() string {
if c.flagSet == nil {
return ""
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure if there was a better solution than this for cases where Help() gets called before anything is initialized, like with the kv command and the kv tests that check for no tabs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this seems ok - I'd add a comment about why this is here.

Copy link
Contributor

@slackpad slackpad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted a new small things and then good to merge.

api/api.go Outdated
@@ -437,6 +450,9 @@ func (r *request) setWriteOptions(q *WriteOptions) {
if q.Token != "" {
r.header.Set("X-Consul-Token", q.Token)
}
if q.RelayFactor != 0 {
r.header.Set("relay-factor", strconv.Itoa(int(q.RelayFactor)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be a param set, not header.

@@ -130,6 +140,9 @@ func (c *Command) Parse(args []string) error {

// Help returns the help for this flagSet.
func (c *Command) Help() string {
if c.flagSet == nil {
return ""
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this seems ok - I'd add a comment about why this is here.

// Change 'value' to 'string' for consistency
if example == "value" {
example = "string"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm - we should probably keep the default Go behavior here for consistency. Looking at UnquoteUsage you can fix -http-addr by putting string in backquotes in the help text:

The `address` to connect to...

This will make it do -http-addr=<address> and is probably a better way to customize. While in here I realized that the description for -http-addr doesn't address UNIX sockets at all, so we need to touch that up a bit.

command/event.go Outdated
f.StringVar(&node, "node", "",
"Regular expression to filter on node names.")
f.StringVar(&service, "service", "",
"Regular expression to filter on service instances")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing period at the end of this one. We keep an eye out for this and try to make them all match (include the period).

@@ -101,7 +92,7 @@ func (c *EventCommand) Run(args []string) int {
}

// Create and test the HTTP client
client, err := HTTPClient(*httpAddr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self to make sure we delete this HTTPClient later.

f.BoolVar(&listKeys, "list", false,
"List all keys currently in use within the cluster.")
f.IntVar(&relay, "relay-factor", 0,
"Added in Consul 0.7.4, setting this to a non-zero value will cause nodes "+
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it makes sense to put these version notes in the actual command help, or just the web docs. If you are seeing this, then you have the right version :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's pretty redundant here, going to remove it.

"This is especially useful if you only need the key names themselves. "+
"This option is commonly combined with the -separator option. The default "+
"value is false.")
base64encode := f.Bool("base64", false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved up to keep them in sorted order.

recurse := f.Bool("recurse", false,
"Recursively look at all keys prefixed with the given path. The default "+
"value is false.")
separator := f.String("separator", "/",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ought to get a -stale option while we are in here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale is one of the common http options, are you referring to something else?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh then we need to plumb it into the options below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or does the API client plumb that in?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't; it gets passed in through the QueryOptions like this:

AllowStale: c.Command.HTTPStale(),

@@ -87,6 +87,10 @@
<a href="/docs/commands/force-leave.html">force-leave</a>
</li>

<li<%= sidebar_current("docs-commands-info") %>>
<a href="/docs/commands/info.html">info</a>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the whitespace got borked here.

@kyhavlov kyhavlov merged commit 8ecbd91 into master Feb 10, 2017
@kyhavlov kyhavlov deleted the f-cli-rework-2 branch February 10, 2017 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants