2023-04-19 08:28:09 +03:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
2023-04-26 18:16:42 +03:00
|
|
|
"github.com/neilotoole/sq/cli/config/yamlstore"
|
2023-04-19 08:28:09 +03:00
|
|
|
"github.com/neilotoole/sq/cli/flag"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newConfigCmd() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "config",
|
2023-05-01 06:59:34 +03:00
|
|
|
Args: cobra.NoArgs,
|
2023-04-19 08:28:09 +03:00
|
|
|
Short: "Manage config",
|
2023-05-05 20:41:22 +03:00
|
|
|
Long: `View and edit config.`,
|
2023-04-19 08:28:09 +03:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return cmd.Help()
|
|
|
|
},
|
|
|
|
Example: ` # Print config location
|
2023-04-23 01:31:28 +03:00
|
|
|
$ sq config location
|
|
|
|
|
2023-05-03 15:36:10 +03:00
|
|
|
# Show base config
|
2023-04-23 01:31:28 +03:00
|
|
|
$ sq config get
|
|
|
|
|
2023-05-03 15:36:10 +03:00
|
|
|
# Show base config including unset and default values.
|
|
|
|
$ sq config get -v
|
|
|
|
|
2023-05-05 20:41:22 +03:00
|
|
|
# Set option value
|
2023-05-03 15:36:10 +03:00
|
|
|
$ sq config set format json
|
|
|
|
|
|
|
|
# Edit base config
|
2023-04-23 01:31:28 +03:00
|
|
|
$ sq config edit
|
|
|
|
|
|
|
|
# Edit config for source
|
2023-05-05 20:41:22 +03:00
|
|
|
$ sq config edit @sakila
|
|
|
|
|
|
|
|
# Delete option (reset to default value)
|
|
|
|
$ sq config set -D log.level`,
|
2023-04-19 08:28:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func newConfigLocationCmd() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "location",
|
|
|
|
Aliases: []string{"loc"},
|
|
|
|
Short: "Print config location",
|
|
|
|
Long: "Print config location. Use --verbose for more detail.",
|
|
|
|
Args: cobra.ExactArgs(0),
|
|
|
|
RunE: execConfigLocation,
|
|
|
|
Example: ` # Print config location
|
2023-04-23 01:31:28 +03:00
|
|
|
$ sq config location
|
2023-04-19 08:28:09 +03:00
|
|
|
/Users/neilotoole/.config/sq
|
|
|
|
|
|
|
|
# Print location, also show origin (flag, env, default)
|
|
|
|
$ sq config location -v
|
|
|
|
/Users/neilotoole/.config/sq
|
|
|
|
Origin: env`,
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Flags().BoolP(flag.JSON, flag.JSONShort, false, flag.JSONUsage)
|
|
|
|
cmd.Flags().BoolP(flag.YAML, flag.YAMLShort, false, flag.YAMLUsage)
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func execConfigLocation(cmd *cobra.Command, _ []string) error {
|
|
|
|
rc := RunContextFrom(cmd.Context())
|
|
|
|
path := rc.ConfigStore.Location()
|
|
|
|
var origin string
|
2023-04-26 18:16:42 +03:00
|
|
|
if store, ok := rc.ConfigStore.(*yamlstore.Store); ok {
|
2023-04-19 08:28:09 +03:00
|
|
|
origin = store.PathOrigin
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc.writers.configw.Location(path, origin)
|
|
|
|
}
|