diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/analyze.go | 7 | ||||
-rw-r--r-- | cmd/build.go | 1 | ||||
-rw-r--r-- | cmd/root.go | 11 |
3 files changed, 8 insertions, 11 deletions
diff --git a/cmd/analyze.go b/cmd/analyze.go index 6ac51f6..d06c0d4 100644 --- a/cmd/analyze.go +++ b/cmd/analyze.go @@ -2,17 +2,18 @@ package cmd import ( "fmt" - "os" "github.com/fatih/color" "github.com/spf13/cobra" "github.com/wagoodman/dive/image" "github.com/wagoodman/dive/ui" + "github.com/wagoodman/dive/utils" ) // analyze takes a docker image tag, digest, or id and displayes the // image analysis to the screen func analyze(cmd *cobra.Command, args []string) { + defer utils.Cleanup() if len(args) == 0 { printVersionFlag, err := cmd.PersistentFlags().GetBool("version") if err == nil && printVersionFlag { @@ -22,14 +23,14 @@ func analyze(cmd *cobra.Command, args []string) { fmt.Println("No image argument given") cmd.Help() - os.Exit(1) + utils.Exit(1) } userImage := args[0] if userImage == "" { fmt.Println("No image argument given") cmd.Help() - os.Exit(1) + utils.Exit(1) } color.New(color.Bold).Println("Analyzing Image") manifest, refTrees, efficiency, inefficiencies := image.InitializeData(userImage) diff --git a/cmd/build.go b/cmd/build.go index 309d1ee..81b6069 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -24,6 +24,7 @@ func init() { // doBuild implements the steps taken for the build command func doBuild(cmd *cobra.Command, args []string) { + defer utils.Cleanup() iidfile, err := ioutil.TempFile("/tmp", "dive.*.iid") if err != nil { log.Fatal(err) diff --git a/cmd/root.go b/cmd/root.go index 321682f..6a7ac17 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "github.com/wagoodman/dive/utils" "os" "github.com/k0kubun/go-ansi" @@ -9,7 +10,6 @@ import ( log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/tebeka/atexit" ) var cfgFile string @@ -28,17 +28,12 @@ the amount of wasted space and identifies the offending files from the image.`, func Execute() { if err := rootCmd.Execute(); err != nil { fmt.Println(err) - os.Exit(1) + utils.Exit(1) } } -func exitHandler() { - ansi.CursorShow() -} - func init() { ansi.CursorHide() - atexit.Register(exitHandler) cobra.OnInitialize(initConfig) cobra.OnInitialize(initLogging) @@ -59,7 +54,7 @@ func initConfig() { home, err := homedir.Dir() if err != nil { fmt.Println(err) - os.Exit(1) + utils.Exit(1) } // Search config in home directory with name ".dive" (without extension). |