-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
73 lines (65 loc) · 1.21 KB
/
main.go
File metadata and controls
73 lines (65 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"context"
"os"
"strings"
"github.com/charmbracelet/fang"
"github.com/o6uoq/fuzmit/internal/fuzmit"
)
var version = "dev"
func main() {
args := os.Args[1:]
args = normalizeArgs(args)
helpMode := helpRequested(args)
cmd := fuzmit.NewRootCommand()
cmd.SetArgs(args)
if err := fang.Execute(
context.Background(),
cmd,
fang.WithVersion(version),
); err != nil {
os.Exit(1)
}
if helpMode {
fuzmit.PrintHelpNotes(os.Stdout)
}
}
func helpRequested(args []string) bool {
if len(args) > 0 && args[0] == "help" {
return true
}
for _, arg := range args {
if arg == "--" {
break
}
if arg == "-h" || arg == "--help" || strings.HasPrefix(arg, "--help=") {
return true
}
}
return false
}
func normalizeArgs(args []string) []string {
if len(args) == 0 {
return args
}
out := make([]string, 0, len(args))
for i := 0; i < len(args); i++ {
arg := args[i]
if arg == "--" {
out = append(out, args[i:]...)
break
}
if arg == "--scope" || arg == "-s" {
if i+1 < len(args) {
next := args[i+1]
if next != "--" && !strings.HasPrefix(next, "-") {
out = append(out, arg+"="+next)
i++
continue
}
}
}
out = append(out, arg)
}
return out
}