Skip to content

Commit

Permalink
add deprecated flags once again
Browse files Browse the repository at this point in the history
This way, users calling -s or -r get a helpful message.
The use of -s can still let the tool work, for now.

Fixes #174.
  • Loading branch information
Oiyoo authored Dec 12, 2021
1 parent 872763c commit cf88391
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 10 deletions.
42 changes: 32 additions & 10 deletions gofmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,22 @@ import (

var (
// main operation modes
list = flag.Bool("l", false, "list files whose formatting differs from gofumpt's")
write = flag.Bool("w", false, "write result to (source) file instead of stdout")
doDiff = flag.Bool("d", false, "display diffs instead of rewriting files")
allErrors = flag.Bool("e", false, "report all errors (not just the first 10 on different lines)")
list = flag.Bool("l", false, "")
write = flag.Bool("w", false, "")
doDiff = flag.Bool("d", false, "")
allErrors = flag.Bool("e", false, "")

// debugging
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to this file")
cpuprofile = flag.String("cpuprofile", "", "")

// gofumpt's own flags
langVersion = flag.String("lang", "", "target Go version in the form 1.X (default from go.mod)")
extraRules = flag.Bool("extra", false, "enable extra rules which should be vetted by a human")
showVersion = flag.Bool("version", false, "show version and exit")
langVersion = flag.String("lang", "", "")
extraRules = flag.Bool("extra", false, "")
showVersion = flag.Bool("version", false, "")

// DEPRECATED
rewriteRule = flag.String("r", "", "")
simplifyAST = flag.Bool("s", false, "")
)

// Keep these in sync with go/format/format.go.
Expand Down Expand Up @@ -71,8 +75,18 @@ func report(err error) {
}

func usage() {
fmt.Fprintf(os.Stderr, "usage: gofumpt [flags] [path ...]\n")
flag.PrintDefaults()
fmt.Fprintf(os.Stderr, `usage: gofumpt [flags] [path ...]
-version show version and exit
-d display diffs instead of rewriting files
-e report all errors (not just the first 10 on different lines)
-l list files whose formatting differs from gofumpt's
-w write result to (source) file instead of stdout
-extra enable extra rules which should be vetted by a human
-cpuprofile str write cpu profile to this file
-lang str target Go version in the form 1.X (default from go.mod)
`)
}

func initParserMode() {
Expand Down Expand Up @@ -204,6 +218,14 @@ func gofumptMain() {
flag.Usage = usage
flag.Parse()

if *simplifyAST {
fmt.Fprintf(os.Stderr, "warning: -s is deprecated as it is always enabled\n")
}
if *rewriteRule != "" {
fmt.Fprintf(os.Stderr, `the rewrite flag is no longer available; use "gofmt -r" instead`+"\n")
os.Exit(2)
}

// Print the gofumpt version if the user asks for it.
if *showVersion {
version.Print()
Expand Down
26 changes: 26 additions & 0 deletions testdata/scripts/deprecated-flags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cp foo.orig.go foo.go
! gofumpt -w -r foo foo.go
stderr 'the rewrite flag is no longer available; use "gofmt -r" instead\n'
cmp foo.orig.go foo.go

gofumpt -w -s foo.go
stderr 'warning: -s is deprecated as it is always enabled\n'
cmp foo.go foo.go.golden

gofumpt -d foo.go.golden
! stdout .

-- foo.orig.go --
package p

func f() {

println("foo")

}
-- foo.go.golden --
package p

func f() {
println("foo")
}

0 comments on commit cf88391

Please sign in to comment.