1
0

[configuration.go] append a list instead, in case there are multiple processes options.

Removed StoreConfiguratuion from Add/RemoveProcess funcs, and shorten theirs names.
This commit is contained in:
Alexander Andreev 2022-01-06 03:13:52 +04:00
parent c0407cb4d6
commit e19d69b845
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F

View File

@ -42,10 +42,9 @@ func LoadConfiguration(path string) (conf *Configuration, err error) {
conf.IndentedOutput = v conf.IndentedOutput = v
case "processes": case "processes":
if kv[1] != "" { if kv[1] != "" {
conf.Processes = strings.Split(kv[1], " ") conf.Processes = append(conf.Processes, strings.Split(kv[1], " ")...)
} else { } else {
log.Printf("WARN: \"processes\" list is empty.\n") 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 return nil
} }
// AddProcessToList appends a new given process into a configuration file. // AddProcess appends a new given process into a configuration file.
func (conf *Configuration) AddProcessToList(process string, configPath string) error { func (conf *Configuration) AddProcess(process string, configPath string) error {
for _, v := range conf.Processes { for _, v := range conf.Processes {
if v == process { if v == process {
return ErrIsOnList return ErrIsOnList
@ -82,24 +81,16 @@ func (conf *Configuration) AddProcessToList(process string, configPath string) e
} }
conf.Processes = append(conf.Processes, process) conf.Processes = append(conf.Processes, process)
if err := conf.StoreConfiguration(configPath); err != nil {
return err
}
return nil return nil
} }
// RemoveProcessFromList removes a given process from a configuration file. // RemoveProcess removes a given process from a configuration file.
func (conf *Configuration) RemoveProcessFromList(process string, configPath string) error { func (conf *Configuration) RemoveProcess(process string, configPath string) error {
for k, v := range conf.Processes { for k, v := range conf.Processes {
if v == process { if v == process {
newlist := make([]string, len(conf.Processes)-1) newlist := make([]string, len(conf.Processes)-1)
newlist = append(conf.Processes[:k], conf.Processes[k+1:]...) newlist = append(conf.Processes[:k], conf.Processes[k+1:]...)
conf.Processes = newlist conf.Processes = newlist
if err := conf.StoreConfiguration(configPath); err != nil {
return err
}
return nil return nil
} }
} }