-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[cli] [vtctl] Migrate all vtctl commands to pflag
#11320
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
Changes from all commits
8372e38
cb6a0ad
0866965
c859172
893482b
52582c5
7a99394
8868cea
453b1b4
3d44768
dd4a4a4
fb2ca46
87d23fd
02cdc4c
1b4b4e0
80ba3fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| - The deprecated `--mutex-profile-fraction` flag has been removed. Please use `--pprof=mutex` instead. | ||
| - The deprecated vtgate/vtexplain/vtcombo flag `--planner_version` has been removed. Please use `--planner-version` instead. | ||
| - The deprecated flag `--master_connect_retry` has been removed. Please use `--replication_connect_retry` instead. | ||
| - `vtctl` commands that take shard names and ranges as positional arguments (e.g. `vtctl Reshard ks.workflow -80 -40,40-80`) need to have their positional arguments separated from their flag arguments by a double-dash separator to avoid the new parsing library from mistaking them as flags (e.g. `vtctl Reshard ks.workflow -- -80 -40,40-80`). | ||
|
|
||
| #### Vindex Interface | ||
|
|
||
|
|
@@ -85,10 +86,10 @@ connections, similar to the way pooling happens for write buffers. Defaults to o | |
|
|
||
| We introduced the ability to resume a VDiff2 workflow: | ||
| ``` | ||
| $ vtctlclient --server=localhost:15999 VDiff -- --v2 customer.commerce2customer resume 4c664dc2-eba9-11ec-9ef7-920702940ee0 | ||
| $ vtctlclient --server=localhost:15999 VDiff --v2 customer.commerce2customer resume 4c664dc2-eba9-11ec-9ef7-920702940ee0 | ||
|
||
| VDiff 4c664dc2-eba9-11ec-9ef7-920702940ee0 resumed on target shards, use show to view progress | ||
|
|
||
| $ vtctlclient --server=localhost:15999 VDiff -- --v2 customer.commerce2customer show last | ||
| $ vtctlclient --server=localhost:15999 VDiff --v2 customer.commerce2customer show last | ||
|
|
||
| VDiff Summary for customer.commerce2customer (4c664dc2-eba9-11ec-9ef7-920702940ee0) | ||
| State: completed | ||
|
|
@@ -99,7 +100,7 @@ CompletedAt: 2022-06-26 22:44:31 | |
|
|
||
| Use "--format=json" for more detailed output. | ||
|
|
||
| $ vtctlclient --server=localhost:15999 VDiff -- --v2 --format=json customer.commerce2customer show last | ||
| $ vtctlclient --server=localhost:15999 VDiff --v2 --format=json customer.commerce2customer show last | ||
| { | ||
| "Workflow": "commerce2customer", | ||
| "Keyspace": "customer", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,29 @@ var ( | |
|
|
||
| func init() { | ||
| servenv.OnParse(func(fs *pflag.FlagSet) { | ||
| // N.B. This is necessary for subcommand pflag parsing when not using | ||
|
||
| // cobra (cobra is where we're headed, but for `vtctl` it's a big lift | ||
| // before the RC cut). | ||
| // | ||
| // Essentially, the situation we have here is that commands look like: | ||
| // | ||
| // `vtctl [global flags] <command> [subcommand flags]` | ||
| // | ||
| // Since the default behavior of pflag is to allow "interspersed" flag | ||
| // and positional arguments, this means that the initial servenv parse | ||
| // will complain if _any_ subocmmand's flag is provided; for example, if | ||
| // you were to invoke | ||
| // | ||
| // `vtctl AddCellInfo --root /vitess/global --server_address "1.2.3.4" global | ||
| // | ||
| // then you would get the error "unknown flag --root", even though that | ||
| // is a valid flag for the AddCellInfo flag. | ||
| // | ||
| // By disabling interspersal on the top-level parse, anything after the | ||
| // command name ("AddCellInfo", in this example) will be forwarded to | ||
| // the subcommand's flag set for further parsing. | ||
| fs.SetInterspersed(false) | ||
|
||
|
|
||
| logger := logutil.NewConsoleLogger() | ||
| fs.SetOutput(logutil.NewLoggerWriter(logger)) | ||
| fs.Usage = func() { | ||
|
|
@@ -156,12 +179,14 @@ func main() { | |
| default: | ||
| log.Warningf("WARNING: vtctl should only be used for VDiff workflows. Consider using vtctldclient for all other commands.") | ||
|
|
||
| wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient()) | ||
|
|
||
| if args[0] == "--" { | ||
| vtctl.PrintDoubleDashDeprecationNotice(wr) | ||
| args = args[1:] | ||
| } | ||
|
|
||
| action = args[0] | ||
| wr := wrangler.New(logutil.NewConsoleLogger(), ts, tmclient.NewTabletManagerClient()) | ||
| err := vtctl.RunCommand(ctx, wr, args) | ||
| cancel() | ||
| switch err { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -299,7 +299,7 @@ func performResharding(t *testing.T) { | |
| require.NoError(t, err) | ||
| } | ||
|
|
||
| err = clusterInstance.VtctlclientProcess.ExecuteCommand("Reshard", "--", "--v1", "ks.reshardWorkflow", "0", "-80,80-") | ||
| err = clusterInstance.VtctlclientProcess.ExecuteCommand("Reshard", "--", "--v1", "ks.reshardWorkflow", "0", "--", "-80,80-") | ||
|
||
| require.NoError(t, err) | ||
|
|
||
| err = clusterInstance.VtctlclientProcess.ExecuteCommand("SwitchReads", "--", "--tablet_types=rdonly", "ks.reshardWorkflow") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -418,7 +418,7 @@ func tlsPerformResharding(t *testing.T) { | |
| require.NoError(t, err) | ||
| } | ||
|
|
||
| err = clusterInstance.VtctlclientProcess.ExecuteCommand("Reshard", "ks.reshardWorkflow", "0", "-80,80-") | ||
| err = clusterInstance.VtctlclientProcess.ExecuteCommand("Reshard", "ks.reshardWorkflow", "0", "--", "-80,80-") | ||
|
||
| require.NoError(t, err) | ||
|
|
||
| err = clusterInstance.VtctlclientProcess.ExecuteCommand("SwitchReads", "--", "--tablet_type=rdonly", "ks.reshardWorkflow") | ||
|
|
||
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.
In total, I think we've made the double dash usage required to ensure correct behavior as part of this work (e.g. sub-command --help). IMO, we should make a more general announcement/summary that the double dash usage is required (even though in some cases things will work fine / the same w/o it).
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'm adding a deprecation notice to
vtctl.RunCommandthat i hope will help.