From 050d703a28912f22d4ef036f8c842b28aeb64349 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Mon, 29 Mar 2021 17:41:43 +0530 Subject: [PATCH 1/3] move --config to a global option --- commands/commands.go | 9 +-------- commands/delete-database.go | 3 +-- commands/import.go | 5 ++--- commands/reporting.go | 3 +-- commands/show-beacons-fqdn.go | 3 +-- commands/show-beacons.go | 3 +-- commands/show-bl-hostname.go | 3 +-- commands/show-bl-ip.go | 6 ++---- commands/show-databases.go | 5 +---- commands/show-explodedDns.go | 3 +-- commands/show-long-connections.go | 3 +-- commands/show-strobes.go | 3 +-- commands/show-user-agents.go | 3 +-- commands/update-check.go | 2 +- rita.go | 8 ++++++++ 15 files changed, 24 insertions(+), 38 deletions(-) diff --git a/commands/commands.go b/commands/commands.go index e3933645..d63a86b4 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -13,13 +13,6 @@ var ( // below are some prebuilt flags that get used often in various commands - // configFlag allows users to specify an alternate config file to use - configFlag = cli.StringFlag{ - Name: "config, c", - Usage: "Use a given `CONFIG_FILE` when running this command", - Value: "", - } - // forceFlag allows users to bypass prompts forceFlag = cli.BoolFlag{ Name: "force, f", @@ -130,7 +123,7 @@ func bootstrapCommands(commands ...cli.Command) { for _, command := range commands { command.Before = func(c *cli.Context) error { //Get access to the logger - configFile := c.String("config") + configFile := c.GlobalString("config") res := resources.InitResources(configFile) //Display args in logs fields := log.Fields{ diff --git a/commands/delete-database.go b/commands/delete-database.go index d88ea57d..2cabc6e8 100644 --- a/commands/delete-database.go +++ b/commands/delete-database.go @@ -21,7 +21,6 @@ func init() { ArgsUsage: "", Flags: []cli.Flag{ forceFlag, - configFlag, allFlag, matchFlag, regexFlag, @@ -35,7 +34,7 @@ func init() { //deleteDatabase deletes a target database func deleteDatabase(c *cli.Context) error { - res := resources.InitResources(c.String("config")) + res := resources.InitResources(c.GlobalString("config")) // Different command flags tgt := c.Args().Get(0) diff --git a/commands/import.go b/commands/import.go index 58e770b4..35b95fb7 100644 --- a/commands/import.go +++ b/commands/import.go @@ -23,7 +23,6 @@ func init() { " named .", Flags: []cli.Flag{ threadFlag, - configFlag, deleteFlag, rollingFlag, totalChunksFlag, @@ -32,7 +31,7 @@ func init() { Action: func(c *cli.Context) error { importer := NewImporter(c) err := importer.run() - fmt.Println(updateCheck(c.String("config"))) + fmt.Println(updateCheck(c.GlobalString("config"))) return err }, } @@ -59,7 +58,7 @@ type ( //NewImporter .... func NewImporter(c *cli.Context) *Importer { return &Importer{ - configFile: c.String("config"), + configFile: c.GlobalString("config"), args: c.Args(), deleteOldData: c.Bool("delete"), userRolling: c.Bool("rolling"), diff --git a/commands/reporting.go b/commands/reporting.go index 0a2f7b31..e1adadcc 100644 --- a/commands/reporting.go +++ b/commands/reporting.go @@ -14,11 +14,10 @@ func init() { UsageText: "rita html-report [command-options] [database]\n\n" + "If no database is specified, a report will be created for every database.", Flags: []cli.Flag{ - configFlag, netNamesFlag, }, Action: func(c *cli.Context) error { - res := resources.InitResources(c.String("config")) + res := resources.InitResources(c.GlobalString("config")) databaseName := c.Args().Get(0) var databases []string if databaseName != "" { diff --git a/commands/show-beacons-fqdn.go b/commands/show-beacons-fqdn.go index aa7abfc0..3188a637 100644 --- a/commands/show-beacons-fqdn.go +++ b/commands/show-beacons-fqdn.go @@ -18,7 +18,6 @@ func init() { ArgsUsage: "", Flags: []cli.Flag{ humanFlag, - configFlag, delimFlag, netNamesFlag, }, @@ -33,7 +32,7 @@ func showBeaconsFQDN(c *cli.Context) error { if db == "" { return cli.NewExitError("Specify a database", -1) } - res := resources.InitResources(c.String("config")) + res := resources.InitResources(c.GlobalString("config")) res.DB.SelectDB(db) data, err := beaconfqdn.Results(res, 0) diff --git a/commands/show-beacons.go b/commands/show-beacons.go index 4fcbd5ed..a814ec4d 100644 --- a/commands/show-beacons.go +++ b/commands/show-beacons.go @@ -18,7 +18,6 @@ func init() { ArgsUsage: "", Flags: []cli.Flag{ humanFlag, - configFlag, delimFlag, netNamesFlag, }, @@ -33,7 +32,7 @@ func showBeacons(c *cli.Context) error { if db == "" { return cli.NewExitError("Specify a database", -1) } - res := resources.InitResources(c.String("config")) + res := resources.InitResources(c.GlobalString("config")) res.DB.SelectDB(db) data, err := beacon.Results(res, 0) diff --git a/commands/show-bl-hostname.go b/commands/show-bl-hostname.go index 8dec7a72..7873f232 100644 --- a/commands/show-bl-hostname.go +++ b/commands/show-bl-hostname.go @@ -20,7 +20,6 @@ func init() { ArgsUsage: "", Flags: []cli.Flag{ humanFlag, - configFlag, limitFlag, noLimitFlag, delimFlag, @@ -40,7 +39,7 @@ func printBLHostnames(c *cli.Context) error { return cli.NewExitError("Specify a database", -1) } - res := resources.InitResources(c.String("config")) + res := resources.InitResources(c.GlobalString("config")) res.DB.SelectDB(db) data, err := blacklist.HostnameResults(res, "conn_count", c.Int("limit"), c.Bool("no-limit")) diff --git a/commands/show-bl-ip.go b/commands/show-bl-ip.go index f7c1e596..cd46bab3 100644 --- a/commands/show-bl-ip.go +++ b/commands/show-bl-ip.go @@ -21,7 +21,6 @@ func init() { humanFlag, blConnFlag, blSortFlag, - configFlag, limitFlag, noLimitFlag, delimFlag, @@ -38,7 +37,6 @@ func init() { humanFlag, blConnFlag, blSortFlag, - configFlag, limitFlag, noLimitFlag, delimFlag, @@ -71,7 +69,7 @@ func printBLSourceIPs(c *cli.Context) error { if err != nil { return err } - res := resources.InitResources(c.String("config")) + res := resources.InitResources(c.GlobalString("config")) res.DB.SelectDB(db) data, err := blacklist.SrcIPResults(res, sort, c.Int("limit"), c.Bool("no-limit")) @@ -105,7 +103,7 @@ func printBLDestIPs(c *cli.Context) error { return err } - res := resources.InitResources(c.String("config")) + res := resources.InitResources(c.GlobalString("config")) res.DB.SelectDB(db) data, err := blacklist.DstIPResults(res, sort, c.Int("limit"), c.Bool("no-limit")) diff --git a/commands/show-databases.go b/commands/show-databases.go index d0eb0db5..28b4a335 100644 --- a/commands/show-databases.go +++ b/commands/show-databases.go @@ -13,11 +13,8 @@ func init() { Name: "list", Aliases: []string{"show-databases"}, Usage: "Print the databases currently stored", - Flags: []cli.Flag{ - configFlag, - }, Action: func(c *cli.Context) error { - res := resources.InitResources(c.String("config")) + res := resources.InitResources(c.GlobalString("config")) if res != nil { for _, name := range res.MetaDB.GetDatabases() { diff --git a/commands/show-explodedDns.go b/commands/show-explodedDns.go index 9dc87089..97149f7d 100644 --- a/commands/show-explodedDns.go +++ b/commands/show-explodedDns.go @@ -20,7 +20,6 @@ func init() { ArgsUsage: "", Flags: []cli.Flag{ humanFlag, - configFlag, limitFlag, noLimitFlag, delimFlag, @@ -31,7 +30,7 @@ func init() { return cli.NewExitError("Specify a database", -1) } - res := resources.InitResources(c.String("config")) + res := resources.InitResources(c.GlobalString("config")) res.DB.SelectDB(db) data, err := explodeddns.Results(res, c.Int("limit"), c.Bool("no-limit")) diff --git a/commands/show-long-connections.go b/commands/show-long-connections.go index 32f4ed32..45e9132a 100644 --- a/commands/show-long-connections.go +++ b/commands/show-long-connections.go @@ -20,7 +20,6 @@ func init() { ArgsUsage: "", Flags: []cli.Flag{ humanFlag, - configFlag, limitFlag, noLimitFlag, delimFlag, @@ -32,7 +31,7 @@ func init() { return cli.NewExitError("Specify a database", -1) } - res := resources.InitResources(c.String("config")) + res := resources.InitResources(c.GlobalString("config")) res.DB.SelectDB(db) thresh := 60 // 1 minute diff --git a/commands/show-strobes.go b/commands/show-strobes.go index ae3c3c18..3f7ec83d 100644 --- a/commands/show-strobes.go +++ b/commands/show-strobes.go @@ -23,7 +23,6 @@ func init() { Name: "connection-count, l", Usage: "Sort the strobes by largest connection count.", }, - configFlag, limitFlag, noLimitFlag, delimFlag, @@ -35,7 +34,7 @@ func init() { return cli.NewExitError("Specify a database", -1) } - res := resources.InitResources(c.String("config")) + res := resources.InitResources(c.GlobalString("config")) res.DB.SelectDB(db) sortDirection := -1 diff --git a/commands/show-user-agents.go b/commands/show-user-agents.go index 80c6cda9..219c5f1c 100644 --- a/commands/show-user-agents.go +++ b/commands/show-user-agents.go @@ -23,7 +23,6 @@ func init() { Name: "least-used, l", Usage: "Sort the user agents from least used to most used.", }, - configFlag, limitFlag, noLimitFlag, delimFlag, @@ -34,7 +33,7 @@ func init() { return cli.NewExitError("Specify a database", -1) } - res := resources.InitResources(c.String("config")) + res := resources.InitResources(c.GlobalString("config")) res.DB.SelectDB(db) sortDirection := 1 diff --git a/commands/update-check.go b/commands/update-check.go index 5ead55cb..8cb51041 100644 --- a/commands/update-check.go +++ b/commands/update-check.go @@ -22,7 +22,7 @@ var versions = []string{"Major", "Minor", "Patch"} func GetVersionPrinter() func(*cli.Context) { return func(c *cli.Context) { fmt.Printf("%s version %s\n", c.App.Name, c.App.Version) - fmt.Println(updateCheck(c.String("config"))) + fmt.Println(updateCheck(c.GlobalString("config"))) } } diff --git a/rita.go b/rita.go index 081ea971..a045fd9e 100644 --- a/rita.go +++ b/rita.go @@ -15,6 +15,14 @@ func main() { app.Name = "rita" app.Usage = "Look for evil needles in big haystacks." + // configFlag allows users to specify an alternate config file to use + configFlag := cli.StringFlag{ + Name: "config, c", + Usage: "Use a given `CONFIG_FILE` when running this command", + Value: "", + } + app.Flags = []cli.Flag{configFlag} + cli.VersionPrinter = commands.GetVersionPrinter() // Change the version string with updates so that a quick help command will From 8416aceac4db6a0b42523a5ce48a4b42144c192f Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Sat, 3 Apr 2021 22:04:40 +0530 Subject: [PATCH 2/3] make --config flag available to both root command and subcommands Signed-off-by: Vivek Kumar --- commands/commands.go | 32 +++++++++++++++++++++++++++++-- commands/delete-database.go | 3 ++- commands/import.go | 5 +++-- commands/reporting.go | 3 ++- commands/show-beacons-fqdn.go | 3 ++- commands/show-beacons.go | 3 ++- commands/show-bl-hostname.go | 3 ++- commands/show-bl-ip.go | 6 ++++-- commands/show-databases.go | 5 ++++- commands/show-explodedDns.go | 3 ++- commands/show-long-connections.go | 3 ++- commands/show-strobes.go | 3 ++- commands/show-user-agents.go | 3 ++- commands/test-config.go | 13 ++++--------- commands/update-check.go | 2 +- rita.go | 10 ++-------- 16 files changed, 66 insertions(+), 34 deletions(-) diff --git a/commands/commands.go b/commands/commands.go index b453e093..2d08e3e6 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -13,6 +13,13 @@ var ( // below are some prebuilt flags that get used often in various commands + // configFlag allows users to specify an alternate config file to use + ConfigFlag = cli.StringFlag{ + Name: "config, c", + Usage: "Use a given `CONFIG_FILE` when running this command", + Value: "", + } + // forceFlag allows users to bypass prompts forceFlag = cli.BoolFlag{ Name: "force, f", @@ -123,13 +130,34 @@ var ( } ) +// SetConfigFilePath reads config file path from cli context and stores it in app metadata +// to make it available to all subcommands. The root command and all subcommands use this. +// If --config flag is supplied for both root command and a subcommand, the value of the +// subcommand is used. +func SetConfigFilePath(c *cli.Context) error { + if configFilePath := c.String("config"); configFilePath != "" { + c.App.Metadata["config"] = configFilePath + } + return nil +} + +// getConfigFilePath returns config file path from app metadata +func getConfigFilePath(c *cli.Context) string { + switch cfg := c.App.Metadata["config"].(type) { + case string: + return cfg + default: + return "" + } +} + // bootstrapCommands simply adds a given command to the allCommands array func bootstrapCommands(commands ...cli.Command) { for _, command := range commands { command.Before = func(c *cli.Context) error { //Get access to the logger - configFile := c.GlobalString("config") - res := resources.InitResources(configFile) + SetConfigFilePath(c) + res := resources.InitResources(getConfigFilePath(c)) //Display args in logs fields := log.Fields{ "Arguments": c.Args(), diff --git a/commands/delete-database.go b/commands/delete-database.go index 2cabc6e8..912e28f5 100644 --- a/commands/delete-database.go +++ b/commands/delete-database.go @@ -20,6 +20,7 @@ func init() { Usage: "Delete imported database(s)", ArgsUsage: "", Flags: []cli.Flag{ + ConfigFlag, forceFlag, allFlag, matchFlag, @@ -34,7 +35,7 @@ func init() { //deleteDatabase deletes a target database func deleteDatabase(c *cli.Context) error { - res := resources.InitResources(c.GlobalString("config")) + res := resources.InitResources(getConfigFilePath(c)) // Different command flags tgt := c.Args().Get(0) diff --git a/commands/import.go b/commands/import.go index 35b95fb7..3343ab95 100644 --- a/commands/import.go +++ b/commands/import.go @@ -22,6 +22,7 @@ func init() { "Logs directly in will be imported into a database" + " named .", Flags: []cli.Flag{ + ConfigFlag, threadFlag, deleteFlag, rollingFlag, @@ -31,7 +32,7 @@ func init() { Action: func(c *cli.Context) error { importer := NewImporter(c) err := importer.run() - fmt.Println(updateCheck(c.GlobalString("config"))) + fmt.Println(updateCheck(getConfigFilePath(c))) return err }, } @@ -58,7 +59,7 @@ type ( //NewImporter .... func NewImporter(c *cli.Context) *Importer { return &Importer{ - configFile: c.GlobalString("config"), + configFile: getConfigFilePath(c), args: c.Args(), deleteOldData: c.Bool("delete"), userRolling: c.Bool("rolling"), diff --git a/commands/reporting.go b/commands/reporting.go index ddcd0a32..05385061 100644 --- a/commands/reporting.go +++ b/commands/reporting.go @@ -14,11 +14,12 @@ func init() { UsageText: "rita html-report [command-options] [database]\n\n" + "If no database is specified, a report will be created for every database.", Flags: []cli.Flag{ + ConfigFlag, netNamesFlag, noBrowserFlag, }, Action: func(c *cli.Context) error { - res := resources.InitResources(c.GlobalString("config")) + res := resources.InitResources(getConfigFilePath(c)) databaseName := c.Args().Get(0) var databases []string if databaseName != "" { diff --git a/commands/show-beacons-fqdn.go b/commands/show-beacons-fqdn.go index 3188a637..64c17416 100644 --- a/commands/show-beacons-fqdn.go +++ b/commands/show-beacons-fqdn.go @@ -17,6 +17,7 @@ func init() { Usage: "Print hosts which show signs of C2 software (FQDN Analysis)", ArgsUsage: "", Flags: []cli.Flag{ + ConfigFlag, humanFlag, delimFlag, netNamesFlag, @@ -32,7 +33,7 @@ func showBeaconsFQDN(c *cli.Context) error { if db == "" { return cli.NewExitError("Specify a database", -1) } - res := resources.InitResources(c.GlobalString("config")) + res := resources.InitResources(getConfigFilePath(c)) res.DB.SelectDB(db) data, err := beaconfqdn.Results(res, 0) diff --git a/commands/show-beacons.go b/commands/show-beacons.go index 0f204056..7741484f 100644 --- a/commands/show-beacons.go +++ b/commands/show-beacons.go @@ -17,6 +17,7 @@ func init() { Usage: "Print hosts which show signs of C2 software", ArgsUsage: "", Flags: []cli.Flag{ + ConfigFlag, humanFlag, delimFlag, netNamesFlag, @@ -32,7 +33,7 @@ func showBeacons(c *cli.Context) error { if db == "" { return cli.NewExitError("Specify a database", -1) } - res := resources.InitResources(c.GlobalString("config")) + res := resources.InitResources(getConfigFilePath(c)) res.DB.SelectDB(db) data, err := beacon.Results(res, 0) diff --git a/commands/show-bl-hostname.go b/commands/show-bl-hostname.go index 7873f232..a9d5e60a 100644 --- a/commands/show-bl-hostname.go +++ b/commands/show-bl-hostname.go @@ -19,6 +19,7 @@ func init() { Name: "show-bl-hostnames", ArgsUsage: "", Flags: []cli.Flag{ + ConfigFlag, humanFlag, limitFlag, noLimitFlag, @@ -39,7 +40,7 @@ func printBLHostnames(c *cli.Context) error { return cli.NewExitError("Specify a database", -1) } - res := resources.InitResources(c.GlobalString("config")) + res := resources.InitResources(getConfigFilePath(c)) res.DB.SelectDB(db) data, err := blacklist.HostnameResults(res, "conn_count", c.Int("limit"), c.Bool("no-limit")) diff --git a/commands/show-bl-ip.go b/commands/show-bl-ip.go index cd46bab3..ca453610 100644 --- a/commands/show-bl-ip.go +++ b/commands/show-bl-ip.go @@ -18,6 +18,7 @@ func init() { Name: "show-bl-source-ips", ArgsUsage: "", Flags: []cli.Flag{ + ConfigFlag, humanFlag, blConnFlag, blSortFlag, @@ -34,6 +35,7 @@ func init() { Name: "show-bl-dest-ips", ArgsUsage: "", Flags: []cli.Flag{ + ConfigFlag, humanFlag, blConnFlag, blSortFlag, @@ -69,7 +71,7 @@ func printBLSourceIPs(c *cli.Context) error { if err != nil { return err } - res := resources.InitResources(c.GlobalString("config")) + res := resources.InitResources(getConfigFilePath(c)) res.DB.SelectDB(db) data, err := blacklist.SrcIPResults(res, sort, c.Int("limit"), c.Bool("no-limit")) @@ -103,7 +105,7 @@ func printBLDestIPs(c *cli.Context) error { return err } - res := resources.InitResources(c.GlobalString("config")) + res := resources.InitResources(getConfigFilePath(c)) res.DB.SelectDB(db) data, err := blacklist.DstIPResults(res, sort, c.Int("limit"), c.Bool("no-limit")) diff --git a/commands/show-databases.go b/commands/show-databases.go index 28b4a335..1732662c 100644 --- a/commands/show-databases.go +++ b/commands/show-databases.go @@ -13,8 +13,11 @@ func init() { Name: "list", Aliases: []string{"show-databases"}, Usage: "Print the databases currently stored", + Flags: []cli.Flag{ + ConfigFlag, + }, Action: func(c *cli.Context) error { - res := resources.InitResources(c.GlobalString("config")) + res := resources.InitResources(getConfigFilePath(c)) if res != nil { for _, name := range res.MetaDB.GetDatabases() { diff --git a/commands/show-explodedDns.go b/commands/show-explodedDns.go index 97149f7d..a9b6e063 100644 --- a/commands/show-explodedDns.go +++ b/commands/show-explodedDns.go @@ -19,6 +19,7 @@ func init() { Usage: "Print dns analysis. Exposes covert dns channels", ArgsUsage: "", Flags: []cli.Flag{ + ConfigFlag, humanFlag, limitFlag, noLimitFlag, @@ -30,7 +31,7 @@ func init() { return cli.NewExitError("Specify a database", -1) } - res := resources.InitResources(c.GlobalString("config")) + res := resources.InitResources(getConfigFilePath(c)) res.DB.SelectDB(db) data, err := explodeddns.Results(res, c.Int("limit"), c.Bool("no-limit")) diff --git a/commands/show-long-connections.go b/commands/show-long-connections.go index 45e9132a..3954913f 100644 --- a/commands/show-long-connections.go +++ b/commands/show-long-connections.go @@ -19,6 +19,7 @@ func init() { Usage: "Print long connections and relevant information", ArgsUsage: "", Flags: []cli.Flag{ + ConfigFlag, humanFlag, limitFlag, noLimitFlag, @@ -31,7 +32,7 @@ func init() { return cli.NewExitError("Specify a database", -1) } - res := resources.InitResources(c.GlobalString("config")) + res := resources.InitResources(getConfigFilePath(c)) res.DB.SelectDB(db) thresh := 60 // 1 minute diff --git a/commands/show-strobes.go b/commands/show-strobes.go index 3f7ec83d..732f558a 100644 --- a/commands/show-strobes.go +++ b/commands/show-strobes.go @@ -18,6 +18,7 @@ func init() { Usage: "Print strobe information", ArgsUsage: "", Flags: []cli.Flag{ + ConfigFlag, humanFlag, cli.BoolFlag{ Name: "connection-count, l", @@ -34,7 +35,7 @@ func init() { return cli.NewExitError("Specify a database", -1) } - res := resources.InitResources(c.GlobalString("config")) + res := resources.InitResources(getConfigFilePath(c)) res.DB.SelectDB(db) sortDirection := -1 diff --git a/commands/show-user-agents.go b/commands/show-user-agents.go index 219c5f1c..b55ea7e1 100644 --- a/commands/show-user-agents.go +++ b/commands/show-user-agents.go @@ -18,6 +18,7 @@ func init() { Usage: "Print user agent information", ArgsUsage: "", Flags: []cli.Flag{ + ConfigFlag, humanFlag, cli.BoolFlag{ Name: "least-used, l", @@ -33,7 +34,7 @@ func init() { return cli.NewExitError("Specify a database", -1) } - res := resources.InitResources(c.GlobalString("config")) + res := resources.InitResources(getConfigFilePath(c)) res.DB.SelectDB(db) sortDirection := 1 diff --git a/commands/test-config.go b/commands/test-config.go index 86de3f7e..904ee43e 100644 --- a/commands/test-config.go +++ b/commands/test-config.go @@ -13,15 +13,10 @@ import ( func init() { command := cli.Command{ - Flags: []cli.Flag{ - cli.StringFlag{ - Name: "config, c", - Usage: "specify a config file to be used", - Value: "", - }, - }, + Flags: []cli.Flag{ConfigFlag}, Name: "test-config", Usage: "Check the configuration file for validity", + Before: SetConfigFilePath, Action: testConfiguration, } @@ -31,7 +26,7 @@ func init() { // testConfiguration prints out the result of parsing the config file func testConfiguration(c *cli.Context) error { // First, print out the config as it was parsed - conf, err := config.LoadConfig(c.String("config")) + conf, err := config.LoadConfig(getConfigFilePath(c)) if err != nil { fmt.Fprintf(os.Stdout, "Failed to config: %s\n", err.Error()) os.Exit(-1) @@ -51,7 +46,7 @@ func testConfiguration(c *cli.Context) error { fmt.Fprintf(os.Stdout, "\n%s\n", string(tableConfig)) // Then test initializing external resources like db connection and file handles - resources.InitResources(c.String("config")) + resources.InitResources(getConfigFilePath(c)) return nil } diff --git a/commands/update-check.go b/commands/update-check.go index 8cb51041..005aac37 100644 --- a/commands/update-check.go +++ b/commands/update-check.go @@ -22,7 +22,7 @@ var versions = []string{"Major", "Minor", "Patch"} func GetVersionPrinter() func(*cli.Context) { return func(c *cli.Context) { fmt.Printf("%s version %s\n", c.App.Name, c.App.Version) - fmt.Println(updateCheck(c.GlobalString("config"))) + fmt.Println(updateCheck(getConfigFilePath(c))) } } diff --git a/rita.go b/rita.go index a045fd9e..8072d995 100644 --- a/rita.go +++ b/rita.go @@ -14,14 +14,7 @@ func main() { app := cli.NewApp() app.Name = "rita" app.Usage = "Look for evil needles in big haystacks." - - // configFlag allows users to specify an alternate config file to use - configFlag := cli.StringFlag{ - Name: "config, c", - Usage: "Use a given `CONFIG_FILE` when running this command", - Value: "", - } - app.Flags = []cli.Flag{configFlag} + app.Flags = []cli.Flag{commands.ConfigFlag} cli.VersionPrinter = commands.GetVersionPrinter() @@ -32,6 +25,7 @@ func main() { // Define commands used with this application app.Commands = commands.Commands() + app.Before = commands.SetConfigFilePath runtime.GOMAXPROCS(runtime.NumCPU()) app.Run(os.Args) From a4b2a3aab98a75f7afc4b6c7c8db9b08ea9b03a0 Mon Sep 17 00:00:00 2001 From: Vivek Kumar Date: Sat, 3 Apr 2021 22:10:36 +0530 Subject: [PATCH 3/3] fix silly linter issue Signed-off-by: Vivek Kumar --- commands/commands.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/commands.go b/commands/commands.go index 2d08e3e6..45be1e46 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -13,7 +13,7 @@ var ( // below are some prebuilt flags that get used often in various commands - // configFlag allows users to specify an alternate config file to use + // ConfigFlag allows users to specify an alternate config file to use ConfigFlag = cli.StringFlag{ Name: "config, c", Usage: "Use a given `CONFIG_FILE` when running this command",