-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile_clearselection.go
43 lines (38 loc) · 1.33 KB
/
profile_clearselection.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 cmd
import (
"github.com/brawaru/marct/launcher"
"github.com/brawaru/marct/locales"
"github.com/nicksnyder/go-i18n/v2/i18n"
"github.com/urfave/cli/v2"
)
var profileSelectionClearCommand = createCommand(&cli.Command{
Name: "selection-clear",
Aliases: []string{"deselect"},
Usage: locales.Translate(&i18n.Message{
ID: "command.profile-selection-clear.usage",
Other: "Clear default profile selection",
}),
Description: locales.Translate(&i18n.Message{
ID: "command.profile-selection-clear.description",
Other: "Allows to clear default profile used in management or launch commands",
}),
Action: func(ctx *cli.Context) error {
workDir := ctx.Context.Value(instanceKey).(*launcher.Instance)
profiles := ctx.Context.Value(profilesKey).(*launcher.Profiles)
profiles.SelectedProfile = nil
err := workDir.WriteProfiles(profiles)
if err != nil {
return cli.Exit(locales.Translate(&i18n.Message{
ID: "command.profile-selection-clear.profiles-write-failed",
Other: "Failed to save changes to profile file: {{ .Error }}",
}), 1)
}
return cli.Exit(locales.Translate(&i18n.Message{
ID: "command.profile-selection-clear.success",
Other: "Cleared profile selection",
}), 0)
},
})
func init() {
profileCommand.Subcommands = append(profileCommand.Subcommands, profileSelectionClearCommand)
}