psu/cmd/configList.go

42 lines
861 B
Go
Raw Normal View History

package cmd
import (
"fmt"
"sort"
2019-08-06 22:51:56 +00:00
"github.com/spf13/viper"
"github.com/spf13/cobra"
)
// configListCmd represents the list command
var configListCmd = &cobra.Command{
2019-07-24 22:23:44 +00:00
Use: "list",
Short: "List configs",
Aliases: []string{"ls"},
Run: func(cmd *cobra.Command, args []string) {
// Get alphabetically ordered list of config keys
keys := viper.AllKeys()
sort.Slice(keys, func(i, j int) bool {
return keys[i] < keys[j]
})
for _, key := range keys {
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)
2019-08-06 22:51:56 +00:00
configListCmd.Flags().Bool("keys", false, "Only list keys.")
viper.BindPFlag("config.list.keys", configListCmd.Flags().Lookup("keys"))
}