-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
remove.go
43 lines (33 loc) · 733 Bytes
/
remove.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package file
import (
"github.com/guumaster/hostctl/pkg/types"
)
// RemoveProfiles removes given profiles from the list.
func (f *File) RemoveProfiles(profiles []string) error {
for _, p := range profiles {
err := f.RemoveProfile(p)
if err != nil {
return err
}
}
return nil
}
// RemoveProfile removes given profile from the list.
func (f *File) RemoveProfile(name string) error {
var names []string
if name == types.Default {
return types.ErrDefaultProfile
}
_, ok := f.data.Profiles[name]
if !ok {
return types.ErrUnknownProfile
}
delete(f.data.Profiles, name)
for _, n := range f.data.ProfileNames {
if n != name {
names = append(names, n)
}
}
f.data.ProfileNames = names
return nil
}