Skip to content

Commit a39c9ab

Browse files
feat: added a default --yes flag to set the tty
Signed-off-by: Surya Prakash <[email protected]> - created a new boolean flag `--yes' Signed-off-by: Surya Prakash <[email protected]> fix: required changes Signed-off-by: Surya Prakash <[email protected]> - added intutive help message for the `--yes' flag - added a check with `cmd.Flags().Changed()` - changed the variable name from `ttyValue` to `yesValue` for better understanding feat: added a check usage of --yes && --tty Signed-off-by: Surya Prakash <[email protected]> fix: removed space from deprecated.md
1 parent d82d125 commit a39c9ab

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
@@ -68,6 +68,7 @@ func newApp() *cobra.Command {
6868
rootCmd.PersistentFlags().Bool("debug", false, "debug mode")
6969
// TODO: "survey" does not support using cygwin terminal on windows yet
7070
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.")
71+
rootCmd.PersistentFlags().BoolP("yes", "y", isatty.IsTerminal(os.Stdout.Fd()), "Alias of --tty=false")
7172
rootCmd.PersistentPreRunE = func(cmd *cobra.Command, _ []string) error {
7273
l, _ := cmd.Flags().GetString("log-level")
7374
if l != "" {
@@ -129,6 +130,22 @@ func newApp() *cobra.Command {
129130
if nfs {
130131
return errors.New("must not run on NFS dir")
131132
}
133+
134+
if cmd.Flags().Changed("yes") && cmd.Flags().Changed("tty") {
135+
return errors.New("cannot use both --tty and --yes flags at the same time")
136+
}
137+
138+
if cmd.Flags().Changed("yes") {
139+
// Sets the value of the yesValue flag by using the yes flag.
140+
yesValue, _ := cmd.Flags().GetBool("yes")
141+
if yesValue {
142+
// Sets to the default value false
143+
err := cmd.Flags().Set("tty", "false")
144+
if err != nil {
145+
return err
146+
}
147+
}
148+
}
132149
return nil
133150
}
134151
rootCmd.AddGroup(&cobra.Group{ID: "basic", Title: "Basic Commands:"})

0 commit comments

Comments
 (0)