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