You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let me start by conceding that this is a pretty low-priority issue, and it's probably out of scope for any formatter to address the wide variety of table formats1 that the ArgParse @add_arg_table! macro accepts.
... but, the following example from the first page of the ArgParse documentation2 is formatted (IMO) poorly by JuliaFormatter on the default settings:
using ArgParse
functionparse_commandline()
s =ArgParseSettings()
@add_arg_table! s begin"--opt1"
help ="an option with an argument""--opt2", "-o"
help ="another option with an argument"
arg_type = Int
default =0"--flag1"
help ="an option without argument, i.e. a flag"
action =:store_true"arg1"
help ="a positional argument"
required =trueendreturnparse_args(s)
endfunctionmain()
parsed_args =parse_commandline()
println("Parsed args:")
for (arg,val) in parsed_args
println("$arg => $val")
endendmain()
Formatting this flattens out all the arguments to the macro:
using ArgParse
functionparse_commandline()
s =ArgParseSettings()
@add_arg_table! s begin"--opt1"
help ="an option with an argument""--opt2", "-o"
help ="another option with an argument"
arg_type = Int
default =0"--flag1"
help ="an option without argument, i.e. a flag"
action =:store_true"arg1"
help ="a positional argument"
required =trueendreturnparse_args(s)
endfunctionmain()
parsed_args =parse_commandline()
println("Parsed args:")
for (arg, val) in parsed_args
println("$arg => $val")
endendmain()
One way to get things working properly is to surround each of the argument arguments with begin ... end as follows:
using ArgParse
functionparse_commandline()
s =ArgParseSettings()
@add_arg_table! s begin"--opt1"begin
help ="an option with an argument"end"--opt2", "-o"begin
help ="another option with an argument"
arg_type = Int
default =0end"--flag1"begin
help ="an option without argument, i.e. a flag"
action =:store_trueend"arg1"begin
help ="a positional argument"
required =trueendendreturnparse_args(s)
endfunctionmain()
parsed_args =parse_commandline()
println("Parsed args:")
for (arg, val) in parsed_args
println("$arg => $val")
endendmain()
JuliaFormatter leaves this one alone. But things get weird again if you put format_docstrings = true in the config:
using ArgParse
functionparse_commandline()
s =ArgParseSettings()
@add_arg_table! s begin""" --opt1"""begin
help ="an option with an argument"end"--opt2", "-o"begin
help ="another option with an argument"
arg_type = Int
default =0end""" --flag1"""begin
help ="an option without argument, i.e. a flag"
action =:store_trueend""" arg1"""begin
help ="a positional argument"
required =trueendendreturnparse_args(s)
endfunctionmain()
parsed_args =parse_commandline()
println("Parsed args:")
for (arg, val) in parsed_args
println("$arg => $val")
endendmain()
Each of the argument names is parsed as a docstring and put between triple quotes. In this case, the formatting actually changes how ArgParse parses the macro arguments, and causes it to complain that command-line argument names can't contain whitespace:
I see a similar issue from 2019 (#37), which I see was closed by #41. But it seems that the ArgParse syntax and/or JuliaFormatter rules have drifted and this issue has surfaced again.
Let me start by conceding that this is a pretty low-priority issue, and it's probably out of scope for any formatter to address the wide variety of table formats1 that the ArgParse
@add_arg_table!
macro accepts.... but, the following example from the first page of the ArgParse documentation2 is formatted (IMO) poorly by JuliaFormatter on the default settings:
Formatting this flattens out all the arguments to the macro:
One way to get things working properly is to surround each of the argument arguments with
begin ... end
as follows:JuliaFormatter leaves this one alone. But things get weird again if you put
format_docstrings = true
in the config:Each of the argument names is parsed as a docstring and put between triple quotes. In this case, the formatting actually changes how ArgParse parses the macro arguments, and causes it to complain that command-line argument names can't contain whitespace:
I see a similar issue from 2019 (#37), which I see was closed by #41. But it seems that the ArgParse syntax and/or JuliaFormatter rules have drifted and this issue has surfaced again.
Footnotes
https://carlobaldassi.github.io/ArgParse.jl/stable/arg_table/ ↩
https://carlobaldassi.github.io/ArgParse.jl/stable/ ↩
The text was updated successfully, but these errors were encountered: