Browse Source

Default output to stdout if input is stdin

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

12
src/main.jl

@ -44,7 +44,7 @@ function print_help() @@ -44,7 +44,7 @@ function print_help()
<path>...
Input path(s) (files and/or directories) to process. For directories,
all files (recursively) with the '*.jl' suffix are used as input files.
If path is `-` input is read from stdin.
If path is `-` input is read from stdin and output written to stdout.
-c, --check
Do not write output and exit with a non-zero code if the input is not
@ -146,7 +146,9 @@ function main(argv) @@ -146,7 +146,9 @@ function main(argv)
end
# one of --check, --diff, --inplace, or --output must be specified
if !(inplace || check || diff || outputfile !== nothing)
stdio_mode = length(inputfiles) == 1 && inputfiles[1] == "-" &&
(outputfile === nothing || outputfile == "-")
if !(inplace || check || diff || stdio_mode)
return panic(
"at least one of options `-c, --check`, `-d, --diff`, `-i, --inplace`, " *
"or `-o, --output` must be specified",
@ -230,10 +232,10 @@ function main(argv) @@ -230,10 +232,10 @@ function main(argv)
output = devnull
else
@assert length(inputfiles) == 1
if outputfile === nothing
return panic("no output file specified")
elseif outputfile == "-"
if stdio_mode
output = stdout
elseif outputfile === nothing
return panic("no output file specified")
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")
else

Loading…
Cancel
Save