Skip to content

Commit

Permalink
cmd/shfmt: move --filename out of parser options
Browse files Browse the repository at this point in the history
The man page says:

    If any parser or printer flags are given to the tool,
    no EditorConfig formatting options will be used.

This clearly does not apply to --filename, which primarily exists
so that stdin inputs can still use EditorConfig filename matching.

While here, add a note about EditorConfig support to the help text,
which wasn't obvious unless the user went to read `man shfmt`.

Fixes #1079.
  • Loading branch information
mvdan committed Oct 19, 2024
1 parent f3c9101 commit 9482bff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions cmd/shfmt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ directory, all shell scripts found under that directory will be used.
-s, --simplify simplify the code
-mn, --minify minify the code to reduce its size (implies -s)
--apply-ignore always apply EditorConfig ignore rules
--filename str provide a name for the standard input file
Parser options:
-ln, --language-dialect str bash/posix/mksh/bats, default "auto"
-p, --posix shorthand for -ln=posix
--filename str provide a name for the standard input file
Printer options:
Expand All @@ -158,7 +158,9 @@ Utilities:
--to-json print syntax tree to stdout as a typed JSON
--from-json read syntax tree from stdin as a typed JSON
For more information, see 'man shfmt' and https://github.com/mvdan/sh.
Formatting options can also be read from EditorConfig files; see 'man shfmt'
for a detailed description of the tool's behavior.
For more information and to report bugs, see https://github.com/mvdan/sh.
`)
}
flag.Parse()
Expand Down
12 changes: 6 additions & 6 deletions cmd/shfmt/shfmt.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ predictable. Some aspects of the format can be configured via printer flags.
Should be useful to any tools or editors which format stdin or a single file.
When printing results to stdout, an ignored file results in no output at all.

*--filename* str
Provide a name for the standard input file.

Use of this flag is necessary for EditorConfig support to work with stdin,
since EditorConfig files are found relative to the location of a script.

## Parser flags

*-ln*, *--language-dialect* <str>
Expand All @@ -70,12 +76,6 @@ predictable. Some aspects of the format can be configured via printer flags.
*-p*, *--posix*
Shorthand for *-ln=posix*.

*--filename* str
Provide a name for the standard input file.

Use of this flag is necessary for EditorConfig support to work with stdin,
since EditorConfig files are found relative to the location of a script.

## Printer flags

*-i*, *--indent* <uint>
Expand Down

0 comments on commit 9482bff

Please sign in to comment.