Skip to content

Commit 8dac16a

Browse files
committed
Add --start Flag to limactl shell
This PR is a follow up to #4108 and <#3995 (comment)> which adds a new `--start` flag to the `shell` subcommand, which auto-starts the VM in case it isn't already running. Note that, unlike #4108, I did not add any deprecation warning to the `--yes` flag since it was previously ignored by `limactl shell`. Signed-off-by: Nicholas Rodrigues Lordello <n@lordello.net>
1 parent 808c80c commit 8dac16a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

cmd/limactl/shell.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@ func newShellCommand() *cobra.Command {
6363
shellCmd.Flags().String("workdir", "", "Working directory")
6464
shellCmd.Flags().Bool("reconnect", false, "Reconnect to the SSH session")
6565
shellCmd.Flags().Bool("preserve-env", false, "Propagate environment variables to the shell")
66+
shellCmd.Flags().Bool("start", false, "Start the instance if it is not already running")
6667
return shellCmd
6768
}
6869

6970
func shellAction(cmd *cobra.Command, args []string) error {
7071
ctx := cmd.Context()
72+
flags := cmd.Flags()
7173
// simulate the behavior of double dash
7274
newArg := []string{}
7375
if len(args) >= 2 && args[1] == "--" {
@@ -93,11 +95,18 @@ func shellAction(cmd *cobra.Command, args []string) error {
9395
return err
9496
}
9597
if inst.Status == limatype.StatusStopped {
96-
startNow, err := askWhetherToStart()
98+
startNow, err := flags.GetBool("start")
9799
if err != nil {
98100
return err
99101
}
100102

103+
if !flags.Changed("start") {
104+
startNow, err = askWhetherToStart()
105+
if err != nil {
106+
return err
107+
}
108+
}
109+
101110
if !startNow {
102111
return nil
103112
}

0 commit comments

Comments
 (0)