[cli] [vtctl] Migrate all vtctl commands to pflag#11320
[cli] [vtctl] Migrate all vtctl commands to pflag#11320deepthi merged 16 commits intovitessio:mainfrom
pflag#11320Conversation
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Bug fixes
Non-trivial changes
New/Existing features
Backward compatibility
|
6f10ff1 to
73db936
Compare
73db936 to
8516f6e
Compare
There was a problem hiding this comment.
Something we'll need to note in the release notes, so I've added that label.
There was a problem hiding this comment.
It doesn't affect v2 workflows because the shards are passed as flags like vtctlclient Reshard -- --source_shards '0' --target_shards '-80,80-' Create customer.cust2cust where as in v1 workflows the shards are passed as Args like Reshard -- --v1 --cells=zone1 --tablet_types=replica,primary merchant-type.m2m3 -80,80- -40,40-c0,c0-
One possibility is to require quoting the shard arguments to the v1 workflows. That will require a trivial code change, however it will still make it backwardly incompatible. Since we have deprecated v1 workflows, the approach in this PR might be acceptable.
There was a problem hiding this comment.
One possibility is to require quoting the shard arguments to the v1 workflows.
this doesn't work (i tried it)
$ go run ./go/cmd/pflagtester -80,80-
unknown shorthand flag: '8' in -80,80-
Usage of /var/folders/8q/6w7llb2j03v454_4pcm68w7w0000gn/T/go-build3458657591/b001/exe/pflagtester:
--foo int (default 2)
unknown shorthand flag: '8' in -80,80-
exit status 2
$ go run ./go/cmd/pflagtester "-80,80-"
unknown shorthand flag: '8' in -80,80-
Usage of /var/folders/8q/6w7llb2j03v454_4pcm68w7w0000gn/T/go-build4228639101/b001/exe/pflagtester:
--foo int (default 2)
unknown shorthand flag: '8' in -80,80-
exit status 2
There was a problem hiding this comment.
rohit is correct thought that this only affects v1 workflows
There was a problem hiding this comment.
One possibility is to require quoting the shard arguments to the v1 workflows. That will require a trivial code change, however it will still make it backwardly incompatible. Since we have deprecated v1 workflows, the approach in this PR might be acceptable.
I mean't after the code change referred to above, we can support quotes. But it just replaces one incompatibility with another ...
There was a problem hiding this comment.
ahh, gotcha gotcha, sorry i misunderstood!
go/vt/vtctl/cells_aliases.go
Outdated
There was a problem hiding this comment.
Did you intend to leave the commented line? There is one more below.
There was a problem hiding this comment.
ohhh weird, no i didn't!
doc/releasenotes/15_0_0_summary.md
Outdated
There was a problem hiding this comment.
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.
i'm adding a deprecation notice to vtctl.RunCommand that i hope will help.
doc/releasenotes/15_0_0_summary.md
Outdated
There was a problem hiding this comment.
Why remove the double dashes? Compare the output of these two things for an example of why I think we should always use them and why I feel the way I do about noting that it's (virtually) required now in the release notes:
$ vtctlclient --server=localhost:15999 VDiff --help
$ vtctlclient --server=localhost:15999 VDiff -- --help
This same comment applies to all of the other places we remove them in the PR.
There was a problem hiding this comment.
because that gets in the way of moving to cobra (cobra does one full-blown parse by merging together the parent/subcommand flag-sets, so if you have the -- after the sub-command name then all the sub-command flags get treated as positional arguments instead of flags)
go/cmd/vtctl/vtctl.go
Outdated
go/cmd/vtctl/vtctl.go
Outdated
There was a problem hiding this comment.
Ah, I guess this is why you removed the double dashes? I still think we should leave them as the help output is still different, and it would be nice to have some uniformity across the client commands/binaries. Unless I'm misunderstanding something?
There was a problem hiding this comment.
We don't need both double dashes do we? Is the first one not enough?
There was a problem hiding this comment.
#11320 (comment) sort of explains it. the double-dash breaks further parsing, so everything after it (--v1, in this case) because a positional argument. so you want this after your last "true" flag
go/vt/vtctl/vtctl.go
Outdated
There was a problem hiding this comment.
IF the double dash after Reshard also works I'd much prefer that as we've been pushing people in that direction for a while.
|
so, new problem (maybe) i think in order to get the vtctld_web_test to pass, i need to apply the following diff: diff --git a/web/vtctld2/src/app/shared/flags/flag.ts b/web/vtctld2/src/app/shared/flags/flag.ts
index d8fc03d023..15107e001a 100644
--- a/web/vtctld2/src/app/shared/flags/flag.ts
+++ b/web/vtctld2/src/app/shared/flags/flag.ts
@@ -110,7 +110,7 @@ export class Flag {
if (this.getValue() === true) {
return [`-${this.id}`];
}
- return [`-${this.id}=${this.getStrValue()}`];
+ return [`--${this.id}=${this.getStrValue()}`];
}
}This creates at least one problem:
@deepthi what do you think? |
yes, we will need to rebuild/regen that. we can ask @notfelineit to help, she had the build working at some point.
Should be fine |
|
@ajm188 I suspect more changes are needed in flag.ts That's 3 more places where we have |
|
yeah, i just went ahead and double-dashed everything. i also tried all morning to get @notfelineit when you get a chance can you re-run the web build? (not urgent ❤️ ) |
Closes vitessio#11304. Signed-off-by: Andrew Mason <andrew@planetscale.com>
Signed-off-by: Andrew Mason <andrew@planetscale.com>
Signed-off-by: Andrew Mason <andrew@planetscale.com>
Signed-off-by: Andrew Mason <andrew@planetscale.com>
Signed-off-by: Andrew Mason <andrew@planetscale.com>
Signed-off-by: Andrew Mason <andrew@planetscale.com>
Signed-off-by: Andrew Mason <andrew@planetscale.com>
Signed-off-by: Andrew Mason <andrew@planetscale.com>
Signed-off-by: Andrew Mason <andrew@planetscale.com>
Signed-off-by: Andrew Mason <andrew@planetscale.com>
Signed-off-by: Andrew Mason <andrew@planetscale.com>
Signed-off-by: notfelineit <notfelineit@gmail.com>
Signed-off-by: deepthi <deepthi@planetscale.com>
Signed-off-by: Andrew Mason <andrew@planetscale.com>
Signed-off-by: Andrew Mason <andrew@planetscale.com>
65443b4 to
1b4b4e0
Compare
|
note the failing test will pass after we re-build the frontend bundle: |
Signed-off-by: notfelineit <notfelineit@gmail.com>
Description
See the lengthy comment in
go/cmd/vtctl/vtctl.go'sinitfunction for the bulk of the explanation of what's happening here, but this mostly works.The one thing that seems to be a potential problem is commands that take shard names or ranges as positional arguments, if and only if those names begin with a dash (e.g. "-80,80-"), because
pflagsees the dash and tries to find a shorthand option with that name (leading to fun errors likeunknown shorthand flag: '8' in -80,80-), but putting a double-dash to stop parsing works (and is something we've been pushing users toward so I feel okay about it, but let me know if there's a strong disagreement.Related Issue(s)
Closes #11304.
Checklist
Deployment Notes