Get rid of the pflag dependency.
This commit is contained in:
parent
b7d2c1ab83
commit
7382dde1f6
1 changed files with 6 additions and 21 deletions
27
main.go
27
main.go
|
@ -15,31 +15,16 @@ const code = `
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
func init() {
|
||||
pflag.ErrHelp = nil
|
||||
versionFlagSet := pflag.NewFlagSet("version", pflag.ContinueOnError)
|
||||
versionFlagSet.ParseErrorsWhitelist.UnknownFlags = true
|
||||
versionFlagSet.SetOutput(nil)
|
||||
|
||||
versionIsAsked := versionFlagSet.BoolP("version", "v", false, "Prints version of this application.")
|
||||
versionFlagSet.BoolP("help", "h", false, "") // This line is needed to supress (redefine) built-in help flag.
|
||||
|
||||
err := versionFlagSet.Parse(os.Args)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if *versionIsAsked {
|
||||
fmt.Println(gitVersion)
|
||||
os.Exit(0)
|
||||
}
|
||||
for _, arg := range os.Args {
|
||||
if arg == "-v" || arg == "--version" {
|
||||
fmt.Println(gitVersion)
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
`
|
||||
|
||||
func main() {
|
||||
|
|
Loading…
Add table
Reference in a new issue