|
26 | 26 | )
|
27 | 27 |
|
28 | 28 | var rootCmd = &cobra.Command{
|
29 |
| - Use: "ssl-checker [flags] [file-targets <files>|domain-targets <domains>]", |
| 29 | + Use: "ssl-checker [flags] [files <files>|domains <domains>]", |
30 | 30 | Short: "ssl-checker",
|
31 | 31 | Long: "ssl-checker is a tool to _quickly_ check certificate details of multiple https targets.",
|
32 | 32 |
|
@@ -91,6 +91,28 @@ var rootCmd = &cobra.Command{
|
91 | 91 | },
|
92 | 92 | }
|
93 | 93 |
|
| 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 | + |
94 | 116 | func runQueries(fileTargets map[string]string, domainTargets map[string][]string) {
|
95 | 117 | if viper.GetBool("silent") {
|
96 | 118 | fmt.Fprintln(os.Stderr, "Processing query!")
|
@@ -126,6 +148,8 @@ func init() {
|
126 | 148 | viper.BindPFlag("silent", rootCmd.PersistentFlags().Lookup("silent"))
|
127 | 149 | viper.BindPFlag("debug", rootCmd.PersistentFlags().Lookup("debug"))
|
128 | 150 | viper.BindPFlag("timeout", rootCmd.PersistentFlags().Lookup("timeout"))
|
| 151 | + |
| 152 | + rootCmd.AddCommand(listEnvs) |
129 | 153 | }
|
130 | 154 |
|
131 | 155 | func Execute() {
|
|
0 commit comments