Get rid of the pflag dependency.

This commit is contained in:
Foil-hat-guy 2025-04-20 02:43:47 +03:00
parent b7d2c1ab83
commit 7382dde1f6
No known key found for this signature in database
GPG key ID: 221CC305A7B23591

27
main.go
View file

@ -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() {