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

feat: clean command prompts for use case #35

Merged
merged 2 commits into from
Sep 30, 2021
Merged

feat: clean command prompts for use case #35

merged 2 commits into from
Sep 30, 2021

Conversation

alexeagle
Copy link
Member

No description provided.

// then ask
// do you want to see this wizard again next time?
// and if not, record in the cache file to inhibit next time
skip := viper.GetBool(skipPromptKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a singleton really hard to mock for testing. I wonder if we should wrap this so we have better control.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

// do you want to see this wizard again next time?
// and if not, record in the cache file to inhibit next time
skip := viper.GetBool(skipPromptKey)
interactive := isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd())
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be a field in the Clean struct that gets populated when we construct the command. Again, makes it easier to test, since we should not access the real IO streams inside the pkg tree.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah we should even have an assertion on the dep graph like "pkg should not import os" or something

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm I never thought about doing something like this. We can try. Maybe a bit hard, but sounds correct.


case 0:
// Allow user to opt-out of our fancy "clean" command and just behave like bazel
fmt.Println("You can skip this prompt to make 'aspect clean' behave the same as 'bazel clean'")
Copy link
Contributor

Choose a reason for hiding this comment

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

This and the print statements below should be in the format of:

fmt.Fprintf(c.Streams.Stdout, "foo\n")

Copy link
Member Author

Choose a reason for hiding this comment

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

done, and added some assertions on the stdout

},
}

i, _, err := choose.Run()
Copy link
Contributor

Choose a reason for hiding this comment

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

The idea for testing these proptui calls is to make the promptui.Selects an interface. As simple as:

type PromptSelectRunner interface {
  Run() (int, string, error)
}

The default constructor can then receive the prompui.Select struct initialization and on tests we just create mocks out of the interface.

Since we are passing the IO streams as interfaces, these can also receive e.g. a bytes.Buffer instead of os.Stdout so we can capture the output and make assertions on the selections.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah that works pretty well

@alexeagle alexeagle force-pushed the promptui branch 3 times, most recently from ae9ec31 to cffe056 Compare September 30, 2021 05:50
pkg/aspect/clean/clean.go Outdated Show resolved Hide resolved
pkg/aspect/clean/clean.go Outdated Show resolved Hide resolved
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.

Awesome! Much better!

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