Skip to content

Commit 5a9f0b1

Browse files
committed
New command to list available environments in config file
1 parent 0eab80c commit 5a9f0b1

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

cmd/root.go

+25-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var (
2626
)
2727

2828
var rootCmd = &cobra.Command{
29-
Use: "ssl-checker [flags] [file-targets <files>|domain-targets <domains>]",
29+
Use: "ssl-checker [flags] [files <files>|domains <domains>]",
3030
Short: "ssl-checker",
3131
Long: "ssl-checker is a tool to _quickly_ check certificate details of multiple https targets.",
3232

@@ -91,6 +91,28 @@ var rootCmd = &cobra.Command{
9191
},
9292
}
9393

94+
var listEnvs = &cobra.Command{
95+
Use: "environments",
96+
Short: "List environments set in configuration file",
97+
Run: func(cmd *cobra.Command, args []string) {
98+
if viper.IsSet("queries") {
99+
queries := viper.Get("queries")
100+
envs := make([]string, len(queries.(map[string]interface{})))
101+
102+
i := 0
103+
for env := range queries.(map[string]interface{}) {
104+
envs[i] = env
105+
i++
106+
}
107+
fmt.Printf("Available environments: %s.\n", strings.Join(envs, ", "))
108+
} else {
109+
// Nothing to do
110+
log.Debug().Msgf("Empty query... nothing to do")
111+
os.Exit(1)
112+
}
113+
},
114+
}
115+
94116
func runQueries(fileTargets map[string]string, domainTargets map[string][]string) {
95117
if viper.GetBool("silent") {
96118
fmt.Fprintln(os.Stderr, "Processing query!")
@@ -126,6 +148,8 @@ func init() {
126148
viper.BindPFlag("silent", rootCmd.PersistentFlags().Lookup("silent"))
127149
viper.BindPFlag("debug", rootCmd.PersistentFlags().Lookup("debug"))
128150
viper.BindPFlag("timeout", rootCmd.PersistentFlags().Lookup("timeout"))
151+
152+
rootCmd.AddCommand(listEnvs)
129153
}
130154

131155
func Execute() {

cmd/targets.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ var fileTargetsCmd = &cobra.Command{
2121
},
2222
}
2323

24-
func init() {
25-
rootCmd.AddCommand(fileTargetsCmd)
26-
}
27-
2824
var domainTargetsCmd = &cobra.Command{
2925
Use: "domains [flags] domain1[,domain2,domain3...]",
3026
Short: "Run test against provided list of domains",
@@ -40,5 +36,6 @@ var domainTargetsCmd = &cobra.Command{
4036
}
4137

4238
func init() {
39+
rootCmd.AddCommand(fileTargetsCmd)
4340
rootCmd.AddCommand(domainTargetsCmd)
4441
}

0 commit comments

Comments
 (0)