github.com/MichaelDarr/ahab@v0.0.0-20200528062404-c74c5106e605/cmd/prune.go (about)

     1  package cmd
     2  
     3  import (
     4  	"github.com/spf13/cobra"
     5  
     6  	"github.com/MichaelDarr/ahab/internal"
     7  	ahab "github.com/MichaelDarr/ahab/pkg"
     8  )
     9  
    10  // volumes is used as a flag by the prune command
    11  var volumes bool
    12  
    13  var pruneCmd = &cobra.Command{
    14  	Use:   "prune",
    15  	Short: "Remove unused Docker assets",
    16  	Long: `Remove unused Docker assets
    17  
    18  Docker Command:
    19    docker system prune -a [--volumes]`,
    20  	Run: func(cmd *cobra.Command, args []string) {
    21  		pruneArgs := []string{"system", "prune", "-a"}
    22  		if volumes {
    23  			pruneArgs = append(pruneArgs, "--volumes")
    24  		}
    25  		ahab.PrintErrFatal(internal.DockerCmd(&pruneArgs))
    26  	},
    27  }
    28  
    29  func init() {
    30  	pruneCmd.Flags().BoolVar(&volumes, "volumes", false, "Also prune docker volumes")
    31  	rootCmd.AddCommand(pruneCmd)
    32  }