-
Notifications
You must be signed in to change notification settings - Fork 13
/
reset.go
68 lines (56 loc) · 1.71 KB
/
reset.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package use
import (
"runtime"
"github.com/ActiveState/cli/internal/config"
"github.com/ActiveState/cli/internal/globaldefault"
"github.com/ActiveState/cli/internal/locale"
"github.com/ActiveState/cli/internal/logging"
"github.com/ActiveState/cli/internal/output"
"github.com/ActiveState/cli/internal/prompt"
"github.com/ActiveState/cli/internal/subshell"
)
type Reset struct {
prompt prompt.Prompter
out output.Outputer
config *config.Instance
subshell subshell.SubShell
}
type ResetParams struct {
Force bool
}
func NewReset(prime primeable) *Reset {
return &Reset{
prime.Prompt(),
prime.Output(),
prime.Config(),
prime.Subshell(),
}
}
func (u *Reset) Run(params *ResetParams) error {
logging.Debug("Resetting default project runtime")
if !globaldefault.IsSet(u.config) {
return locale.NewInputError(locale.T("use_reset_notice_not_reset"))
}
defaultChoice := params.Force || !u.out.Config().Interactive
ok, err := u.prompt.Confirm(locale.T("confirm"),
locale.Tl("use_reset_confirm", "You are about to stop using your project runtime. Continue?"), &defaultChoice)
if err != nil {
return err
}
if !ok {
return locale.NewInputError("err_reset_aborted", "Reset aborted by user")
}
reset, err := globaldefault.ResetDefaultActivation(u.subshell, u.config)
if err != nil {
return locale.WrapError(err, "err_use_reset", "Could not stop using your project.")
} else if !reset {
return locale.NewInputError(locale.T("use_reset_notice_not_reset"))
}
u.out.Notice(locale.Tl("use_reset_notice_reset", "Stopped using your project runtime"))
if runtime.GOOS == "windows" {
u.out.Notice(locale.T("use_reset_notice_windows"))
} else {
u.out.Notice(locale.T("use_reset_notice"))
}
return nil
}