@@ -51,6 +51,7 @@ func newShellCommand() *cobra.Command {
51
51
}
52
52
53
53
func shellAction (cmd * cobra.Command , args []string ) error {
54
+ _ = os .Setenv ("_LIMACTL_SHELL_IN_ACTION" , "" )
54
55
// simulate the behavior of double dash
55
56
newArg := []string {}
56
57
if len (args ) >= 2 && args [1 ] == "--" {
@@ -68,15 +69,36 @@ func shellAction(cmd *cobra.Command, args []string) error {
68
69
}
69
70
}
70
71
72
+ tty , err := interactive (cmd )
73
+ if err != nil {
74
+ return err
75
+ }
71
76
inst , err := store .Inspect (instName )
72
77
if err != nil {
73
- if errors .Is (err , os .ErrNotExist ) {
78
+ if ! errors .Is (err , os .ErrNotExist ) {
79
+ return err
80
+ }
81
+ if ! tty {
74
82
return fmt .Errorf ("instance %q does not exist, run `limactl create %s` to create a new instance" , instName , instName )
75
83
}
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 {
76
98
return err
77
99
}
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 )
80
102
}
81
103
82
104
// When workDir is explicitly set, the shell MUST have workDir as the cwd, or exit with an error.
0 commit comments