in controller/profile/profile.go [95:133]
func (c controller) DeleteProfiles(names []string) error {
profilesMap, err := c.GetProfilesMap()
if err != nil {
return err
}
var invalidProfileNames []string
for _, name := range names {
if _, ok := profilesMap[name]; !ok {
invalidProfileNames = append(invalidProfileNames, name)
continue
}
delete(profilesMap, name)
}
//load config
data, err := c.configCtrl.Read()
if err != nil {
return err
}
//empty existing profile
data.Profiles = nil
for _, p := range profilesMap {
// add existing profiles to the list
data.Profiles = append(data.Profiles, p)
}
//save config
err = c.configCtrl.Write(data)
if err != nil {
return err
}
// if found any invalid profiles
if len(invalidProfileNames) > 0 {
return fmt.Errorf("no profiles found for: %s", strings.Join(invalidProfileNames, ", "))
}
return nil
}