-
Notifications
You must be signed in to change notification settings - Fork 339
/
root.go
64 lines (52 loc) · 1.33 KB
/
root.go
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
package cmd
import (
"fmt"
"os"
"github.com/sensepost/gowitness/internal/ascii"
"github.com/sensepost/gowitness/pkg/log"
"github.com/sensepost/gowitness/pkg/runner"
"github.com/spf13/cobra"
)
var (
opts = &runner.Options{}
)
var rootCmd = &cobra.Command{
Use: "gowitness",
Short: "A web screenshot and information gathering tool",
Long: ascii.Logo(),
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if opts.Logging.Silence {
log.EnableSilence()
}
if opts.Logging.Debug && !opts.Logging.Silence {
log.EnableDebug()
log.Debug("debug logging enabled")
}
return nil
},
}
func Execute() {
rootCmd.CompletionOptions.DisableDefaultCmd = true
rootCmd.SilenceErrors = true
err := rootCmd.Execute()
if err != nil {
var cmd string
c, _, cerr := rootCmd.Find(os.Args[1:])
if cerr == nil {
cmd = c.Name()
}
v := "\n"
if cmd != "" {
v += fmt.Sprintf("An error occured running the `%s` command\n", cmd)
} else {
v += "An error has occured. "
}
v += "The error was:\n\n" + fmt.Sprintf("```%s```", err)
fmt.Println(ascii.Markdown(v))
os.Exit(1)
}
}
func init() {
rootCmd.PersistentFlags().BoolVarP(&opts.Logging.Debug, "debug-log", "D", false, "Enable debug logging")
rootCmd.PersistentFlags().BoolVarP(&opts.Logging.Silence, "quiet", "q", false, "Silence (almost all) logging")
}