diff --git a/cmd/config.go b/cmd/config.go new file mode 100644 index 0000000..2d1cb8b --- /dev/null +++ b/cmd/config.go @@ -0,0 +1,64 @@ +/* +Copyright © Brian Buller +*/ +package cmd + +import ( + "fmt" + "strings" + + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +// configCmd represents the config command +var configCmd = &cobra.Command{ + Use: "config", + Short: "View/Edit Config", + RunE: func(cmd *cobra.Command, args []string) error { + setVal := func(k, v string) error { + viper.Set(k, v) + return viper.WriteConfig() + } + + switch len(args) { + case 0: + // List all config keys + all := viper.AllKeys() + for i := range all { + fmt.Printf("%s: %s\n", all[i], viper.Get(all[i])) + } + return nil + case 1: + k := args[0] + if strings.Contains(k, "=") { + // This is actually a set + pts := strings.Split(k, "=") + if viper.IsSet(pts[0]) { + return setVal(pts[0], pts[1]) + } else { + return fmt.Errorf("no config value found for %s", pts[0]) + } + return nil + } + // Show a config key/value + if viper.IsSet(k) { + fmt.Printf("%s: %s\n", k, viper.Get(k)) + } else { + return fmt.Errorf("no config value found for %s", k) + } + return nil + case 2: + // Setting a config value + if !viper.IsSet(args[0]) { + return fmt.Errorf("no config value found for %s", args[0]) + } + return setVal(args[0], args[1]) + } + return nil + }, +} + +func init() { + rootCmd.AddCommand(configCmd) +} diff --git a/cmd/get.go b/cmd/get.go index 68300ca..e65dd29 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -1,5 +1,5 @@ /* -Copyright © 2024 Brian Buller +Copyright © Brian Buller */ package cmd diff --git a/cmd/rofi.go b/cmd/rofi.go index 65e3fb1..62bdc56 100644 --- a/cmd/rofi.go +++ b/cmd/rofi.go @@ -1,5 +1,5 @@ /* -Copyright © 2024 Brian Buller +Copyright © Brian Buller */ package cmd diff --git a/cmd/rofiNotes.go b/cmd/rofiNotes.go index 642a091..ac2a06d 100644 --- a/cmd/rofiNotes.go +++ b/cmd/rofiNotes.go @@ -1,5 +1,5 @@ /* -Copyright © 2024 Brian Buller +Copyright © Brian Buller Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/cmd/rofiUn.go b/cmd/rofiUn.go index 4d53ee1..9ef08ef 100644 --- a/cmd/rofiUn.go +++ b/cmd/rofiUn.go @@ -1,5 +1,5 @@ /* -Copyright © 2024 Brian Buller +Copyright © Brian Buller Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/cmd/root.go b/cmd/root.go index 3b8099c..60a3e94 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,5 +1,5 @@ /* -Copyright © 2024 Brian Buller +Copyright © Brian Buller */ package cmd diff --git a/cmd/test.go b/cmd/test.go index e05005c..3e4a947 100644 --- a/cmd/test.go +++ b/cmd/test.go @@ -1,5 +1,5 @@ /* -Copyright © 2024 Brian Buller +Copyright © Brian Buller */ package cmd