Skip to content

Commit

Permalink
set --help exit code to zero (pingcap#197)
Browse files Browse the repository at this point in the history
* set --help exit code to zero

* address comment
  • Loading branch information
lichunzhu authored Nov 10, 2020
1 parent f13e421 commit f269d59
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cmd/dumpling/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package main

import (
"context"
"errors"
"fmt"
_ "net/http/pprof"
"os"
Expand All @@ -33,14 +32,19 @@ func main() {
fmt.Fprint(os.Stderr, "Dumpling is a CLI tool that helps you dump MySQL/TiDB data\n\nUsage:\n dumpling [flags]\n\nFlags:\n")
pflag.PrintDefaults()
}
pflag.ErrHelp = errors.New("")

printVersion := pflag.BoolP("version", "V", false, "Print Dumpling version")

conf := export.DefaultConfig()
conf.DefineFlags(pflag.CommandLine)

pflag.Parse()
if printHelp, err := pflag.CommandLine.GetBool(export.FlagHelp); printHelp || err != nil {
if err != nil {
fmt.Printf("\nGet help flag error: %s\n", err)
}
pflag.Usage()
return
}
println(cli.LongVersion())
if *printVersion {
return
Expand Down
2 changes: 2 additions & 0 deletions v4/export/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const (
flagOutputFilenameTemplate = "output-filename-template"
flagCompleteInsert = "complete-insert"
flagParams = "params"
FlagHelp = "help"
)

type Config struct {
Expand Down Expand Up @@ -220,6 +221,7 @@ func (conf *Config) DefineFlags(flags *pflag.FlagSet) {
flags.String(flagOutputFilenameTemplate, "", "The output filename template (without file extension)")
flags.Bool(flagCompleteInsert, false, "Use complete INSERT statements that include column names")
flags.StringToString(flagParams, nil, `Extra session variables used while dumping, accepted format: --params "character_set_client=latin1,character_set_connection=latin1"`)
flags.Bool(FlagHelp, false, "Print help message and quit")
}

// GetDSN generates DSN from Config
Expand Down

0 comments on commit f269d59

Please sign in to comment.