MCPcopy
hub / github.com/lima-vm/lima / shellAction

Function shellAction

cmd/limactl/shell.go:86–445  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

84)
85
86func shellAction(cmd *cobra.Command, args []string) error {
87 ctx := cmd.Context()
88 flags := cmd.Flags()
89 tty, err := flags.GetBool("tty")
90 if err != nil {
91 return err
92 }
93
94 // When --instance is specified, all positional args are treated as COMMAND.
95 // Otherwise, the first positional arg is the instance name (backward compatible).
96 instName, err := flags.GetString("instance")
97 if err != nil {
98 return err
99 }
100 if instName != "" {
101 // All args are COMMAND; prepend a placeholder instance name so the rest of the code works unchanged.
102 args = append([]string{instName}, args...)
103 } else {
104 if len(args) == 0 {
105 return errors.New("requires instance name as first argument")
106 }
107 // simulate the behavior of double dash
108 newArg := []string{}
109 if len(args) >= 2 && args[1] == "--" {
110 newArg = append(newArg, args[:1]...)
111 newArg = append(newArg, args[2:]...)
112 args = newArg
113 }
114 instName = args[0]
115 }
116
117 if len(args) >= 2 {
118 switch args[1] {
119 case "create", "start", "delete", "shell":
120 // `lima start` (alias of `limactl $LIMA_INSTANCE start`) is probably a typo of `limactl start`
121 logrus.Warnf("Perhaps you meant `limactl %s`?", strings.Join(args[1:], " "))
122 }
123 }
124
125 inst, err := store.Inspect(ctx, instName)
126 if err != nil {
127 if errors.Is(err, os.ErrNotExist) {
128 return fmt.Errorf("instance %#q does not exist, run `limactl create %s` to create a new instance", instName, instName)
129 }
130 return err
131 }
132 if len(inst.Errors) > 0 {
133 logrus.WithError(errors.Join(inst.Errors...)).Errorf("Instance %#q has configuration errors", instName)
134 }
135 if inst.Config == nil {
136 return fmt.Errorf("instance %#q has no configuration", instName)
137 }
138 if inst.Status == limatype.StatusStopped {
139 startNow, err := flags.GetBool("start")
140 if err != nil {
141 return err
142 }
143

Callers

nothing calls this directly

Calls 15

InspectFunction · 0.92
IsRegisteredFunction · 0.92
ReconcileFunction · 0.92
StartFunction · 0.92
WithLaunchingShellFunction · 0.92
IsControlMasterExistingFunction · 0.92
FilterEnvironmentFunction · 0.92
NewSSHExeFunction · 0.92
SSHOptsFunction · 0.92
SSHArgsFromOptsFunction · 0.92
NewFunction · 0.92

Tested by

no test coverage detected