Browse Source

Add --verbose command line argument

This patch implements a new command line argument `--verbose` which
enables verbose ouutput. Runic is now silent by default so `--verbose`
re-enables the verbose file printing from previous releases.
pull/121/head
Fredrik Ekre 12 months ago
parent
commit
9ae14105c3
No known key found for this signature in database
GPG Key ID: DE82E6D5E364C0A2
  1. 7
      CHANGELOG.md
  2. 6
      README.md
  3. 7
      src/main.jl
  4. 73
      test/maintests.jl

7
CHANGELOG.md

@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Added
- New command line argument `--verbose` which enables verbose output ([#121]).
### Changed
- Runic is now silent by default. Use `--verbose` to enable the verbose file progress
printing from previous releases ([#121]).
## [v1.2.0] - 2024-12-09 ## [v1.2.0] - 2024-12-09
### Added ### Added
- New command line option `--lines=a:b` for limiting formatting to lines `a` to `b`. - New command line option `--lines=a:b` for limiting formatting to lines `a` to `b`.

6
README.md

@ -111,6 +111,12 @@ OPTIONS
-o <file>, --output=<file> -o <file>, --output=<file>
File to write formatted output to. If no output is given, or if the file File to write formatted output to. If no output is given, or if the file
is `-`, output is written to stdout. is `-`, output is written to stdout.
-v, --verbose
Enable verbose output.
--version
Print Runic and julia version information.
``` ```
In addition to the CLI there is also the two function `Runic.format_file` and In addition to the CLI there is also the two function `Runic.format_file` and

7
src/main.jl

@ -143,6 +143,9 @@ function print_help()
File to write formatted output to. If no output is given, or if the file File to write formatted output to. If no output is given, or if the file
is `-`, output is written to stdout. is `-`, output is written to stdout.
-v, --verbose
Enable verbose output.
--version --version
Print Runic and julia version information. Print Runic and julia version information.
""" """
@ -355,8 +358,8 @@ function main(argv)
end end
end end
# Print file info unless quiet and unless stdin and/or stdout is involved # Print file info if `verbose` unless piping from/to stdin/stdout
print_progress = !(quiet || input_is_stdin || !(output.output_is_file || check)) print_progress = verbose && !(input_is_stdin || !(output.output_is_file || check))
# Print file info unless quiet and unless input/output is stdin/stdout # Print file info unless quiet and unless input/output is stdin/stdout
if print_progress if print_progress

73
test/maintests.jl

@ -91,6 +91,15 @@ function maintests(f::R) where {R}
write(f_in, bad) write(f_in, bad)
f_out = "out.jl" f_out = "out.jl"
for argv in [["--output=$f_out", f_in], ["-o", f_out, f_in]] for argv in [["--output=$f_out", f_in], ["-o", f_out, f_in]]
rm(f_out, force = true)
rc, fd1, fd2 = runic(argv)
@test rc == 0
@test isempty(fd1) && isempty(fd2)
@test read(f_out, String) == good
@test read(f_in, String) == bad
end
# --verbose
let argv = ["--verbose", "--output=$f_out", f_in]
rm(f_out, force = true) rm(f_out, force = true)
rc, fd1, fd2 = runic(argv) rc, fd1, fd2 = runic(argv)
@test rc == 0 @test rc == 0
@ -107,6 +116,14 @@ function maintests(f::R) where {R}
cdtmp() do cdtmp() do
f_in = "in.jl" f_in = "in.jl"
for argv in [["--inplace", f_in], ["-i", f_in]] for argv in [["--inplace", f_in], ["-i", f_in]]
write(f_in, bad)
rc, fd1, fd2 = runic(argv)
@test rc == 0
@test isempty(fd1) && isempty(fd2)
@test read(f_in, String) == good
end
# --verbose
let argv = ["-v", "--inplace", f_in]
write(f_in, bad) write(f_in, bad)
rc, fd1, fd2 = runic(argv) rc, fd1, fd2 = runic(argv)
@test rc == 0 @test rc == 0
@ -125,7 +142,14 @@ function maintests(f::R) where {R}
write(f_in, good) write(f_in, good)
rc, fd1, fd2 = runic(argv) rc, fd1, fd2 = runic(argv)
@test rc == 0 @test rc == 0
@test isempty(fd1) @test isempty(fd1) && isempty(fd2)
@test read(f_in, String) == good
end
# --verbose
let argv = ["--verbose", "--inplace", f_in]
write(f_in, good)
rc, fd1, fd2 = runic(argv)
@test rc == 0
@test occursin("Formatting `in.jl` ...", fd2) @test occursin("Formatting `in.jl` ...", fd2)
@test occursin("", fd2) @test occursin("", fd2)
@test !occursin("", fd2) @test !occursin("", fd2)
@ -144,6 +168,15 @@ function maintests(f::R) where {R}
markdownfile = "markdown.md" markdownfile = "markdown.md"
write(markdownfile, "this is not a Julia file") write(markdownfile, "this is not a Julia file")
for argv in [["--inplace", "."], ["-i", "."], ["-i", ".", "src"]] for argv in [["--inplace", "."], ["-i", "."], ["-i", ".", "src"]]
write(fgood, good)
write(fbad, bad)
rc, fd1, fd2 = runic(argv)
@test rc == 0
@test isempty(fd1) && isempty(fd2)
@test read(fgood, String) == read(fbad, String) == good
end
# --verbose
let argv = ["-v", "--inplace", "."]
write(fgood, good) write(fgood, good)
write(fbad, bad) write(fbad, bad)
rc, fd1, fd2 = runic(argv) rc, fd1, fd2 = runic(argv)
@ -163,6 +196,14 @@ function maintests(f::R) where {R}
cdtmp() do cdtmp() do
f_in = "in.jl" f_in = "in.jl"
for argv in [["--check", f_in], ["-c", f_in]] for argv in [["--check", f_in], ["-c", f_in]]
write(f_in, bad)
rc, fd1, fd2 = runic(argv)
@test rc == 1
@test isempty(fd1) && isempty(fd2)
@test read(f_in, String) == bad
end
# --verbose
let argv = ["--verbose", "--check", f_in]
write(f_in, bad) write(f_in, bad)
rc, fd1, fd2 = runic(argv) rc, fd1, fd2 = runic(argv)
@test rc == 1 @test rc == 1
@ -178,6 +219,13 @@ function maintests(f::R) where {R}
cdtmp() do cdtmp() do
f_in = "in.jl" f_in = "in.jl"
for argv in [["--check", f_in], ["-c", f_in]] for argv in [["--check", f_in], ["-c", f_in]]
write(f_in, good)
rc, fd1, fd2 = runic(argv)
@test rc == 0
@test isempty(fd1) && isempty(fd2)
@test read(f_in, String) == good
end
let argv = ["-v", "--check", f_in]
write(f_in, good) write(f_in, good)
rc, fd1, fd2 = runic(argv) rc, fd1, fd2 = runic(argv)
@test rc == 0 @test rc == 0
@ -200,6 +248,16 @@ function maintests(f::R) where {R}
markdownfile = "markdown.md" markdownfile = "markdown.md"
write(markdownfile, "this is not a Julia file") write(markdownfile, "this is not a Julia file")
for argv in [["--check", "."], ["-c", "."]] for argv in [["--check", "."], ["-c", "."]]
write(fgood, good)
write(fbad, bad)
rc, fd1, fd2 = runic(argv)
@test rc == 1
@test isempty(fd1) && isempty(fd2)
@test read(fgood, String) == good
@test read(fbad, String) == bad
end
# --verbose
let argv = ["--verbose", "--check", "."]
write(fgood, good) write(fgood, good)
write(fbad, bad) write(fbad, bad)
rc, fd1, fd2 = runic(argv) rc, fd1, fd2 = runic(argv)
@ -221,6 +279,19 @@ function maintests(f::R) where {R}
cdtmp() do cdtmp() do
f_in = "in.jl" f_in = "in.jl"
for argv in [["--check", "--diff", f_in], ["-c", "-d", f_in]] for argv in [["--check", "--diff", f_in], ["-c", "-d", f_in]]
write(f_in, bad)
rc, fd1, fd2 = runic(argv)
@test rc == 1
@test isempty(fd1)
@test !occursin("Checking `in.jl` ...", fd2)
@test !occursin("", fd2)
@test !occursin("", fd2)
@test occursin("diff --git", fd2)
@test occursin("-1+1", fd2)
@test occursin("+1 + 1", fd2)
@test read(f_in, String) == bad
end
let argv = ["-v", "--check", "--diff", f_in]
write(f_in, bad) write(f_in, bad)
rc, fd1, fd2 = runic(argv) rc, fd1, fd2 = runic(argv)
@test rc == 1 @test rc == 1

Loading…
Cancel
Save