Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions cmd/limactl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func newApp() *cobra.Command {
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.PersistentFlags().BoolP("yes", "y", false, "Alias of --tty=false")
rootCmd.PersistentPreRunE = func(cmd *cobra.Command, _ []string) error {
l, _ := cmd.Flags().GetString("log-level")
if l != "" {
Expand Down Expand Up @@ -129,6 +130,22 @@ func newApp() *cobra.Command {
if nfs {
return errors.New("must not run on NFS dir")
}

if cmd.Flags().Changed("yes") && cmd.Flags().Changed("tty") {
return errors.New("cannot use both --tty and --yes flags at the same time")
}

if cmd.Flags().Changed("yes") {
// Sets the value of the yesValue flag by using the yes flag.
yesValue, _ := cmd.Flags().GetBool("yes")
if yesValue {
// Sets to the default value false
err := cmd.Flags().Set("tty", "false")
if err != nil {
return err
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if --yes=false is explicitly specified?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting the value of --yes=false will not induce any effects and it will be neglected. we can just give a warning to user to prevent confusion.

}
return nil
}
rootCmd.AddGroup(&cobra.Group{ID: "basic", Title: "Basic Commands:"})
Expand Down
Loading