Browse Source

Update docstrings, convert to String faster, fix --help

pull/19/head
Fredrik Ekre 1 year ago
parent
commit
9e006832cc
No known key found for this signature in database
GPG Key ID: DE82E6D5E364C0A2
  1. 21
      src/Runic.jl
  2. 3
      src/main.jl

21
src/Runic.jl

@ -137,7 +137,7 @@ mutable struct Context @@ -137,7 +137,7 @@ mutable struct Context
end
function Context(
src_str; assert::Bool = true, debug::Bool = false, verbose::Bool = debug,
src_str::String; assert::Bool = true, debug::Bool = false, verbose::Bool = debug,
diff::Bool = false, check::Bool = false, quiet::Bool = false,
)
src_io = IOBuffer(src_str)
@ -366,9 +366,9 @@ function format_tree!(ctx::Context) @@ -366,9 +366,9 @@ function format_tree!(ctx::Context)
end
"""
format_string(str::AbstractString) -> String
Runic.format_string(str::AbstractString) -> String
Format a string.
Format string `str` and return the formatted string.
"""
function format_string(str::AbstractString)
ctx = Context(str)
@ -376,15 +376,22 @@ function format_string(str::AbstractString) @@ -376,15 +376,22 @@ function format_string(str::AbstractString)
return String(take!(ctx.fmt_io))
end
# TODO: Implement the check and diff options here too.
"""
format_file(inputfile::AbstractString, outputfile::AbstractString; inplace::Bool=false)
Runic.format_file(
inputfile::AbstractString, outputfile::AbstractString = inputfile;
inplace::Bool=false,
)
Format file `inputfile` and write the formatted text to `outputfile`.
Format a file.
Setting the keyword argument `inplace = true` is required if `inputfile` and `outputfile`
are the same file.
"""
function format_file(inputfile::AbstractString, outputfile::AbstractString = inputfile; inplace::Bool = false)
# Argument handling
inputfile = normpath(abspath(inputfile))
outputfile = normpath(abspath(outputfile))
inputfile = normpath(abspath(String(inputfile)))
outputfile = normpath(abspath(String(outputfile)))
str = read(inputfile, String)
if !inplace && (outputfile == inputfile || (isfile(outputfile) && samefile(inputfile, outputfile)))
error("input and output must not be the same when `inplace = false`")

3
src/main.jl

@ -111,6 +111,9 @@ function main(argv) @@ -111,6 +111,9 @@ function main(argv)
x = popfirst!(argv)
if x == "-i" || x == "--inplace"
inplace = true
elseif x == "--help"
print_help()
return errno
elseif x == "-q" || x == "--quiet"
quiet = true
elseif x == "-v" || x == "--verbose"

Loading…
Cancel
Save