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 #2717

Merged
merged 8 commits into from
Feb 8, 2017
Merged

Centralize command-line parsing #2717

merged 8 commits into from
Feb 8, 2017

Conversation

kyhavlov
Copy link
Contributor

@kyhavlov kyhavlov commented Feb 7, 2017

This picks up from #2412 and converts the configtest and force-leave commands to use the Meta struct.

@slackpad
Copy link
Contributor

slackpad commented Feb 7, 2017

Running this locally I don't actually see any of the command-specific options, just the generic ones.

@kyhavlov
Copy link
Contributor Author

kyhavlov commented Feb 7, 2017

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.

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 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.

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 "+
Copy link
Contributor

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 "+
Copy link
Contributor

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)
Copy link
Contributor

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 {
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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{
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

"taking" into account

@slackpad
Copy link
Contributor

slackpad commented Feb 7, 2017

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.

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.

A few small things - otherwise LGTM!

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))
Copy link
Contributor

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.

Copy link
Contributor Author

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

"time"

"github.com/mitchellh/mapstructure"
"os"
Copy link
Contributor

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.

type FlagSetFlags uint

const (
FlagSetNone FlagSetFlags = iota << 1
Copy link
Contributor

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.

@kyhavlov kyhavlov merged commit a4cb414 into master Feb 8, 2017
@kyhavlov kyhavlov deleted the f-cli-rework branch February 8, 2017 02:15
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.

3 participants