From 43724e6e614fa757c6881cd754439fa187aa9b5a Mon Sep 17 00:00:00 2001 From: Kcermak Date: Fri, 31 Jan 2025 20:55:37 +0100 Subject: [PATCH] Add view key command --- cli/cmd/keys.go | 90 +++++++++++++++++++++++++++++++++---------------- cli/main.go | 7 ++-- 2 files changed, 64 insertions(+), 33 deletions(-) diff --git a/cli/cmd/keys.go b/cli/cmd/keys.go index 8e7f7db..52fd685 100644 --- a/cli/cmd/keys.go +++ b/cli/cmd/keys.go @@ -7,41 +7,73 @@ import ( ) -func ViewAllKeys() { +func ViewKeys(key string) { if !db.DatabaseExist() { helpers.PrintError(true, "Database does not exist, run first") } - fmt.Println("\033[1m*probe_name\033[0m") - fmt.Println(" -> " + db.GetValue("probe_name")) - fmt.Println(" \033[3mProbe name is used to identify the probe in the API requests.\033[0m") + found := false - fmt.Println("\033[1mdb_version\033[0m") - fmt.Println(" -> " + db.GetValue("db_version")) - fmt.Println(" \033[3mDatabase version.\033[0m") - - fmt.Println("\033[1mdb_init_time\033[0m") - fmt.Println(" -> " + db.GetValue("db_init_time")) - fmt.Println(" \033[3mDatabase initialization time.\033[0m") - - fmt.Println("\033[1mconfig_set\033[0m") - fmt.Println(" -> " + db.GetValue("config_set")) - fmt.Println(" \033[3mConfig set status, if set to true, you already set the config file.\033[0m") - - //delete_after - fmt.Println("\033[1m*delete_after\033[0m") - fmt.Println(" -> " + db.GetValue("delete_after")) - fmt.Println(" \033[3mDelete after is used to set the time to delete the scan history data after. Updating this value will not affect the existing data.\033[0m") - - fmt.Println("\033[1m*api_port\033[0m") - fmt.Println(" -> " + db.GetValue("api_port")) - fmt.Println(" \033[3mAPI port is used to set the port for the API server.\033[0m") - - fmt.Println("\033[1m*editor_endpoint\033[0m") - fmt.Println(" -> " + db.GetValue("editor_endpoint")) - fmt.Println(" \033[3mEditor endpoint is used to enable/disable the /editor endpoint.\033[0m") + if key == "all" || key == "probe_name" { + found = true + fmt.Println("\033[1m*probe_name\033[0m") + fmt.Println(" -> " + db.GetValue("probe_name")) + fmt.Println(" \033[3mProbe name is used to identify the probe in the API requests.\033[0m") + } - fmt.Println("\n(values with * can be changed using > command)") + if key == "all" || key == "probe_name" { + found = true + fmt.Println("\033[1m*probe_name\033[0m") + fmt.Println(" -> " + db.GetValue("probe_name")) + fmt.Println(" \033[3mProbe name is used to identify the probe in the API requests.\033[0m") + } + + if key == "all" || key == "db_version" { + found = true + fmt.Println("\033[1mdb_version\033[0m") + fmt.Println(" -> " + db.GetValue("db_version")) + fmt.Println(" \033[3mDatabase version.\033[0m") + } + + if key == "all" || key == "db_init_time" { + found = true + fmt.Println("\033[1mdb_init_time\033[0m") + fmt.Println(" -> " + db.GetValue("db_init_time")) + fmt.Println(" \033[3mDatabase initialization time.\033[0m") + } + + if key == "all" || key == "config_set" { + found = true + fmt.Println("\033[1mconfig_set\033[0m") + fmt.Println(" -> " + db.GetValue("config_set")) + fmt.Println(" \033[3mConfig set status, if set to true, you already set the config file.\033[0m") + } + + if key == "all" || key == "delete_after" { + found = true + fmt.Println("\033[1m*delete_after\033[0m") + fmt.Println(" -> " + db.GetValue("delete_after")) + fmt.Println(" \033[3mDelete after is used to set the time to delete the scan history data after. Updating this value will not affect the existing data.\033[0m") + } + + if key == "all" || key == "api_port" { + found = true + fmt.Println("\033[1m*api_port\033[0m") + fmt.Println(" -> " + db.GetValue("api_port")) + fmt.Println(" \033[3mAPI port is used to set the port for the API server.\033[0m") + } + + if key == "all" || key == "editor_endpoint" { + found = true + fmt.Println("\033[1m*editor_endpoint\033[0m") + fmt.Println(" -> " + db.GetValue("editor_endpoint")) + fmt.Println(" \033[3mEditor endpoint is used to enable/disable the /editor endpoint.\033[0m") + } + if found { + fmt.Println("\n\033[3m(values with\033[0m \033[1m*\033[0m \033[3mcan be changed using > command)\033[0m") + } else { + helpers.PrintError(true, "Key " + key + " not found") + } } \ No newline at end of file diff --git a/cli/main.go b/cli/main.go index 03218ed..0abc234 100644 --- a/cli/main.go +++ b/cli/main.go @@ -34,13 +34,12 @@ func main() { return } - //keys view all - if (helpers.ArgsMatch(args, []string{"*", "keys", "view", "all"})) { - cmd.ViewAllKeys() + //keys view all / keys view + if (helpers.ArgsMatch(args, []string{"*", "keys", "view", "*"})) { + cmd.ViewKeys(args[3]) return } - //keys view //keys set