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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
pflag.ErrHelp = nil
|
for _, arg := range os.Args {
|
||||||
versionFlagSet := pflag.NewFlagSet("version", pflag.ContinueOnError)
|
if arg == "-v" || arg == "--version" {
|
||||||
versionFlagSet.ParseErrorsWhitelist.UnknownFlags = true
|
fmt.Println(gitVersion)
|
||||||
versionFlagSet.SetOutput(nil)
|
os.Exit(0)
|
||||||
|
}
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue