Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lima-vm
GitHub Repository: lima-vm/lima
Path: blob/master/cmd/limactl/unprotect.go
1645 views
1
// SPDX-FileCopyrightText: Copyright The Lima Authors
2
// SPDX-License-Identifier: Apache-2.0
3
4
package main
5
6
import (
7
"errors"
8
"fmt"
9
10
"github.com/sirupsen/logrus"
11
"github.com/spf13/cobra"
12
13
"github.com/lima-vm/lima/v2/pkg/store"
14
)
15
16
func newUnprotectCommand() *cobra.Command {
17
unprotectCommand := &cobra.Command{
18
Use: "unprotect INSTANCE [INSTANCE, ...]",
19
Short: "Unprotect an instance",
20
Args: WrapArgsError(cobra.MinimumNArgs(1)),
21
RunE: unprotectAction,
22
ValidArgsFunction: unprotectBashComplete,
23
GroupID: advancedCommand,
24
}
25
return unprotectCommand
26
}
27
28
func unprotectAction(cmd *cobra.Command, args []string) error {
29
ctx := cmd.Context()
30
var errs []error
31
for _, instName := range args {
32
inst, err := store.Inspect(ctx, instName)
33
if err != nil {
34
errs = append(errs, fmt.Errorf("failed to inspect instance %q: %w", instName, err))
35
continue
36
}
37
if !inst.Protected {
38
logrus.Warnf("Instance %q isn't protected. Skipping.", instName)
39
continue
40
}
41
if err := inst.Unprotect(); err != nil {
42
errs = append(errs, fmt.Errorf("failed to unprotect instance %q: %w", instName, err))
43
continue
44
}
45
logrus.Infof("Unprotected %q", instName)
46
}
47
return errors.Join(errs...)
48
}
49
50
func unprotectBashComplete(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
51
return bashCompleteInstanceNames(cmd)
52
}
53
54