From 410f975a489fc99f1c8035dd36e3b05128ad61b7 Mon Sep 17 00:00:00 2001 From: Christoph Mewes Date: Thu, 6 May 2021 00:33:19 +0200 Subject: [PATCH] add -dry-run --- main.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index e366234..dfc6860 100644 --- a/main.go +++ b/main.go @@ -36,11 +36,13 @@ func printVersion() { func main() { configFile := "" + dryRun := false showVersion := false stdout := false flag.StringVar(&configFile, "config", configFile, "Path to the config file (mandatory).") flag.BoolVar(&stdout, "stdout", showVersion, "Print output to stdout instead of updating the source file(s).") + flag.BoolVar(&dryRun, "dry-run", dryRun, "Do not update files.") flag.BoolVar(&showVersion, "version", stdout, "Show version and exit.") flag.Parse() @@ -50,7 +52,7 @@ func main() { } if flag.NArg() == 0 { - log.Fatal("Usage: gimps [-stdout] [-config=(autodetect)] FILE_OR_DIRECTORY[, ...]") + log.Fatal("Usage: gimps [-stdout] [-dry-run] [-config=(autodetect)] FILE_OR_DIRECTORY[, ...]") } inputs, err := cleanupArgs(flag.Args()) @@ -113,8 +115,10 @@ func main() { log.Printf("Fixing %s", relPath) - if err := ioutil.WriteFile(filename, formattedOutput, 0644); err != nil { - log.Fatalf("Failed to write fixed result to file %q: %v", filename, err) + if !dryRun { + if err := ioutil.WriteFile(filename, formattedOutput, 0644); err != nil { + log.Fatalf("Failed to write fixed result to file %q: %v", filename, err) + } } } }