I believe that all functionality is implemented

This commit is contained in:
2022-01-21 08:40:44 -06:00
parent 54c91f0d3c
commit 45d13e7052
12 changed files with 333 additions and 72 deletions

View File

@@ -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())