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

[cmd/*] Switch to pflag for all CLI flag parsing #10619

Merged
merged 6 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion go/cmd/mysqlctl/mysqlctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"os"
"time"

"github.com/spf13/pflag"

"vitess.io/vitess/go/cmd"
"vitess.io/vitess/go/exit"
"vitess.io/vitess/go/flagutil"
Expand Down Expand Up @@ -248,7 +250,7 @@ func main() {
exit.Return(1)
}
dbconfigs.RegisterFlags(dbconfigs.Dba)
_flag.Parse()
_flag.Parse(pflag.NewFlagSet("mysqlctl", pflag.ExitOnError))

tabletAddr = netutil.JoinHostPort("localhost", int32(*port))

Expand Down
4 changes: 3 additions & 1 deletion go/cmd/query_analyzer/query_analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"os"
"sort"

"github.com/spf13/pflag"

"vitess.io/vitess/go/exit"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/sqlparser"
Expand Down Expand Up @@ -59,7 +61,7 @@ func (a stats) Less(i, j int) bool { return a[i].Count > a[j].Count }

func main() {
defer exit.Recover()
_flag.Parse()
_flag.Parse(pflag.NewFlagSet("query_analyzer", pflag.ExitOnError))
for _, filename := range _flag.Args() {
fmt.Printf("processing: %s\n", filename)
if err := processFile(filename); err != nil {
Expand Down
4 changes: 3 additions & 1 deletion go/cmd/topo2topo/topo2topo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"fmt"
"os"

"github.com/spf13/pflag"

"vitess.io/vitess/go/exit"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/logutil"
Expand Down Expand Up @@ -53,7 +55,7 @@ func main() {
defer exit.RecoverAll()
defer logutil.Flush()

_flag.Parse()
_flag.Parse(pflag.NewFlagSet("topo2topo", pflag.ExitOnError))
args := _flag.Args()
if len(args) != 0 {
flag.Usage()
Expand Down
4 changes: 3 additions & 1 deletion go/cmd/vtbench/vtbench.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"strings"
"time"

"github.com/spf13/pflag"

"vitess.io/vitess/go/exit"
"vitess.io/vitess/go/vt/dbconfigs"
"vitess.io/vitess/go/vt/log"
Expand Down Expand Up @@ -104,7 +106,7 @@ func main() {
defer exit.Recover()

flag.Lookup("logtostderr").Value.Set("true")
_flag.Parse()
_flag.Parse(pflag.NewFlagSet("vtbench", pflag.ExitOnError))

clientProto := vtbench.MySQL
switch *protocol {
Expand Down
3 changes: 2 additions & 1 deletion go/cmd/vtclient/vtclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"time"

"github.com/olekukonko/tablewriter"
"github.com/spf13/pflag"

"vitess.io/vitess/go/vt/concurrency"
"vitess.io/vitess/go/vt/log"
Expand Down Expand Up @@ -147,7 +148,7 @@ func main() {
}

func run() (*results, error) {
_flag.Parse()
_flag.Parse(pflag.NewFlagSet("vtclient", pflag.ExitOnError))
args := _flag.Args()

if len(args) == 0 {
Expand Down
4 changes: 3 additions & 1 deletion go/cmd/vtctlclient/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"strings"
"time"

"github.com/spf13/pflag"

"vitess.io/vitess/go/exit"
"vitess.io/vitess/go/trace"
"vitess.io/vitess/go/vt/log"
Expand Down Expand Up @@ -70,7 +72,7 @@ func checkDeprecations(args []string) {
func main() {
defer exit.Recover()

_flag.Parse()
_flag.Parse(pflag.NewFlagSet("vtctlclient", pflag.ExitOnError))

closer := trace.StartTracing("vtctlclient")
defer trace.LogErrorsWhenClosing(closer)
Expand Down
2 changes: 1 addition & 1 deletion go/cmd/vtgate/vtgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func main() {
log.Exitf("tablet_types_to_wait should contain at least one serving tablet type")
}

err := CheckCellFlags(context.Background(), resilientServer, *cell, *vtgate.CellsToWatch)
err := CheckCellFlags(context.Background(), resilientServer, *cell, vtgate.CellsToWatch)
if err != nil {
log.Exitf("cells_to_watch validation failed: %v", err)
}
Expand Down
4 changes: 3 additions & 1 deletion go/cmd/vtgr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"flag"
"strings"

"github.com/spf13/pflag"

"vitess.io/vitess/go/vt/vtgr"

// Include deprecation warnings for soon-to-be-unsupported flag invocations.
Expand All @@ -26,7 +28,7 @@ import (

func main() {
clustersToWatch := flag.String("clusters_to_watch", "", "Comma-separated list of keyspaces or keyspace/shards that this instance will monitor and repair. Defaults to all clusters in the topology. Example: \"ks1,ks2/-80\"")
_flag.Parse()
_flag.Parse(pflag.NewFlagSet("vtgr", pflag.ExitOnError))

// openTabletDiscovery will open up a connection to topo server
// and populate the tablets in memory
Expand Down
4 changes: 3 additions & 1 deletion go/cmd/vttlstest/vttlstest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"fmt"
"io"

"github.com/spf13/pflag"

"vitess.io/vitess/go/exit"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/logutil"
Expand Down Expand Up @@ -137,7 +139,7 @@ func main() {
_flag.SetUsage(flag.CommandLine, _flag.UsageOptions{
Preface: func(w io.Writer) { fmt.Fprint(w, doc) },
})
_flag.Parse()
_flag.Parse(pflag.NewFlagSet("vttlstest", pflag.ExitOnError))
args := _flag.Args()
if len(args) == 0 {
flag.Usage()
Expand Down
6 changes: 4 additions & 2 deletions go/cmd/zk/zkcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"syscall"
"time"

"github.com/spf13/pflag"
"github.com/z-division/go-zookeeper/zk"
"golang.org/x/term"

Expand Down Expand Up @@ -140,10 +141,11 @@ func main() {
defer exit.Recover()
defer logutil.Flush()

_flag.SetUsage(flag.CommandLine, _flag.UsageOptions{
fs := pflag.NewFlagSet("zkcmd", pflag.ExitOnError)
_flag.SetUsage(flag.CommandLine, _flag.UsageOptions{ // TODO: hmmm
Epilogue: func(w io.Writer) { fmt.Fprint(w, doc) },
})
_flag.Parse()
_flag.Parse(fs)
args := _flag.Args()
if len(args) == 0 {
flag.Usage()
Expand Down
4 changes: 3 additions & 1 deletion go/cmd/zkctl/zkctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"io"
"os"

"github.com/spf13/pflag"

"vitess.io/vitess/go/exit"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/logutil"
Expand Down Expand Up @@ -60,7 +62,7 @@ func main() {
defer exit.Recover()
defer logutil.Flush()

_flag.Parse()
_flag.Parse(pflag.NewFlagSet("zkctl", pflag.ExitOnError))
args := _flag.Args()

if len(args) == 0 {
Expand Down
4 changes: 3 additions & 1 deletion go/cmd/zkctld/zkctld.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"os/signal"
"syscall"

"github.com/spf13/pflag"

"vitess.io/vitess/go/exit"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/logutil"
Expand All @@ -45,7 +47,7 @@ func main() {
defer exit.Recover()
defer logutil.Flush()

_flag.Parse()
_flag.Parse(pflag.NewFlagSet("zkctld", pflag.ExitOnError))

zkConfig := zkctl.MakeZkConfigFromString(*zkCfg, uint32(*myID))
zkd := zkctl.NewZkd(zkConfig)
Expand Down
Loading