diff options
author | Pedro L. Ramos <pedrolorgaramos@tecnico.ulisboa.pt> | 2019-07-13 18:42:22 +0100 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-07-15 09:42:03 -0400 |
commit | d85f671bdf90dbdd725db88e5d6970630e36f9f1 (patch) | |
tree | f4cb94081d12087cc6de04dacd8a44157ccab2bb /commands/set.go | |
parent | 9bf1a0418ba7fa817c4704d363bc4350ef883b59 (diff) | |
download | aerc-d85f671bdf90dbdd725db88e5d6970630e36f9f1.tar.gz |
71: Allow user to change config options at runtime
There is a LoadConf and a LoadConfFromFile. LoadConfFromFile reads the iniFile into memory and and calls LoadConf, which executes the old parsing commands from LoadConf (old func). The remaining of the LoadConfFromFile is the same as the old OldConf.
Diffstat (limited to 'commands/set.go')
-rw-r--r-- | commands/set.go | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/commands/set.go b/commands/set.go new file mode 100644 index 0000000..f5366ff --- /dev/null +++ b/commands/set.go @@ -0,0 +1,69 @@ +package commands + +import ( + "errors" + "strings" + + "git.sr.ht/~sircmpwn/aerc/widgets" + + "github.com/go-ini/ini" +) + +type Set struct{} + +func setUsage() string { + return "set <category>.<option> <value>" +} + +func init() { + register(Set{}) +} + +func (_ Set) Aliases() []string { + return []string{"set"} + +} + +func (_ Set) Complete(aerc *widgets.Aerc, args []string) []string { + return nil +} + +func SetCore(aerc *widgets.Aerc, args []string) error { + if len(args) != 3 { + return errors.New("Usage: " + setUsage()) + } + + config := aerc.Config() + + parameters := strings.Split(args[1], ".") + + if len(parameters) != 2 { + return errors.New("Usage: " + setUsage()) + } + + category := parameters[0] + option := parameters[1] + value := args[2] + + new_file := ini.Empty() + + section, err := new_file.NewSection(category) + + if err != nil { + return nil + } + + if _, err := section.NewKey(option, value); err != nil { + return err + } + + if err := config.LoadConfig(new_file); err != nil { + return err + } + + return nil +} + +func (_ Set) Execute(aerc *widgets.Aerc, args []string) error { + return SetCore(aerc, args) +} |