From 9e006832cc7cd99e037af38546c16a3422e9df41 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Fri, 5 Jul 2024 09:24:33 +0200 Subject: [PATCH] Update docstrings, convert to String faster, fix --help --- src/Runic.jl | 21 ++++++++++++++------- src/main.jl | 3 +++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Runic.jl b/src/Runic.jl index 9ce5033..b88614c 100644 --- a/src/Runic.jl +++ b/src/Runic.jl @@ -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) 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) 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`") diff --git a/src/main.jl b/src/main.jl index 4119f13..2a408aa 100644 --- a/src/main.jl +++ b/src/main.jl @@ -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"