aboutsummaryrefslogtreecommitdiffstats
path: root/lib/pama/switch.go
blob: 4d6b25f778d8f6b56526ce49dba9b2a7b9024dcf (plain) (blame)
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
package pama

import (
	"fmt"
)

func (m PatchManager) SwitchProject(name string) error {
	c, err := m.CurrentProject()
	if err == nil {
		if c.Name == name {
			return nil
		}
	}
	names, err := m.store().Names()
	if err != nil {
		return storeErr(err)
	}
	found := false
	for _, n := range names {
		if n == name {
			found = true
			break
		}
	}
	if !found {
		return fmt.Errorf("Project '%s' not found", name)
	}
	return storeErr(m.store().SetCurrent(name))
}