diff options
-rw-r--r-- | go.mod | 6 | ||||
-rw-r--r-- | go.sum | 2 | ||||
-rw-r--r-- | main.go | 24 |
3 files changed, 21 insertions, 11 deletions
@@ -1,5 +1,9 @@ module git.thomasvoss.com/gsp -go 1.21.0 +go 1.21.4 + +toolchain go1.22.2 require git.thomasvoss.com/getgopt v1.0.1 + +require git.sr.ht/~mango/opts/v2 v2.0.0 // indirect @@ -1,2 +1,4 @@ +git.sr.ht/~mango/opts/v2 v2.0.0 h1:Xgf9veVQTgdd7Sgp8hmEz61//XUbFeyfTu/9V98vuBE= +git.sr.ht/~mango/opts/v2 v2.0.0/go.mod h1:cWMagyMJYfu1Un3MXOlIsUJJNbJRFZkTx+2oGAp0gDk= git.thomasvoss.com/getgopt v1.0.1 h1:i2eyNe0K0MEEwsVpCFVVNKqV//WpEv54wWPyY6yKU7s= git.thomasvoss.com/getgopt v1.0.1/go.mod h1:xGRkf4eAWU0vXcnddTN5d6MB5dbca8+G1qM2PWSmZbg= @@ -4,7 +4,7 @@ import ( "fmt" "os" - "git.thomasvoss.com/getgopt" + "git.sr.ht/~mango/opts/v2" "git.thomasvoss.com/gsp/formatter" "git.thomasvoss.com/gsp/parser" ) @@ -12,23 +12,27 @@ import ( var dflag bool func main() { - for opt := byte(0); getgopt.Getopt(len(os.Args), os.Args, "d", &opt); { - switch opt { + flags, rest, err := opts.GetLong(os.Args, []opts.LongOpt{ + {Short: 'd', Long: "no-doctype", Arg: opts.None}, + }) + if err != nil { + fmt.Fprintf(os.Stderr, "%s: %s\n", os.Args[0], err) + fmt.Fprintf(os.Stderr, "Usage: %s [-d] [file ...]\n", os.Args[0]) + os.Exit(1) + } + + for _, f := range flags { + switch f.Key { case 'd': dflag = true - default: - fmt.Fprintf(os.Stderr, "Usage: %s [-d] [file ...]\n", os.Args[0]) - os.Exit(1) } } - args := os.Args[getgopt.Optind:] - - if len(args) == 0 { + if len(rest) == 0 { process("-") } - for _, a := range args { + for _, a := range rest { process(a) } } |