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

command line flags: dashes and underscores synonyms #7406

Merged
merged 7 commits into from
Feb 7, 2021

Conversation

shlomi-noach
Copy link
Contributor

@shlomi-noach shlomi-noach commented Jan 28, 2021

Description

As pointed by @deepthi here we use both dash-based and underscore-based command line flags. This PR show how we can make synonyms so we can standardize on one (underscored) over the other (dashes)

Related Issue(s)

See #7405

Checklist

  • Should this PR be backported?
  • Tests were added or are not required
  • Documentation was added or is not required

Impacted Areas in Vitess

Components that this PR will affect:

  • Query Serving
  • VReplication
  • Cluster Management
  • Build/CI
  • VTAdmin

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@@ -143,7 +143,8 @@ func init() {

flag.BoolVar(&enableHeartbeat, "heartbeat_enable", false, "If true, vttablet records (if master) or checks (if replica) the current time of a replication heartbeat in the table _vt.heartbeat. The result is used to inform the serving state of the vttablet via healthchecks.")
flag.DurationVar(&heartbeatInterval, "heartbeat_interval", 1*time.Second, "How frequently to read and write replication heartbeat.")
flag.BoolVar(&currentConfig.EnableLagThrottler, "enable-lag-throttler", defaultConfig.EnableLagThrottler, "If true, vttablet will run a throttler service, and will implicitly enable heartbeats")
flag.BoolVar(&currentConfig.EnableLagThrottler, "enable_lag_throttler", defaultConfig.EnableLagThrottler, "If true, vttablet will run a throttler service, and will implicitly enable heartbeats")
flag.BoolVar(&currentConfig.EnableLagThrottler, "enable-lag-throttler", currentConfig.EnableLagThrottler, "synonym to -enable_lag_throttler")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

notice both the target and the default are currentConfig.EnableLagThrottler

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@@ -144,6 +144,7 @@ func init() {
flag.BoolVar(&enableHeartbeat, "heartbeat_enable", false, "If true, vttablet records (if master) or checks (if replica) the current time of a replication heartbeat in the table _vt.heartbeat. The result is used to inform the serving state of the vttablet via healthchecks.")
flag.DurationVar(&heartbeatInterval, "heartbeat_interval", 1*time.Second, "How frequently to read and write replication heartbeat.")
flag.BoolVar(&currentConfig.EnableLagThrottler, "enable-lag-throttler", defaultConfig.EnableLagThrottler, "If true, vttablet will run a throttler service, and will implicitly enable heartbeats")
flag.BoolVar(&currentConfig.EnableLagThrottler, "enable_lag_throttler", currentConfig.EnableLagThrottler, "synonym to -enable-lag-throttler")
Copy link
Member

Choose a reason for hiding this comment

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

If both are specified, which one wins?
In order to standardize on underscore, should we document the _ version of the flag and call the other one a synonym?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in the above case, underscores override dashes. Or, actually, I think that just depends on the order specified on the command line (with any single-valued flag, you can specify it as many times you want on the CLI and the last one wins it all).

In order to standardize on underscore, should we document the _ version of the flag and call the other one a synonym?

Agreed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW confirmed, last flag specified on the command line wins, regardless of which order the flags are created in code.

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@shlomi-noach
Copy link
Contributor Author

reversed order: underscores is the official flag, dashes is the synonym.

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@shlomi-noach
Copy link
Contributor Author

Refactor: extracted the dual-case logic to flagutil

Copy link
Member

@deepthi deepthi left a comment

Choose a reason for hiding this comment

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

This is really cool. You may merge once the feedback is addressed.

@@ -124,3 +125,58 @@ func (value StringMapValue) String() string {
sort.Strings(parts)
return strings.Join(parts, ",")
}

// DualCaseStringListVar cretes a flag which supports both dashes and underscores
Copy link
Member

Choose a reason for hiding this comment

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

typo: cretes -> creates (applies to all the functions)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

@@ -124,3 +125,58 @@ func (value StringMapValue) String() string {
sort.Strings(parts)
return strings.Join(parts, ",")
}

// DualCaseStringListVar cretes a flag which supports both dashes and underscores
func DualCaseStringListVar(p *[]string, name string, value []string, usage string) {
Copy link
Member

Choose a reason for hiding this comment

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

Sorry to be nitpicky, but DualCase to me means upper/lower case. Here we are talking about two different formats. I suggest renaming these functions to DualFormat...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renaming. I used the term "Case" because it's common to refer to this as snake_case and kebab-case.

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@shlomi-noach shlomi-noach merged commit 20e1242 into vitessio:master Feb 7, 2021
@shlomi-noach shlomi-noach deleted the cli-flags-underscores branch February 7, 2021 07:18
@askdba askdba added this to the v10.0 milestone Feb 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants