Skip to content

Commit d82d125

Browse files
authored
Merge pull request #3337 from tatucosmin/ask-start-shell-confirmation
feat: ask to start instance if not running in limactl shell
2 parents 9fd8519 + 9b09980 commit d82d125

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

cmd/limactl/shell.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import (
1515

1616
"al.essio.dev/pkg/shellescape"
1717
"github.com/coreos/go-semver/semver"
18+
"github.com/lima-vm/lima/pkg/instance"
1819
"github.com/lima-vm/lima/pkg/ioutilx"
20+
networks "github.com/lima-vm/lima/pkg/networks/reconcile"
1921
"github.com/lima-vm/lima/pkg/sshutil"
2022
"github.com/lima-vm/lima/pkg/store"
2123
"github.com/mattn/go-isatty"
@@ -78,7 +80,31 @@ func shellAction(cmd *cobra.Command, args []string) error {
7880
return err
7981
}
8082
if inst.Status == store.StatusStopped {
81-
return fmt.Errorf("instance %q is stopped, run `limactl start %s` to start the instance", instName, instName)
83+
startNow, err := askWhetherToStart()
84+
if err != nil {
85+
return err
86+
}
87+
88+
if !startNow {
89+
return nil
90+
}
91+
92+
ctx := cmd.Context()
93+
94+
err = networks.Reconcile(ctx, inst.Name)
95+
if err != nil {
96+
return err
97+
}
98+
99+
err = instance.Start(ctx, inst, "", false)
100+
if err != nil {
101+
return err
102+
}
103+
104+
inst, err = store.Inspect(instName)
105+
if err != nil {
106+
return err
107+
}
82108
}
83109

84110
// When workDir is explicitly set, the shell MUST have workDir as the cwd, or exit with an error.

0 commit comments

Comments
 (0)