From e19d69b8451c7ec10194746e662502e2af4e5396 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Thu, 6 Jan 2022 03:13:52 +0400 Subject: [PATCH] [configuration.go] append a list instead, in case there are multiple processes options. Removed StoreConfiguratuion from Add/RemoveProcess funcs, and shorten theirs names. --- configuration.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/configuration.go b/configuration.go index b4486d1..0559fcc 100644 --- a/configuration.go +++ b/configuration.go @@ -42,10 +42,9 @@ func LoadConfiguration(path string) (conf *Configuration, err error) { conf.IndentedOutput = v case "processes": if kv[1] != "" { - conf.Processes = strings.Split(kv[1], " ") + conf.Processes = append(conf.Processes, strings.Split(kv[1], " ")...) } else { log.Printf("WARN: \"processes\" list is empty.\n") - conf.Processes = []string{} } } } @@ -73,8 +72,8 @@ func (conf *Configuration) StoreConfiguration(path string) (err error) { return nil } -// AddProcessToList appends a new given process into a configuration file. -func (conf *Configuration) AddProcessToList(process string, configPath string) error { +// AddProcess appends a new given process into a configuration file. +func (conf *Configuration) AddProcess(process string, configPath string) error { for _, v := range conf.Processes { if v == process { return ErrIsOnList @@ -82,24 +81,16 @@ func (conf *Configuration) AddProcessToList(process string, configPath string) e } conf.Processes = append(conf.Processes, process) - if err := conf.StoreConfiguration(configPath); err != nil { - return err - } - return nil } -// RemoveProcessFromList removes a given process from a configuration file. -func (conf *Configuration) RemoveProcessFromList(process string, configPath string) error { +// RemoveProcess removes a given process from a configuration file. +func (conf *Configuration) RemoveProcess(process string, configPath string) error { for k, v := range conf.Processes { if v == process { newlist := make([]string, len(conf.Processes)-1) newlist = append(conf.Processes[:k], conf.Processes[k+1:]...) conf.Processes = newlist - if err := conf.StoreConfiguration(configPath); err != nil { - return err - } - return nil } }