Skip to content

Commit 377c1f7

Browse files
authored
Merge pull request #3342 from suryaaprakassh/flagFix
feat: added a default `--yes` flag to set the tty
2 parents 3a45903 + 1db3315 commit 377c1f7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

cmd/limactl/main.go

+17
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func newApp() *cobra.Command {
7878
rootCmd.PersistentFlags().Bool("debug", false, "debug mode")
7979
// TODO: "survey" does not support using cygwin terminal on windows yet
8080
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.")
81+
rootCmd.PersistentFlags().BoolP("yes", "y", false, "Alias of --tty=false")
8182
rootCmd.PersistentPreRunE = func(cmd *cobra.Command, _ []string) error {
8283
l, _ := cmd.Flags().GetString("log-level")
8384
if l != "" {
@@ -139,6 +140,22 @@ func newApp() *cobra.Command {
139140
if nfs {
140141
return errors.New("must not run on NFS dir")
141142
}
143+
144+
if cmd.Flags().Changed("yes") && cmd.Flags().Changed("tty") {
145+
return errors.New("cannot use both --tty and --yes flags at the same time")
146+
}
147+
148+
if cmd.Flags().Changed("yes") {
149+
// Sets the value of the yesValue flag by using the yes flag.
150+
yesValue, _ := cmd.Flags().GetBool("yes")
151+
if yesValue {
152+
// Sets to the default value false
153+
err := cmd.Flags().Set("tty", "false")
154+
if err != nil {
155+
return err
156+
}
157+
}
158+
}
142159
return nil
143160
}
144161
rootCmd.AddGroup(&cobra.Group{ID: "basic", Title: "Basic Commands:"})

0 commit comments

Comments
 (0)