Add --keys flag to config list command to show only config keys

This commit is contained in:
Juan Carlos Mejías Rodríguez 2019-07-23 20:34:22 -04:00
parent 1ca444a79d
commit 3d475143c1
3 changed files with 12 additions and 2 deletions

View File

@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- `config` command to get and set configuration options.
- `config list|ls` command to list configuration options.
- `--keys` flag to show only config keys.
- `endpoint list|ls` command to print the endpoints list as a table.
- `--format` flag to format output using a Go template.
- `stack list|ls` command to print the stacks list as a table.

View File

@ -3,6 +3,7 @@ FROM alpine
ENV PSU_AUTHENTICATION_PASSWORD="" \
PSU_AUTHENTICATION_USER="" \
PSU_CONFIG="" \
PSU_CONFIG_LIST_KEYS="" \
PSU_CONNECTION_INSECURE="" \
PSU_CONNECTION_TIMEOUT="" \
PSU_CONNECTION_URL="" \

View File

@ -20,13 +20,21 @@ var configListCmd = &cobra.Command{
return keys[i] < keys[j]
})
// List keys and values
for _, key := range keys {
fmt.Printf("%s: %v\n", key, viper.Get(key))
if viper.GetBool("config.list.keys") {
// List config key
fmt.Println(key)
} else {
// List config key and value
fmt.Printf("%s: %v\n", key, viper.Get(key))
}
}
},
}
func init() {
configCmd.AddCommand(configListCmd)
configListCmd.Flags().Bool("keys", false, "list only keys")
viper.BindPFlag("config.list.keys", configListCmd.Flags().Lookup("keys"))
}