I believe that all functionality is implemented
This commit is contained in:
@@ -7,6 +7,7 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
@@ -15,8 +16,11 @@ import (
|
||||
// configCmd represents the config command
|
||||
var configCmd = &cobra.Command{
|
||||
Use: "config",
|
||||
Short: "Print all configuration values",
|
||||
RunE: opConfig,
|
||||
Short: "Show or update configuration values",
|
||||
Long: `To set values just list them in key=value format.
|
||||
For example:
|
||||
gime config copytags=true roundto=30m`,
|
||||
RunE: opConfig,
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -24,9 +28,36 @@ func init() {
|
||||
}
|
||||
|
||||
func opConfig(cmd *cobra.Command, args []string) error {
|
||||
updConfig := make(map[string]string)
|
||||
if len(args) > 0 {
|
||||
// We're setting arguments
|
||||
for _, a := range args {
|
||||
pts := strings.Split(a, "=")
|
||||
if len(pts) == 2 {
|
||||
updConfig[pts[0]] = pts[1]
|
||||
} else {
|
||||
return fmt.Errorf("Unable to parse config values.")
|
||||
}
|
||||
}
|
||||
}
|
||||
var settings []string
|
||||
for k, v := range viper.AllSettings() {
|
||||
settings = append(settings, fmt.Sprintf("%s: %s", k, v))
|
||||
switch v.(type) {
|
||||
case bool:
|
||||
if nv, ok := updConfig[k]; ok {
|
||||
v = nv == "true"
|
||||
viper.Set(k, v)
|
||||
viper.WriteConfig()
|
||||
}
|
||||
settings = append(settings, fmt.Sprintf("%s: %t", k, v))
|
||||
default:
|
||||
if nv, ok := updConfig[k]; ok {
|
||||
v = nv
|
||||
viper.Set(k, v)
|
||||
viper.WriteConfig()
|
||||
}
|
||||
settings = append(settings, fmt.Sprintf("%s: %s", k, v))
|
||||
}
|
||||
}
|
||||
sort.Strings(settings)
|
||||
fmt.Println("Configuration File:", viper.ConfigFileUsed())
|
||||
|
||||
Reference in New Issue
Block a user