mirror of
https://gitlab.com/psuapp/psu.git
synced 2024-08-30 18:12:34 +00:00
Add config list --format documentation
This commit is contained in:
parent
579025f8de
commit
79acf44225
@ -19,6 +19,20 @@ var configListCmd = &cobra.Command{
|
|||||||
Use: "list",
|
Use: "list",
|
||||||
Short: "List configs",
|
Short: "List configs",
|
||||||
Aliases: []string{"ls"},
|
Aliases: []string{"ls"},
|
||||||
|
Example: ` Print configs in a table format:
|
||||||
|
psu config ls
|
||||||
|
|
||||||
|
Print available config keys:
|
||||||
|
psu config ls --format "{{ .Key }}"
|
||||||
|
|
||||||
|
Print configs in a yaml|properties format:
|
||||||
|
psu config ls --format "{{ .Key }}:{{ if .CurrentValue }} {{ .CurrentValue }}{{ end }}"
|
||||||
|
|
||||||
|
Print available environment variables:
|
||||||
|
psu config ls --format "{{ .EnvironmentVariable }}"
|
||||||
|
|
||||||
|
Print configs in a dotenv format:
|
||||||
|
psu config ls --format "{{ .EnvironmentVariable }}={{ if .CurrentValue }}{{ .CurrentValue }}{{ end }}"`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
// Get alphabetically ordered list of config keys
|
// Get alphabetically ordered list of config keys
|
||||||
keys := viper.AllKeys()
|
keys := viper.AllKeys()
|
||||||
@ -77,6 +91,17 @@ func init() {
|
|||||||
|
|
||||||
configListCmd.Flags().String("format", "", "Format output using a Go template.")
|
configListCmd.Flags().String("format", "", "Format output using a Go template.")
|
||||||
viper.BindPFlag("config.list.format", configListCmd.Flags().Lookup("format"))
|
viper.BindPFlag("config.list.format", configListCmd.Flags().Lookup("format"))
|
||||||
|
|
||||||
|
configListCmd.SetUsageTemplate(configListCmd.UsageTemplate() + `
|
||||||
|
Format:
|
||||||
|
The --format flag accepts a Go template, which is executed in an object with this structure:
|
||||||
|
|
||||||
|
{
|
||||||
|
Key string
|
||||||
|
EnvironmentVariable string
|
||||||
|
CurrentValue string
|
||||||
|
}
|
||||||
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user