Skip to content

command line flags: dashes and underscores synonyms#7406

Merged
shlomi-noach merged 7 commits intovitessio:masterfrom
planetscale:cli-flags-underscores
Feb 7, 2021
Merged

command line flags: dashes and underscores synonyms#7406
shlomi-noach merged 7 commits intovitessio:masterfrom
planetscale:cli-flags-underscores

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

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>
@shlomi-noach shlomi-noach requested a review from sougou as a code owner February 2, 2021 07:32
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
Collaborator

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

return strings.Join(parts, ",")
}

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

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.

}

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

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