Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use interactive flag rather than check isatty #39

Closed
wants to merge 1 commit into from

Conversation

alexeagle
Copy link
Member

No description provided.


// ### Viper
if cfgFile != "" {
if pkgroot.CfgFile != "" {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note, this is also broken for the same reason, flag parsing hasn't happened yet. will need some refactoring

@alexeagle alexeagle marked this pull request as ready for review October 1, 2021 14:00
Copy link
Contributor

@f0rmiga f0rmiga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike this approach as it starts to add mutability to the parameters abusing the pointers.
Starts to make it harder to reason the logic. Since the flag parsing only happens after the command gets executed, I think the fix is as simple as:

diff --git a/cmd/aspect/clean/clean.go b/cmd/aspect/clean/clean.go
index ea187e1..18a9f70 100644
--- a/cmd/aspect/clean/clean.go
+++ b/cmd/aspect/clean/clean.go
@@ -7,9 +7,6 @@ Not licensed for re-use.
 package clean
 
 import (
-	"os"
-
-	"github.com/mattn/go-isatty"
 	"github.com/spf13/cobra"
 
 	"aspect.build/cli/pkg/aspect/clean"
@@ -17,8 +14,8 @@ import (
 
 // NewDefaultCleanCmd creates a new clean cobra command.
 func NewDefaultCleanCmd() *cobra.Command {
-	isInteractive := isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd())
-	b := clean.NewDefault(isInteractive)
+	var expunge bool
+	var expungeAsync bool
 
 	cmd := &cobra.Command{
 		Use:   "clean",
@@ -53,16 +50,23 @@ Workaround inconistent state:
 	Such problems are fixable and these bugs are a high priority.
 	If you ever find an incorrect incremental build, please file a bug report,
 	and only use clean as a temporary workaround.`,
-		RunE: b.Run,
+		RunE: func(cmd *cobra.Command, args []string) error {
+			interactive, err := cmd.PersistentFlags().GetBool("interactive")
+			if err != nil {
+				return err
+			}
+			b := clean.NewDefault(interactive, expunge, expungeAsync)
+			return b.Run(cmd, args)
+		},
 	}
 
-	cmd.PersistentFlags().BoolVarP(&b.Expunge, "expunge", "", false, `Remove the entire output_base tree.
+	cmd.PersistentFlags().BoolVarP(&expunge, "expunge", "", false, `Remove the entire output_base tree.
 This removes all build output, external repositories,
 and temp files created by Bazel.
 It also stops the Bazel server after the clean,
 equivalent to the shutdown command.`)
 
-	cmd.PersistentFlags().BoolVarP(&b.ExpungeAsync, "expunge_async", "", false, `Expunge in the background.
+	cmd.PersistentFlags().BoolVarP(&expungeAsync, "expunge_async", "", false, `Expunge in the background.
 It is safe to invoke a Bazel command in the same
 workspace while the asynchronous expunge continues to run.
 Note, however, that this may introduce IO contention.`)

@f0rmiga
Copy link
Contributor

f0rmiga commented Nov 15, 2021

Closing this in favour of the approach in #64.

@f0rmiga f0rmiga closed this Nov 15, 2021
@f0rmiga f0rmiga deleted the fix_interactive branch November 15, 2021 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants