mirror of
https://gitlab.com/psuapp/psu.git
synced 2024-08-30 18:12:34 +00:00
Add --list flag to config command to list all available configuration keys
This commit is contained in:
@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
## [Unreleased]
|
||||
### Added
|
||||
- `config` command to get and set configuration options.
|
||||
- `-l, --list` flag to list all available configuration 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.
|
||||
|
@ -3,6 +3,7 @@ FROM alpine
|
||||
ENV PSU_AUTHENTICATION_PASSWORD="" \
|
||||
PSU_AUTHENTICATION_USER="" \
|
||||
PSU_CONFIG="" \
|
||||
PSU_CONFIG_LIST="" \
|
||||
PSU_CONNECTION_INSECURE="" \
|
||||
PSU_CONNECTION_TIMEOUT="" \
|
||||
PSU_CONNECTION_URL="" \
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
"log"
|
||||
"os"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// configCmd represents the config command
|
||||
@ -15,8 +16,18 @@ var configCmd = &cobra.Command{
|
||||
Use: "config KEY [VALUE]",
|
||||
Short: "Get and set configuration options",
|
||||
Example: "psu config user admin",
|
||||
Args: cobra.RangeArgs(1, 2),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if viper.GetBool("config.list") {
|
||||
// List config keys
|
||||
keys := viper.AllKeys()
|
||||
sort.Slice(keys, func(i, j int) bool {
|
||||
return keys[i] < keys[j]
|
||||
})
|
||||
for _, key := range keys {
|
||||
fmt.Println(key)
|
||||
}
|
||||
} else {
|
||||
if len(args) >= 1 {
|
||||
// Check if it's a valid key
|
||||
var keyExists bool
|
||||
for _, key := range viper.AllKeys() {
|
||||
@ -74,9 +85,14 @@ var configCmd = &cobra.Command{
|
||||
common.CheckError(configWritingErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(configCmd)
|
||||
|
||||
configCmd.Flags().BoolP("list", "l", false, "list all config keys")
|
||||
viper.BindPFlag("config.list", configCmd.Flags().Lookup("list"))
|
||||
}
|
||||
|
Reference in New Issue
Block a user