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

Commit 410f975

Browse files
committed
add -dry-run
1 parent 96a7c07 commit 410f975

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ func printVersion() {
3636

3737
func main() {
3838
configFile := ""
39+
dryRun := false
3940
showVersion := false
4041
stdout := false
4142

4243
flag.StringVar(&configFile, "config", configFile, "Path to the config file (mandatory).")
4344
flag.BoolVar(&stdout, "stdout", showVersion, "Print output to stdout instead of updating the source file(s).")
45+
flag.BoolVar(&dryRun, "dry-run", dryRun, "Do not update files.")
4446
flag.BoolVar(&showVersion, "version", stdout, "Show version and exit.")
4547
flag.Parse()
4648

@@ -50,7 +52,7 @@ func main() {
5052
}
5153

5254
if flag.NArg() == 0 {
53-
log.Fatal("Usage: gimps [-stdout] [-config=(autodetect)] FILE_OR_DIRECTORY[, ...]")
55+
log.Fatal("Usage: gimps [-stdout] [-dry-run] [-config=(autodetect)] FILE_OR_DIRECTORY[, ...]")
5456
}
5557

5658
inputs, err := cleanupArgs(flag.Args())
@@ -113,8 +115,10 @@ func main() {
113115

114116
log.Printf("Fixing %s", relPath)
115117

116-
if err := ioutil.WriteFile(filename, formattedOutput, 0644); err != nil {
117-
log.Fatalf("Failed to write fixed result to file %q: %v", filename, err)
118+
if !dryRun {
119+
if err := ioutil.WriteFile(filename, formattedOutput, 0644); err != nil {
120+
log.Fatalf("Failed to write fixed result to file %q: %v", filename, err)
121+
}
118122
}
119123
}
120124
}

0 commit comments

Comments
 (0)