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
end end
function Context( 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, diff::Bool = false, check::Bool = false, quiet::Bool = false,
) )
src_io = IOBuffer(src_str) src_io = IOBuffer(src_str)
@ -366,9 +366,9 @@ function format_tree!(ctx::Context)
end 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) function format_string(str::AbstractString)
ctx = Context(str) ctx = Context(str)
@ -376,15 +376,22 @@ function format_string(str::AbstractString)
return String(take!(ctx.fmt_io)) return String(take!(ctx.fmt_io))
end 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) function format_file(inputfile::AbstractString, outputfile::AbstractString = inputfile; inplace::Bool = false)
# Argument handling # Argument handling
inputfile = normpath(abspath(inputfile)) inputfile = normpath(abspath(String(inputfile)))
outputfile = normpath(abspath(outputfile)) outputfile = normpath(abspath(String(outputfile)))
str = read(inputfile, String) str = read(inputfile, String)
if !inplace && (outputfile == inputfile || (isfile(outputfile) && samefile(inputfile, outputfile))) if !inplace && (outputfile == inputfile || (isfile(outputfile) && samefile(inputfile, outputfile)))
error("input and output must not be the same when `inplace = false`") error("input and output must not be the same when `inplace = false`")

3
src/main.jl

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

Loading…
Cancel
Save