-
Notifications
You must be signed in to change notification settings - Fork 20
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
Conversation
77aea22
to
7a267c4
Compare
|
||
// ### Viper | ||
if cfgFile != "" { | ||
if pkgroot.CfgFile != "" { |
There was a problem hiding this comment.
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
7a267c4
to
0eb3384
Compare
There was a problem hiding this 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.`)
Closing this in favour of the approach in #64. |
No description provided.