зеркало из https://github.com/github/vitess-gh.git
Better backwards compat/migration support
Signed-off-by: Andrew Mason <amason@slack-corp.com>
This commit is contained in:
Родитель
64a1a65512
Коммит
fa2a55e68d
|
@ -104,8 +104,45 @@ func main() {
|
|||
ctx, cancel := context.WithTimeout(context.Background(), *waitTime)
|
||||
installSignalHandlers(cancel)
|
||||
|
||||
if strings.EqualFold(action, "LegacyVtctlCommand") {
|
||||
// (TODO:ajm188) <Begin backwards compatibility support>.
|
||||
//
|
||||
// For v12, we are going to support new commands by prefixing as:
|
||||
// vtctl VtctldCommand <command> <args...>
|
||||
//
|
||||
// Existing scripts will continue to use the legacy commands. This is the
|
||||
// default case below.
|
||||
//
|
||||
// We will also support legacy commands by prefixing as:
|
||||
// vtctl LegacyVtctlCommand <command> <args...>
|
||||
// This is the fallthrough to the default case.
|
||||
//
|
||||
// In v13, we will make the default behavior to use the new commands and
|
||||
// drop support for the `vtctl VtctldCommand ...` prefix, and legacy
|
||||
// commands will only by runnable with the `vtctl LegacyVtctlCommand ...`
|
||||
// prefix.
|
||||
//
|
||||
// In v14, we will drop support for all legacy commands, only running new
|
||||
// commands, without any prefixing required or supported.
|
||||
switch {
|
||||
case strings.EqualFold(action, "VtctldCommand"):
|
||||
// New behavior. Strip off the prefix, and set things up to run through
|
||||
// the vtctldclient command tree, using the localvtctldclient (in-process)
|
||||
// client.
|
||||
vtctld := grpcvtctldserver.NewVtctldServer(ts)
|
||||
localvtctldclient.SetServer(vtctld)
|
||||
command.VtctldClientProtocol = "local"
|
||||
|
||||
os.Args = append([]string{"vtctldclient"}, args[1:]...)
|
||||
if err := command.Root.ExecuteContext(ctx); err != nil {
|
||||
log.Errorf("action failed: %v %v", action, err)
|
||||
exit.Return(255)
|
||||
}
|
||||
case strings.EqualFold(action, "LegacyVtctlCommand"):
|
||||
// Strip off the prefix (being used for compatibility) and fallthrough
|
||||
// to the legacy behavior.
|
||||
args = args[1:]
|
||||
fallthrough
|
||||
default:
|
||||
if args[0] == "--" {
|
||||
args = args[1:]
|
||||
}
|
||||
|
@ -125,35 +162,4 @@ func main() {
|
|||
exit.Return(255)
|
||||
}
|
||||
}
|
||||
|
||||
vtctld := grpcvtctldserver.NewVtctldServer(ts)
|
||||
localvtctldclient.SetServer(vtctld)
|
||||
command.VtctldClientProtocol = "local"
|
||||
for i, arg := range args {
|
||||
if strings.HasPrefix(arg, "-") {
|
||||
if len(arg) == 2 {
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.HasPrefix(arg, "--") {
|
||||
continue
|
||||
}
|
||||
|
||||
log.Warningf("Long arg %s begins with a single dash; this will not work in future versions.", arg)
|
||||
dashed := strings.ReplaceAll(arg, "_", "-")
|
||||
if arg != dashed {
|
||||
log.Warningf("Long arg %s is using underscore word separators, switching to dashes. This will not work in future versions.", arg)
|
||||
arg = dashed
|
||||
}
|
||||
|
||||
arg = "-" + arg
|
||||
args[i] = arg
|
||||
}
|
||||
}
|
||||
|
||||
os.Args = append([]string{"vtctldclient"}, args...)
|
||||
if err := command.Root.ExecuteContext(ctx); err != nil {
|
||||
log.Errorf("action failed: %v %v", action, err)
|
||||
exit.Return(255)
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче