-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: avoid asking env variables in non-interactive mode
We use a heuristics to determine if the command is called interactively or not: IsInteractive in util.go. Currently, we assume that a command is not interactive if more than 2 flags were set.
- Loading branch information
Showing
3 changed files
with
23 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
package cmdutil | ||
|
||
import "github.com/spf13/cobra" | ||
|
||
func CommandName(name, fullParentName string) string { | ||
return fullParentName + " " + name | ||
} | ||
|
||
// FlagValueIfSet retrieves the value of the specified flag if it is set for the given command | ||
func FlagValueIfSet(cmd *cobra.Command, flagName string) string { | ||
flag, _ := cmd.Flags().GetString(flagName) | ||
return flag | ||
} | ||
|
||
func IsInteractive(cmd *cobra.Command) bool { | ||
return cmd.Flags().NFlag() <= 2 // heuristics to determine whether we're running in interactive mode | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters