Make --non-interactive a global flag
Right now, we only support --non-interactive in a few places (up, refresh, destroy, etc). Over time, we've added it to more (like new). And now, as we're working on better Docker support (pulumi/pulumi#1991), we want to support this more globally, so we can, for example, avoid popping up a web browser inside a Docker contain for logging in. So, this change makes --non-interactive a global flag. Because it is a persistent flag, it still works in the old positions, so this isn't a breaking change to existing commands that use it.
This commit is contained in:
parent
4640d12e08
commit
0e98091bd7
|
@ -40,7 +40,6 @@ func newDestroyCmd() *cobra.Command {
|
|||
var showConfig bool
|
||||
var showReplacementSteps bool
|
||||
var showSames bool
|
||||
var nonInteractive bool
|
||||
var skipPreview bool
|
||||
var yes bool
|
||||
|
||||
|
@ -58,7 +57,7 @@ func newDestroyCmd() *cobra.Command {
|
|||
"is generally irreversible and should be used with great care.",
|
||||
Args: cmdutil.NoArgs,
|
||||
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
|
||||
interactive := isInteractive(nonInteractive)
|
||||
interactive := isInteractive()
|
||||
if !interactive {
|
||||
yes = true // auto-approve changes, since we cannot prompt.
|
||||
}
|
||||
|
@ -130,8 +129,6 @@ func newDestroyCmd() *cobra.Command {
|
|||
cmd.PersistentFlags().BoolVar(
|
||||
&diffDisplay, "diff", false,
|
||||
"Display operation as a rich diff showing the overall change")
|
||||
cmd.PersistentFlags().BoolVar(
|
||||
&nonInteractive, "non-interactive", false, "Disable interactive mode")
|
||||
cmd.PersistentFlags().IntVarP(
|
||||
¶llel, "parallel", "p", defaultParallel,
|
||||
"Allow P resource operations to run in parallel at once (<=1 for no parallelism)")
|
||||
|
|
|
@ -57,7 +57,6 @@ func newNewCmd() *cobra.Command {
|
|||
var offline bool
|
||||
var generateOnly bool
|
||||
var dir string
|
||||
var nonInteractive bool
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "new [template]",
|
||||
|
@ -65,7 +64,7 @@ func newNewCmd() *cobra.Command {
|
|||
Short: "Create a new Pulumi project",
|
||||
Args: cmdutil.MaximumNArgs(1),
|
||||
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
|
||||
interactive := isInteractive(nonInteractive)
|
||||
interactive := isInteractive()
|
||||
if !interactive {
|
||||
yes = true // auto-approve changes, since we cannot prompt.
|
||||
}
|
||||
|
@ -335,8 +334,6 @@ func newNewCmd() *cobra.Command {
|
|||
cmd.PersistentFlags().StringVar(
|
||||
&dir, "dir", "",
|
||||
"The location to place the generated project; if not specified, the current directory is used")
|
||||
cmd.PersistentFlags().BoolVar(
|
||||
&nonInteractive, "non-interactive", false, "Disable interactive mode")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ func newPreviewCmd() *cobra.Command {
|
|||
// Flags for engine.UpdateOptions.
|
||||
var analyzers []string
|
||||
var diffDisplay bool
|
||||
var nonInteractive bool
|
||||
var parallel int
|
||||
var showConfig bool
|
||||
var showReplacementSteps bool
|
||||
|
@ -68,7 +67,7 @@ func newPreviewCmd() *cobra.Command {
|
|||
ShowConfig: showConfig,
|
||||
ShowReplacementSteps: showReplacementSteps,
|
||||
ShowSameResources: showSames,
|
||||
IsInteractive: isInteractive(nonInteractive),
|
||||
IsInteractive: isInteractive(),
|
||||
DiffDisplay: diffDisplay,
|
||||
Debug: debug,
|
||||
},
|
||||
|
@ -128,8 +127,6 @@ func newPreviewCmd() *cobra.Command {
|
|||
cmd.PersistentFlags().BoolVar(
|
||||
&diffDisplay, "diff", false,
|
||||
"Display operation as a rich diff showing the overall change")
|
||||
cmd.PersistentFlags().BoolVar(
|
||||
&nonInteractive, "non-interactive", false, "Disable interactive mode")
|
||||
cmd.PersistentFlags().IntVarP(
|
||||
¶llel, "parallel", "p", defaultParallel,
|
||||
"Allow P resource operations to run in parallel at once (<=1 for no parallelism)")
|
||||
|
|
|
@ -134,6 +134,8 @@ func NewPulumiCmd() *cobra.Command {
|
|||
"Flow log settings to child processes (like plugins)")
|
||||
cmd.PersistentFlags().BoolVar(&logToStderr, "logtostderr", false,
|
||||
"Log to stderr instead of to files")
|
||||
cmd.PersistentFlags().BoolVar(&nonInteractive, "non-interactive", false,
|
||||
"Disable interactive mode for all commands")
|
||||
cmd.PersistentFlags().StringVar(&tracing, "tracing", "",
|
||||
"Emit tracing to a Zipkin-compatible tracing endpoint")
|
||||
cmd.PersistentFlags().StringVar(&profiling, "profiling", "",
|
||||
|
|
|
@ -39,7 +39,6 @@ func newRefreshCmd() *cobra.Command {
|
|||
var showConfig bool
|
||||
var showReplacementSteps bool
|
||||
var showSames bool
|
||||
var nonInteractive bool
|
||||
var skipPreview bool
|
||||
var yes bool
|
||||
|
||||
|
@ -57,7 +56,7 @@ func newRefreshCmd() *cobra.Command {
|
|||
"`--cwd` flag to use a different directory.",
|
||||
Args: cmdutil.NoArgs,
|
||||
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
|
||||
interactive := isInteractive(nonInteractive)
|
||||
interactive := isInteractive()
|
||||
if !interactive {
|
||||
yes = true // auto-approve changes, since we cannot prompt.
|
||||
}
|
||||
|
@ -139,8 +138,6 @@ func newRefreshCmd() *cobra.Command {
|
|||
cmd.PersistentFlags().BoolVar(
|
||||
&diffDisplay, "diff", false,
|
||||
"Display operation as a rich diff showing the overall change")
|
||||
cmd.PersistentFlags().BoolVar(
|
||||
&nonInteractive, "non-interactive", false, "Disable interactive mode")
|
||||
cmd.PersistentFlags().IntVarP(
|
||||
¶llel, "parallel", "p", defaultParallel,
|
||||
"Allow P resource operations to run in parallel at once (<=1 for no parallelism)")
|
||||
|
|
|
@ -50,7 +50,6 @@ func newUpCmd() *cobra.Command {
|
|||
// Flags for engine.UpdateOptions.
|
||||
var analyzers []string
|
||||
var diffDisplay bool
|
||||
var nonInteractive bool
|
||||
var parallel int
|
||||
var refresh bool
|
||||
var showConfig bool
|
||||
|
@ -273,7 +272,7 @@ func newUpCmd() *cobra.Command {
|
|||
"`--cwd` flag to use a different directory.",
|
||||
Args: cmdutil.MaximumNArgs(1),
|
||||
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
|
||||
interactive := isInteractive(nonInteractive)
|
||||
interactive := isInteractive()
|
||||
if !interactive {
|
||||
yes = true // auto-approve changes, since we cannot prompt.
|
||||
}
|
||||
|
@ -325,8 +324,6 @@ func newUpCmd() *cobra.Command {
|
|||
cmd.PersistentFlags().BoolVar(
|
||||
&diffDisplay, "diff", false,
|
||||
"Display operation as a rich diff showing the overall change")
|
||||
cmd.PersistentFlags().BoolVar(
|
||||
&nonInteractive, "non-interactive", false, "Disable interactive mode")
|
||||
cmd.PersistentFlags().IntVarP(
|
||||
¶llel, "parallel", "p", defaultParallel,
|
||||
"Allow P resource operations to run in parallel at once (<=1 for no parallelism)")
|
||||
|
|
10
cmd/util.go
10
cmd/util.go
|
@ -578,9 +578,13 @@ func printJSON(v interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// isInteractive returns true if the environment and command line options indicate we should
|
||||
// do things interactively
|
||||
func isInteractive(nonInteractive bool) bool {
|
||||
// nonInteractive may be set to true in order to disable prompts. This is useful when running in a non-attended
|
||||
// scenario, such as in continuous integration, or when using the Pulumi CLI/SDK in a programmatic way.
|
||||
var nonInteractive bool
|
||||
|
||||
// isInteractive returns true if the environment and command line options indicate we should do things interactively.
|
||||
// It respects the nonInteractive flag as an override, but otherwise defaults by reading the terminal and CI settings.
|
||||
func isInteractive() bool {
|
||||
return !nonInteractive && terminal.IsTerminal(int(os.Stdout.Fd())) && !testutil.IsCI()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue