forked from activecm/rita
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrita.go
82 lines (68 loc) · 1.98 KB
/
rita.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"fmt"
"log"
"os"
"github.com/activecm/rita/v5/cmd"
"github.com/activecm/rita/v5/config"
zlog "github.com/activecm/rita/v5/logger"
"github.com/activecm/rita/v5/viewer"
"github.com/joho/godotenv"
"github.com/urfave/cli/v2"
)
// Version is populated by build flags with the current Git tag
var Version string
func main() {
// set the version in config to make it more importable by other packages
config.Version = Version
// UNIX Time is faster and smaller than most timestamps
// zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
app := &cli.App{
EnableBashCompletion: true,
Commands: cmd.Commands(),
Name: "RITA",
Usage: "Look for evil needles in big haystacks",
UsageText: "rita [-d] command [command options]",
Version: Version,
Args: true,
ExitErrHandler: exitErrHandler,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "debug",
Aliases: []string{"d"},
Usage: "Run in debug mode",
Value: false, // default config file path
Required: false,
},
},
Before: func(cCtx *cli.Context) error {
// set logger mode based on APP_ENV
zlog.DebugMode = os.Getenv("APP_ENV") == "dev"
// override APP_ENV if the --debug flag is set
// *note that global flags must be placed before the subcommand when running in the CLI
if cCtx.Bool("debug") {
zlog.DebugMode = true
viewer.DebugMode = true
}
// load environment variables from .env files
// base .env file is required
err := godotenv.Load("./.env")
if err != nil {
log.Fatal("Error loading .env file", err)
}
return nil
},
}
if err := app.Run(os.Args); err != nil {
logger := zlog.GetLogger()
logger.Fatal().Err(err).Send()
}
}
// exitErrHandler implements cli.ExitErrHandlerFunc
func exitErrHandler(c *cli.Context, err error) {
if err == nil {
return
}
fmt.Fprintf(c.App.ErrWriter, "\n\n\t[!] %+v\n\n", err.Error())
cli.OsExiter(1)
}