// license that can be found in the LICENSE file.
/*
-
Gofmt formats Go programs.
Without an explicit path, it processes the standard input. Given a file,
The flags are:
-l
- just list files whose formatting differs from gofmt's; generate no other output
- unless -w is also set.
+ just list files whose formatting differs from gofmt's;
+ generate no other output unless -w is also set.
-r rule
apply the rewrite rule to the source before reformatting.
-s
try to simplify code (after applying the rewrite rule, if any).
-w
if set, overwrite each input file with its output.
+ -comments=true
+ print comments; if false, all comments are elided from the output.
-spaces
align with spaces instead of tabs.
-tabindent
-tabwidth=8
tab width in spaces.
-Debugging flags:
-
- -trace
- print parse trace.
- -ast
- print AST (before rewrites).
- -comments=true
- print comments; if false, all comments are elided from the output.
-
The rewrite rule specified with the -r flag must be a string of the form:
pattern -> replacement
rewriteRule = flag.String("r", "", "rewrite rule (e.g., 'α[β:len(α)] -> α[β:]')")
simplifyAST = flag.Bool("s", false, "simplify code")
- // debugging support
- comments = flag.Bool("comments", true, "print comments")
- trace = flag.Bool("trace", false, "print parse trace")
- printAST = flag.Bool("ast", false, "print AST (before rewrites)")
-
// layout control
+ comments = flag.Bool("comments", true, "print comments")
tabWidth = flag.Int("tabwidth", 8, "tab width")
tabIndent = flag.Bool("tabindent", true, "indent with tabs independent of -spaces")
useSpaces = flag.Bool("spaces", true, "align with spaces instead of tabs")
if *comments {
parserMode |= parser.ParseComments
}
- if *trace {
- parserMode |= parser.Trace
- }
}
return err
}
- if *printAST {
- ast.Print(file)
- }
-
if rewrite != nil {
file = rewrite(file)
}