Skip to content

Commit

Permalink
limactl: make --tty to be a global flag
Browse files Browse the repository at this point in the history
`limactl start --tty=false` can be now `limactl --tty=false start` .

The previous form continues to work too.

Fix issue 1861

Signed-off-by: Akihiro Suda <[email protected]>
  • Loading branch information
AkihiroSuda committed Sep 30, 2023
1 parent e7f8ffb commit 92cdf5e
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 8 deletions.
3 changes: 0 additions & 3 deletions cmd/limactl/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/lima-vm/lima/pkg/store"
"github.com/lima-vm/lima/pkg/store/filenames"
"github.com/lima-vm/lima/pkg/yqutil"
"github.com/mattn/go-isatty"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand All @@ -29,8 +28,6 @@ func newEditCommand() *cobra.Command {
RunE: editAction,
ValidArgsFunction: editBashComplete,
}
// TODO: "survey" does not support using cygwin terminal on windows yet
editCommand.Flags().Bool("tty", isatty.IsTerminal(os.Stdout.Fd()), "enable TUI interactions such as opening an editor, defaults to true when stdout is a terminal")
editflags.RegisterEdit(editCommand)
return editCommand
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/limactl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func newApp() *cobra.Command {
}
rootCmd.PersistentFlags().String("log-level", "", "Set the logging level [trace, debug, info, warn, error]")
rootCmd.PersistentFlags().Bool("debug", false, "debug mode")
// TODO: "survey" does not support using cygwin terminal on windows yet
rootCmd.PersistentFlags().Bool("tty", isatty.IsTerminal(os.Stdout.Fd()), "Enable TUI interactions such as opening an editor. Defaults to true when stdout is a terminal. Set to false for automation.")
rootCmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
l, _ := cmd.Flags().GetString("log-level")
if l != "" {
Expand Down
3 changes: 0 additions & 3 deletions cmd/limactl/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@ import (
"github.com/lima-vm/lima/pkg/store/filenames"
"github.com/lima-vm/lima/pkg/templatestore"
"github.com/lima-vm/lima/pkg/yqutil"
"github.com/mattn/go-isatty"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

func registerCreateFlags(cmd *cobra.Command, commentPrefix string) {
flags := cmd.Flags()
// TODO: "survey" does not support using cygwin terminal on windows yet
flags.Bool("tty", isatty.IsTerminal(os.Stdout.Fd()), commentPrefix+"enable TUI interactions such as opening an editor, defaults to true when stdout is a terminal")
flags.String("name", "", commentPrefix+"override the instance name")
flags.Bool("list-templates", false, commentPrefix+"list available templates and exit")
editflags.RegisterCreate(cmd, commentPrefix)
Expand Down
2 changes: 1 addition & 1 deletion hack/test-port-forwarding.pl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# running to perform the tests:
#
# ./hack/test-port-forwarding.pl templates/default.yaml
# limactl start --tty=false templates/default.yaml
# limactl --tty=false start templates/default.yaml
# git restore templates/default.yaml
# ./hack/test-port-forwarding.pl default
#
Expand Down
2 changes: 1 addition & 1 deletion hack/test-templates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ INFO "Validating \"$FILE\""
limactl validate "$FILE"

# --cpus=1 is needed for running vz on GHA: https://github.com/lima-vm/lima/pull/1511#issuecomment-1574937888
LIMACTL_CREATE=(limactl create --tty=false --cpus=1 --memory=1)
LIMACTL_CREATE=(limactl --tty=false create --cpus=1 --memory=1)

CONTAINER_ENGINE="nerdctl"

Expand Down

0 comments on commit 92cdf5e

Please sign in to comment.