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

Fixed prune with a confirmation, a force, and removed the spinner #145

Merged
merged 4 commits into from
Feb 28, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions commands/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ func (cmd *Prune) Commands() []cli.Command {

// Run executes the `rig prune` command
func (cmd *Prune) Run(c *cli.Context) error {
cmd.out.Spin("Cleaning up unused Docker resources...")
/* #nosec */
if exitCode := util.PassthruCommand(exec.Command("docker", "system", "prune", "--all", "--volumes")); exitCode != 0 {
return cmd.Failure("Failure pruning Docker resources.", "COMMAND-ERROR", 13)

if util.AskYesNo("Are you sure you want to remove all unused containers, networks, images, caches, and volumes?") {
/* #nosec */
if exitCode := util.PassthruCommand(exec.Command("docker", "system", "prune", "--all", "--volumes", "--force")); exitCode != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we start a spinner inside here in case the command might take awhile to run?

Copy link
Member

Choose a reason for hiding this comment

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

If we kept the spinner I think it would still go above this conditional, just inside the AskYesNo block. I'm in favor of it since it can definitely take a while to run and there is no real indication that things are happening. If we leave it off then perhaps just mention in the prompt that this may take a while to execute.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, the actual prune command has a lot of output as it is cleaning up things, so the spinner will likely get in the way. I'll test it out to see.

I'm thinking no spinner, but I'll see what it looks like.

Copy link
Member

Choose a reason for hiding this comment

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

I just did a test and I didn't see any output (so if some is being generated then the spinner is gobbling it). Interestingly, I didn't see the success message until I hit "Enter" while the spinner was running so I thought things might have actually gotten stuck. Interested to see if you get the same experience (and if so then perhaps the note that it'll will take a bit is a better course).

return cmd.Failure("Failure pruning Docker resources.", "COMMAND-ERROR", 13)
}
cmd.out.Info("Unused Docker images, containers, volumes, and networks cleaned up.")
} else {
cmd.out.Info("Cleanup aborted.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be cmd.out.Warn()? (This is particularly useful if we run a spinner to differentiate no-action from successful action.)

}
cmd.out.Info("Unused Docker images, containers, volumes, and networks cleaned up.")

return cmd.Success("")
}