Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit bea5a17

Browse files
committed
final tweaks
1 parent bd97f7c commit bea5a17

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

cmd/root.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var types diffTypes
4242
var noCache bool
4343

4444
var outputFile string
45+
var forceWrite bool
4546
var cacheDir string
4647
var LogLevel string
4748
var format string
@@ -179,9 +180,11 @@ func getWriter(outputFile string) (io.Writer, error) {
179180
// If the user specifies an output file, ensure exists
180181
if outputFile != "" {
181182

182-
// The file can't exist, we would overwrite it
183+
// Don't overwrite a file that exists, unless given --force
183184
if _, err := os.Stat(outputFile); !os.IsNotExist(err) {
184-
return os.Stdout, errors.Wrap(err, "file exists, will not overwrite")
185+
if !forceWrite {
186+
logrus.Error("file exist, will not overwrite.")
187+
}
185188
}
186189

187190
// Otherwise, output file is an io.writer
@@ -234,5 +237,6 @@ func addSharedFlags(cmd *cobra.Command) {
234237
cmd.Flags().BoolVarP(&util.SortSize, "order", "o", false, "Set this flag to sort any file/package results by descending size. Otherwise, they will be sorted by name.")
235238
cmd.Flags().BoolVarP(&noCache, "no-cache", "n", false, "Set this to force retrieval of image filesystem on each run.")
236239
cmd.Flags().StringVarP(&cacheDir, "cache-dir", "c", "", "cache directory base to create .container-diff (default is $HOME).")
237-
cmd.Flags().StringVarP(&outputFile, "output", "w", "", "output file to write to (default writes to STDOUT).")
240+
cmd.Flags().StringVarP(&outputFile, "output", "w", "", "output file to write to (default writes to the screen).")
241+
cmd.Flags().BoolVar(&forceWrite, "force", false, "force overwrite output file, if exists already.")
238242
}

0 commit comments

Comments
 (0)