returns also the value of the duplicate

This commit is contained in:
alessio 2016-08-25 14:46:28 +02:00
parent da42706f71
commit 2cda8c8d90

View File

@ -73,20 +73,20 @@ func New(params *cli.Context) *Config {
} }
// Duplicates check projects with same name or same combinations of main/path // Duplicates check projects with same name or same combinations of main/path
func Duplicates(value Project, arr []Project) error { func Duplicates(value Project, arr []Project) (error, Project) {
for _, val := range arr { for _, val := range arr {
if value.Path == val.Path || value.Name == val.Name { if value.Path == val.Path || value.Name == val.Name {
return errors.New("There is a duplicate of '" + val.Name + "'. Check your config file!") return errors.New("There is a duplicate of '" + val.Name + "'. Check your config file!"), val
} }
} }
return nil return nil, Project{}
} }
// Clean duplicate projects // Clean duplicate projects
func (h *Config) Clean() { func (h *Config) Clean() {
arr := h.Projects arr := h.Projects
for key, val := range arr { for key, val := range arr {
if err := Duplicates(val, arr[key+1:]); err != nil { if err, _ := Duplicates(val, arr[key+1:]); err != nil {
h.Projects = append(arr[:key], arr[key+1:]...) h.Projects = append(arr[:key], arr[key+1:]...)
break break
} }
@ -139,7 +139,7 @@ func (h *Config) Add(params *cli.Context) error {
Ignore: watcherIgnores, Ignore: watcherIgnores,
}, },
} }
if err := Duplicates(new, h.Projects); err != nil { if err, _ := Duplicates(new, h.Projects); err != nil {
return err return err
} }
h.Projects = append(h.Projects, new) h.Projects = append(h.Projects, new)