Browse Source

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

Removed StoreConfiguratuion from Add/RemoveProcess funcs, and shorten theirs names.
master
Alexander Andreev 7 months ago
parent
commit
e19d69b845
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F
  1. 19
      configuration.go

19
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
}
}

Loading…
Cancel
Save