aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-04-18 10:44:58 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-04-18 10:44:58 +0200
commit679f7a8c5e98b2312876d3a36a82dae2480aa386 (patch)
treedbab43b2ab79996987b0afc9a9c71062d26fc976 /main.go
parent1f83fa89d8585b1fa59df7a400157f8df93ff681 (diff)
Switch to opts for option parsing
Diffstat (limited to 'main.go')
-rw-r--r--main.go24
1 files changed, 14 insertions, 10 deletions
diff --git a/main.go b/main.go
index 96dd479..e84538c 100644
--- a/main.go
+++ b/main.go
@@ -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)
}
}