diff --git a/commands/completion.go b/commands/completion.go index 4fc69c8..8ab8ae2 100644 --- a/commands/completion.go +++ b/commands/completion.go @@ -29,13 +29,14 @@ func newCompletionCommand(cnf *config.Config) *cobra.Command { } var b bytes.Buffer c := &legacy.CLIWrapper{ - Config: cnf, - Version: version, - CustomPharPath: viper.GetString("phar-path"), - Debug: viper.GetBool("debug"), - Stdout: &b, - Stderr: cmd.ErrOrStderr(), - Stdin: cmd.InOrStdin(), + Config: cnf, + Version: version, + CustomPharPath: viper.GetString("phar-path"), + Debug: viper.GetBool("debug"), + DisableInteraction: viper.GetBool("no-interaction"), + Stdout: &b, + Stderr: cmd.ErrOrStderr(), + Stdin: cmd.InOrStdin(), } if err := c.Init(); err != nil { diff --git a/commands/list.go b/commands/list.go index f071928..b3446ff 100644 --- a/commands/list.go +++ b/commands/list.go @@ -24,13 +24,14 @@ func newListCommand(cnf *config.Config) *cobra.Command { Run: func(cmd *cobra.Command, args []string) { var b bytes.Buffer c := &legacy.CLIWrapper{ - Config: cnf, - Version: version, - CustomPharPath: viper.GetString("phar-path"), - Debug: viper.GetBool("debug"), - Stdout: &b, - Stderr: cmd.ErrOrStderr(), - Stdin: cmd.InOrStdin(), + Config: cnf, + Version: version, + CustomPharPath: viper.GetString("phar-path"), + Debug: viper.GetBool("debug"), + DisableInteraction: viper.GetBool("no-interaction"), + Stdout: &b, + Stderr: cmd.ErrOrStderr(), + Stdin: cmd.InOrStdin(), } if err := c.Init(); err != nil { debugLog("%s\n", color.RedString(err.Error())) diff --git a/commands/root.go b/commands/root.go index a85eee0..f6e2c25 100644 --- a/commands/root.go +++ b/commands/root.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "io" "log" "os" "os/exec" @@ -52,6 +53,10 @@ func newRootCommand(cnf *config.Config, assets *vendorization.VendorAssets) *cob SilenceUsage: true, SilenceErrors: true, PersistentPreRun: func(cmd *cobra.Command, _ []string) { + if viper.GetBool("quiet") && !viper.GetBool("debug") && !viper.GetBool("verbose") { + viper.Set("no-interaction", true) + cmd.SetErr(io.Discard) + } if viper.GetBool("version") { versionCommand.Run(cmd, []string{}) os.Exit(0) @@ -65,13 +70,14 @@ func newRootCommand(cnf *config.Config, assets *vendorization.VendorAssets) *cob }, Run: func(cmd *cobra.Command, _ []string) { c := &legacy.CLIWrapper{ - Config: cnf, - Version: version, - CustomPharPath: viper.GetString("phar-path"), - Debug: viper.GetBool("debug"), - Stdout: cmd.OutOrStdout(), - Stderr: cmd.ErrOrStderr(), - Stdin: cmd.InOrStdin(), + Config: cnf, + Version: version, + CustomPharPath: viper.GetString("phar-path"), + Debug: viper.GetBool("debug"), + DisableInteraction: viper.GetBool("no-interaction"), + Stdout: cmd.OutOrStdout(), + Stderr: cmd.ErrOrStderr(), + Stdin: cmd.InOrStdin(), } if err := c.Init(); err != nil { debugLog("%s\n", color.RedString(err.Error())) @@ -118,6 +124,10 @@ func newRootCommand(cnf *config.Config, assets *vendorization.VendorAssets) *cob cmd.PersistentFlags().Bool("debug", false, "Enable debug logging") cmd.PersistentFlags().Bool("no-interaction", false, "Enable non-interactive mode") cmd.PersistentFlags().BoolP("verbose", "v", false, "Enable verbose output") + cmd.PersistentFlags().BoolP("quiet", "q", false, + "Suppress any messages and errors (stderr), while continuing to display necessary output (stdout)."+ + " This implies --no-interaction. Ignored in verbose mode.", + ) projectInitCmd := commands.NewPlatformifyCmd(assets) projectInitCmd.SetHelpFunc(func(_ *cobra.Command, _ []string) { diff --git a/internal/legacy/legacy.go b/internal/legacy/legacy.go index ac6a474..97fadb4 100644 --- a/internal/legacy/legacy.go +++ b/internal/legacy/legacy.go @@ -69,13 +69,14 @@ func fileChanged(filename string, content []byte) (bool, error) { // CLIWrapper wraps the legacy CLI type CLIWrapper struct { - Stdout io.Writer - Stderr io.Writer - Stdin io.Reader - Config *config.Config - Version string - CustomPharPath string - Debug bool + Stdout io.Writer + Stderr io.Writer + Stdin io.Reader + Config *config.Config + Version string + CustomPharPath string + Debug bool + DisableInteraction bool } func (c *CLIWrapper) cacheDir() string { @@ -170,6 +171,9 @@ func (c *CLIWrapper) Exec(ctx context.Context, args ...string) error { if c.Debug { cmd.Env = append(cmd.Env, envPrefix+"CLI_DEBUG=1") } + if c.DisableInteraction { + cmd.Env = append(cmd.Env, envPrefix+"NO_INTERACTION=1") + } cmd.Env = append(cmd.Env, fmt.Sprintf( "%sUSER_AGENT={APP_NAME_DASH}/%s ({UNAME_S}; {UNAME_R}; PHP %s; WRAPPER %s)", envPrefix,