diff --git a/cmd/limactl/clone.go b/cmd/limactl/clone.go index e7946eb45c1..06a95f68c15 100644 --- a/cmd/limactl/clone.go +++ b/cmd/limactl/clone.go @@ -34,6 +34,7 @@ Not to be confused with 'limactl copy' ('limactl cp'). ValidArgsFunction: cloneBashComplete, GroupID: advancedCommand, } + cloneCommand.Flags().Bool("start", false, "Start the instance after cloning") editflags.RegisterEdit(cloneCommand, "[limactl edit] ") return cloneCommand } @@ -48,6 +49,7 @@ func newRenameCommand() *cobra.Command { ValidArgsFunction: cloneBashComplete, GroupID: advancedCommand, } + renameCommand.Flags().Bool("start", false, "Start the instance after renaming") editflags.RegisterEdit(renameCommand, "[limactl edit] ") return renameCommand } @@ -113,15 +115,18 @@ func cloneOrRenameAction(cmd *cobra.Command, args []string) error { } } - if !tty { - // use "start" to start it - return nil - } - startNow, err := askWhetherToStart() + start, err := flags.GetBool("start") if err != nil { return err } - if !startNow { + + if tty && !flags.Changed("start") { + start, err = askWhetherToStart() + if err != nil { + return err + } + } + if !start { return nil } err = reconcile.Reconcile(ctx, newInst.Name) diff --git a/cmd/limactl/edit.go b/cmd/limactl/edit.go index 5eccfcfe8bc..5512d6cdf55 100644 --- a/cmd/limactl/edit.go +++ b/cmd/limactl/edit.go @@ -36,6 +36,7 @@ func newEditCommand() *cobra.Command { ValidArgsFunction: editBashComplete, GroupID: basicCommand, } + editCommand.Flags().Bool("start", false, "Start the instance after editing") editflags.RegisterEdit(editCommand, "") return editCommand } @@ -140,19 +141,23 @@ func editAction(cmd *cobra.Command, args []string) error { logrus.Infof("Instance %q configuration edited", inst.Name) } - if !tty { - // use "start" to start it - return nil - } if inst == nil { // edited a limayaml file directly return nil } - startNow, err := askWhetherToStart() + + start, err := flags.GetBool("start") if err != nil { return err } - if !startNow { + + if tty && !flags.Changed("start") { + start, err = askWhetherToStart() + if err != nil { + return err + } + } + if !start { return nil } err = reconcile.Reconcile(ctx, inst.Name) diff --git a/cmd/limactl/main.go b/cmd/limactl/main.go index a91332da2bc..408e3a9e9d5 100644 --- a/cmd/limactl/main.go +++ b/cmd/limactl/main.go @@ -155,6 +155,11 @@ func newApp() *cobra.Command { } if cmd.Flags().Changed("yes") { + switch cmd.Name() { + case "clone", "edit", "rename": + logrus.Warn("--yes flag is deprecated (--tty=false is still supported and works in the same way. Also consider using --start)") + } + // Sets the value of the yesValue flag by using the yes flag. yesValue, _ := cmd.Flags().GetBool("yes") if yesValue {