Browse Source

Require explicit - for stdin/stdout usage.

pull/19/head
Fredrik Ekre 1 year ago
parent
commit
d70a2fdef1
No known key found for this signature in database
GPG Key ID: DE82E6D5E364C0A2
  1. 14
      src/main.jl

14
src/main.jl

@ -44,7 +44,7 @@ function print_help()
<path>... <path>...
Input path(s) (files and/or directories) to process. For directories, Input path(s) (files and/or directories) to process. For directories,
all files (recursively) with the '*.jl' suffix are used as input files. all files (recursively) with the '*.jl' suffix are used as input files.
If no path is given, or if path is `-`, input is read from stdin. If path is `-` input is read from stdin.
-c, --check -c, --check
Do not write output and exit with a non-zero code if the input is not Do not write output and exit with a non-zero code if the input is not
@ -62,9 +62,9 @@ function print_help()
paths. paths.
-o, --output <file> -o, --output <file>
Output file to write formatted code to. If no output file is given, or Output file to write formatted code to. If the specified file is `-`
if the specified file is `-`, output is written to stdout. This option output is written to stdout. This option can not be used together with
can not be used together with multiple input paths. multiple input paths.
""") """)
return return
end end
@ -150,7 +150,7 @@ function main(argv)
# stdin is the default input # stdin is the default input
if isempty(inputfiles) if isempty(inputfiles)
push!(inputfiles, "-") return panic("no input files or directories specified")
end end
# multiple files require --inplace or --check and no --output # multiple files require --inplace or --check and no --output
@ -220,7 +220,9 @@ function main(argv)
output = devnull output = devnull
else else
@assert length(inputfiles) == 1 @assert length(inputfiles) == 1
if outputfile === nothing || outputfile == "-" if outputfile === nothing
return panic("no output file specified")
elseif outputfile == "-"
output = stdout output = stdout
elseif isfile(outputfile) && input_is_file && samefile(outputfile, inputfile) elseif isfile(outputfile) && input_is_file && samefile(outputfile, inputfile)
return panic("can not use same file for input and output, use `-i` to modify a file in place") return panic("can not use same file for input and output, use `-i` to modify a file in place")

Loading…
Cancel
Save