-
Notifications
You must be signed in to change notification settings - Fork 649
/
Copy pathsave.go
44 lines (37 loc) · 1.05 KB
/
save.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
package main
import (
"github.com/lima-vm/lima/pkg/instance"
networks "github.com/lima-vm/lima/pkg/networks/reconcile"
"github.com/lima-vm/lima/pkg/store"
"github.com/spf13/cobra"
)
func newSaveCommand() *cobra.Command {
saveCmd := &cobra.Command{
Use: "save INSTANCE",
Short: "Save an instance",
Args: WrapArgsError(cobra.MaximumNArgs(1)),
RunE: saveAction,
ValidArgsFunction: saveBashComplete,
GroupID: basicCommand,
}
return saveCmd
}
func saveAction(cmd *cobra.Command, args []string) error {
instName := DefaultInstanceName
if len(args) > 0 {
instName = args[0]
}
inst, err := store.Inspect(instName)
if err != nil {
return err
}
err = instance.StopGracefully(inst, true)
// TODO: should we also reconcile networks if graceful save returned an error?
if err == nil {
err = networks.Reconcile(cmd.Context(), "")
}
return err
}
func saveBashComplete(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
return bashCompleteInstanceNames(cmd)
}