@@ -51,6 +51,7 @@ func newShellCommand() *cobra.Command {
5151}
5252
5353func shellAction (cmd * cobra.Command , args []string ) error {
54+ _ = os .Setenv ("_LIMACTL_SHELL_IN_ACTION" , "" )
5455 // simulate the behavior of double dash
5556 newArg := []string {}
5657 if len (args ) >= 2 && args [1 ] == "--" {
@@ -68,15 +69,36 @@ func shellAction(cmd *cobra.Command, args []string) error {
6869 }
6970 }
7071
72+ tty , err := interactive (cmd )
73+ if err != nil {
74+ return err
75+ }
7176 inst , err := store .Inspect (instName )
7277 if err != nil {
73- if errors .Is (err , os .ErrNotExist ) {
78+ if ! errors .Is (err , os .ErrNotExist ) {
79+ return err
80+ }
81+ if ! tty {
7482 return fmt .Errorf ("instance %q does not exist, run `limactl create %s` to create a new instance" , instName , instName )
7583 }
84+ if err := askToStart (cmd , instName , true ); err != nil {
85+ return err
86+ }
87+ inst , err = store .Inspect (instName )
88+ } else if inst .Status == store .StatusStopped {
89+ if ! tty {
90+ return fmt .Errorf ("instance %q is stopped, run `limactl start %s` to start the instance" , instName , instName )
91+ }
92+ if err := askToStart (cmd , instName , false ); err != nil {
93+ return err
94+ }
95+ inst , err = store .Inspect (instName )
96+ }
97+ if err != nil {
7698 return err
7799 }
78- if inst .Status == store .StatusStopped {
79- return fmt .Errorf ("instance %q is stopped, run `limactl start %s` to start the instance " , instName , instName )
100+ if inst .Status != store .StatusRunning {
101+ return fmt .Errorf ("instance %q status is not %q but %q " , inst . Name , store . StatusRunning , inst . Status )
80102 }
81103
82104 // When workDir is explicitly set, the shell MUST have workDir as the cwd, or exit with an error.
0 commit comments