From 9212a4446a62e7fa84390d6857e2f1d9e6038788 Mon Sep 17 00:00:00 2001 From: Carlo Baldassi Date: Fri, 24 Jan 2020 02:47:47 +0100 Subject: [PATCH] Rename all mutating functions/macros with a `!` E.g. add_arg_table -> add_arg_table! etc. Create deprecation warnings for the exported ones. --- Project.toml | 3 +- README.md | 8 +- docs/src/arg_table.md | 52 ++++++------ docs/src/conflicts.md | 2 +- docs/src/import.md | 4 +- docs/src/index.md | 12 +-- examples/argparse_example1.jl | 2 +- examples/argparse_example2.jl | 2 +- examples/argparse_example3.jl | 2 +- examples/argparse_example4.jl | 2 +- examples/argparse_example5.jl | 6 +- examples/argparse_example6.jl | 6 +- examples/argparse_example7.jl | 22 ++--- examples/argparse_example8.jl | 12 +-- src/ArgParse.jl | 9 ++- src/deprecated.jl | 41 ++++++++++ src/parsing.jl | 42 +++++----- src/settings.jl | 146 +++++++++++++++++----------------- test/argparse_test01.jl | 18 ++--- test/argparse_test02.jl | 20 ++--- test/argparse_test03.jl | 40 +++++----- test/argparse_test04.jl | 18 ++--- test/argparse_test05.jl | 84 +++++++++---------- test/argparse_test06.jl | 24 +++--- test/argparse_test07.jl | 4 +- test/argparse_test08.jl | 4 +- test/argparse_test09.jl | 2 +- test/argparse_test10.jl | 18 ++--- test/argparse_test11.jl | 4 +- test/argparse_test12.jl | 26 +++--- test/common.jl | 2 +- 31 files changed, 341 insertions(+), 296 deletions(-) create mode 100644 src/deprecated.jl diff --git a/Project.toml b/Project.toml index 80e4241..7c0e7f7 100644 --- a/Project.toml +++ b/Project.toml @@ -1,9 +1,10 @@ name = "ArgParse" uuid = "c7e460c6-2fb9-53a9-8c5b-16f535851c63" -version = "1.0.0" author = ["Carlo Baldassi "] +version = "1.0.0" [deps] +Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" TextWrap = "b718987f-49a8-5099-9789-dcd902bef87d" [compat] diff --git a/README.md b/README.md index ab780b5..ea6b991 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,16 @@ See also the examples in the [examples directory](examples). ## Changes in release 1.0.0 * Drop support for Julia versions v0.6/v0.7 +* Renamed a few functions and macros (old versions can be used but produced deprecation warnings): + + `@add_arg_table` → `@add_arg_table!` + + `add_arg_table` → `add_arg_table!` + + `add_arg_group` → `add_arg_group!` + + `set_default_arg_group` → `set_default_arg_group!` + + `import_settings` → `import_settings!`. The signature of this function has also changed: + `args_only` is now a keyword argument * Parsing does not exit julia by default when in interactive mode now * Added mutually-exclusive and/or required argument groups * Added command aliases -* Renamed function `import_settings` → `import_settings!` ## Changes in release 0.6.2 diff --git a/docs/src/arg_table.md b/docs/src/arg_table.md index ff6a1ef..0a6db59 100644 --- a/docs/src/arg_table.md +++ b/docs/src/arg_table.md @@ -13,11 +13,11 @@ Each entry of the table consist of an argument name and a list of argument setti There are two very similar methods to populate a table: ```@docs -@add_arg_table +@add_arg_table! ``` ```@docs -add_arg_table +add_arg_table! ``` ## Argument names @@ -139,7 +139,7 @@ using ArgParse * `store_arg` (non-flag): store the argument. This is the default unless `nargs` is `0`. Example: ``` - julia> @add_arg_table(settings, "arg", action => :store_arg); + julia> @add_arg_table!(settings, "arg", action => :store_arg); julia> parse_args(["x"], settings) Dict{String,Any} with 1 entry: @@ -149,7 +149,7 @@ using ArgParse The result is a vector if `nargs` is a non-zero number, or one of `'*'`, `'+'`, `'R'`: ``` - julia> @add_arg_table(settings, "arg", action => :store_arg, nargs => 2); + julia> @add_arg_table!(settings, "arg", action => :store_arg, nargs => 2); julia> parse_args(["x", "y"], settings) Dict{String,Any} with 1 entry: @@ -159,7 +159,7 @@ using ArgParse * `store_true` (flag): store `true` if given, otherwise `false`. Example: ``` - julia> @add_arg_table(settings, "-v", action => :store_true); + julia> @add_arg_table!(settings, "-v", action => :store_true); julia> parse_args([], settings) Dict{String,Any} with 1 entry: @@ -173,7 +173,7 @@ using ArgParse * `store_false` (flag): store `false` if given, otherwise `true`. Example: ``` - julia> @add_arg_table(settings, "-v", action => :store_false); + julia> @add_arg_table!(settings, "-v", action => :store_false); julia> parse_args([], settings) Dict{String,Any} with 1 entry: @@ -188,7 +188,7 @@ using ArgParse Example: ``` - julia> @add_arg_table(settings, "-v", action => :store_const, constant => 1, default => 0); + julia> @add_arg_table!(settings, "-v", action => :store_const, constant => 1, default => 0); julia> parse_args([], settings) Dict{String,Any} with 1 entry: @@ -202,7 +202,7 @@ using ArgParse * `append_arg` (non-flag): append the argument to the result. Example: ``` - julia> @add_arg_table(settings, "-x", action => :append_arg); + julia> @add_arg_table!(settings, "-x", action => :append_arg); julia> parse_args(["-x", "1", "-x", "2"], settings) Dict{String,Any} with 1 entry: @@ -212,7 +212,7 @@ using ArgParse The result will be a `Vector{Vector}` if `nargs` is a non-zero number, or one of `'*'`, `'+'`, `'R'`: ``` - julia> @add_arg_table(settings, "-x", action => :append_arg, nargs => '*'); + julia> @add_arg_table!(settings, "-x", action => :append_arg, nargs => '*'); julia> parse_args(["-x", "1", "2", "-x", "3"], settings) Dict{String,Any} with 1 entry: @@ -222,7 +222,7 @@ using ArgParse * `append_const` (flag): append the value passed as `constant` in the entry settings. Example: ``` - julia> @add_arg_table(settings, "-x", action => :append_const, constant => 1); + julia> @add_arg_table!(settings, "-x", action => :append_const, constant => 1); julia> parse_args(["-x", "-x", "-x"], settings) Dict{String,Any} with 1 entry: @@ -233,7 +233,7 @@ using ArgParse invoked. Example: ``` - julia> @add_arg_table(settings, "-x", action => :count_invocations); + julia> @add_arg_table!(settings, "-x", action => :count_invocations); julia> parse_args(["-x", "-x", "-x"], settings) Dict{String,Any} with 1 entry: @@ -244,7 +244,7 @@ using ArgParse `false`. Example: ``` - julia> @add_arg_table(settings, "-x", action => :show_help); + julia> @add_arg_table!(settings, "-x", action => :show_help); julia> parse_args(["-x"], settings) usage: [-x] @@ -259,7 +259,7 @@ using ArgParse ``` julia> settings.version = "1.0"; - julia> @add_arg_table(settings, "-x", action => :show_version); + julia> @add_arg_table!(settings, "-x", action => :show_version); julia> parse_args(["-v"], settings) 1.0 @@ -285,7 +285,7 @@ using ArgParse function parse_commandline() s = ArgParseSettings() - @add_arg_table s begin + @add_arg_table! s begin "cmd1", "C" help = "first command" action = :command @@ -348,7 +348,7 @@ optional arguments: The argument settings and tables for commands can be accessed by using a dict-like notation, i.e. `settings["cmd1"]` is an `ArgParseSettings` object specific to the `"cmd1"` command. Therefore, to populate a command sub-argument-table, simply -use `@add_arg_table(settings["cmd1"], table...)` and similar. +use `@add_arg_table!(settings["cmd1"], table...)` and similar. These sub-settings are created when a command is added to the argument table, and by default they inherit their parent general settings except for the `prog` setting (which is auto-generated, as can be seen in the above example) and the @@ -376,7 +376,7 @@ arguments, displayed in that order. Example: ```@repl args settings = ArgParseSettings(exit_after_help = false); -@add_arg_table settings begin +@add_arg_table! settings begin "--opt" "arg" required = true @@ -395,44 +395,44 @@ options in the group can be provided. A group can also be declared to be require one argument in the group needs to be provided. ```@docs -add_arg_group +add_arg_group! ``` ```@docs -set_default_arg_group +set_default_arg_group! ``` -Besides setting a default group with `add_arg_group` and `set_default_group`, it's also possible to assign individual arguments -to a group by using the `group` setting in the argument table entry, which follows the same rules as `set_default_group`. +Besides setting a default group with `add_arg_group!` and `set_default_group!`, it's also possible to assign individual arguments +to a group by using the `group` setting in the argument table entry, which follows the same rules as `set_default_group!`. Note that if the `add_help` or `add_version` general settings are `true`, the `--help, -h` and `--version` options will always be added to the `optional` group. ## Argument table styles -Here are some examples of styles for the [`@add_arg_table`](@ref) marco and [`add_arg_table`](@ref) function invocation: +Here are some examples of styles for the [`@add_arg_table!`](@ref) marco and [`add_arg_table!`](@ref) function invocation: ```julia -@add_arg_table settings begin +@add_arg_table! settings begin "--opt", "-o" help = "an option" "arg" help = "a positional argument" end -@add_arg_table(settings +@add_arg_table!(settings , ["--opt", "-o"] , help => "an option" , "arg" , help => "a positional argument" ) -@add_arg_table settings begin +@add_arg_table! settings begin (["--opt", "-o"]; help = an option) ("arg"; help = "a positional argument") end -@add_arg_table(settings, +@add_arg_table!(settings, ["-opt", "-o"], begin help = "an option" @@ -442,7 +442,7 @@ end help = "a positional argument" end) -add_arg_table(settings, +add_arg_table!(settings, ["-opt", "-o"], Dict(:help => "an option"), "arg" , Dict(:help => "a positional argument") ) diff --git a/docs/src/conflicts.md b/docs/src/conflicts.md index 189573a..cfeacfb 100644 --- a/docs/src/conflicts.md +++ b/docs/src/conflicts.md @@ -24,5 +24,5 @@ the resolution of most of the conflicts in favor of the newest added entry. The * In case of duplicate positional arguments metavars, the older argument is deleted * A command can override an argument with the same destination key * However, an argument can never override a command; neither can a command override another command when added - with `@add_arg_table` (compatible commands are merged by [`import_settings`](@ref) though) + with `@add_arg_table!` (compatible commands are merged by [`import_settings!`](@ref) though) * Conflicting command aliases are removed diff --git a/docs/src/import.md b/docs/src/import.md index a7dffda..1352fb7 100644 --- a/docs/src/import.md +++ b/docs/src/import.md @@ -4,7 +4,5 @@ It may be useful in some cases to import an argument table into the one which is specialized versions of a common interface. ```@docs -import_settings +import_settings! ``` - - diff --git a/docs/src/index.md b/docs/src/index.md index d3b358f..c84fb5b 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -17,7 +17,7 @@ as well. To install the module, use Julia's package manager: start pkg mode by pressing `]` and then enter: ``` -(v1.0) pkg> add ArgParse +(v1.3) pkg> add ArgParse ``` Dependencies will be installed automatically. @@ -31,12 +31,12 @@ using ArgParse ``` There are two main steps for defining a command-line interface: creating an [`ArgParseSettings`](@ref) object, and -populating it with allowed arguments and options using either the macro [`@add_arg_table`](@ref) or the -function [`add_arg_table`](@ref) (see the [Argument table](@ref) section): +populating it with allowed arguments and options using either the macro [`@add_arg_table!`](@ref) or the +function [`add_arg_table!`](@ref) (see the [Argument table](@ref) section): ``` s = ArgParseSettings() -@add_arg_table s begin +@add_arg_table! s begin "--opt1" help = "an option with an argument" "--opt2", "-o" @@ -85,7 +85,7 @@ using ArgParse function parse_commandline() s = ArgParseSettings() - @add_arg_table s begin + @add_arg_table! s begin "--opt1" help = "an option with an argument" "--opt2", "-o" @@ -169,7 +169,7 @@ Parsed args: From these examples, a number of things can be noticed: -* `opt1` defaults to `nothing`, since no `default` setting was used for it in `@add_arg_table` +* `opt1` defaults to `nothing`, since no `default` setting was used for it in `@add_arg_table!` * `opt1` argument type, begin unspecified, defaults to `Any`, but in practice it's parsed as a string (e.g. `"2+2"`) * `opt2` instead has `Int` argument type, so `"4"` will be parsed and converted to an integer, diff --git a/examples/argparse_example1.jl b/examples/argparse_example1.jl index b55d39d..a08e8ce 100644 --- a/examples/argparse_example1.jl +++ b/examples/argparse_example1.jl @@ -7,7 +7,7 @@ function main(args) # initialize the settings (the description is for the help screen) s = ArgParseSettings(description = "Example 1 for argparse.jl: minimal usage.") - @add_arg_table s begin + @add_arg_table! s begin "--opt1" # an option (will take an argument) "--opt2", "-o" # another option, with short form "arg1" # a positional argument diff --git a/examples/argparse_example2.jl b/examples/argparse_example2.jl index febb70b..980f615 100644 --- a/examples/argparse_example2.jl +++ b/examples/argparse_example2.jl @@ -8,7 +8,7 @@ function main(args) "flags, options help, " * "required arguments.") - @add_arg_table s begin + @add_arg_table! s begin "--opt1" help = "an option" # used by the help screen "--opt2", "-o" diff --git a/examples/argparse_example3.jl b/examples/argparse_example3.jl index 586f491..fe7ebc2 100644 --- a/examples/argparse_example3.jl +++ b/examples/argparse_example3.jl @@ -12,7 +12,7 @@ function main(args) version = "Version 1.0", # version info add_version = true) # audo-add version option - @add_arg_table s begin + @add_arg_table! s begin "--opt1" nargs = '?' # '?' means optional argument arg_type = Int # only Int arguments allowed diff --git a/examples/argparse_example4.jl b/examples/argparse_example4.jl index c1e8354..45862f6 100644 --- a/examples/argparse_example4.jl +++ b/examples/argparse_example4.jl @@ -10,7 +10,7 @@ function main(args) "dest_name, metvar, range_tested, " * "alternative actions.") - @add_arg_table s begin + @add_arg_table! s begin "--opt1" action = :append_const # appends 'constant' to 'dest_name' arg_type = String # the only utility of this is restricting the dest array type diff --git a/examples/argparse_example5.jl b/examples/argparse_example5.jl index 0356a46..fa50d09 100644 --- a/examples/argparse_example5.jl +++ b/examples/argparse_example5.jl @@ -8,7 +8,7 @@ function main(args) # which we want to extend # So we just add a simple table - @add_arg_table s0 begin + @add_arg_table! s0 begin "--parent-flag", "-o" action=>"store_true" help=>"parent flag" @@ -25,11 +25,11 @@ function main(args) add_help = false, # disable auto-add of --help option version = "Version 1.0") # we set the version info, but --version won't be added - import_settings(s, s0) # now s has all of s0 arguments (except help/version) + import_settings!(s, s0) # now s has all of s0 arguments (except help/version) s.error_on_conflict = false # do not error-out when trying to override an option - @add_arg_table s begin + @add_arg_table! s begin "-o" # this will partially override s0's --parent-flag action = :store_true help = "child flag" diff --git a/examples/argparse_example6.jl b/examples/argparse_example6.jl index 821dde1..d190dbc 100644 --- a/examples/argparse_example6.jl +++ b/examples/argparse_example6.jl @@ -7,7 +7,7 @@ function main(args) s = ArgParseSettings("Example 6 for argparse.jl: " * "commands and their associated sub-tables.") - @add_arg_table s begin + @add_arg_table! s begin "run" action = :command # adds a command which will be read from an argument help = "start running mode" @@ -16,7 +16,7 @@ function main(args) help = "start jumping mode" end - @add_arg_table s["run"] begin # add command arg_table: same as usual, but invoked on s["cmd"] + @add_arg_table! s["run"] begin # add command arg_table: same as usual, but invoked on s["cmd"] "--speed" arg_type = Float64 default = 10. @@ -29,7 +29,7 @@ function main(args) s["jump"].autofix_names = true # this uses dashes in long options, underscores # in auto-generated dest_names - @add_arg_table s["jump"] begin + @add_arg_table! s["jump"] begin "--higher" action = :store_true help = "enhance jumping" diff --git a/examples/argparse_example7.jl b/examples/argparse_example7.jl index fc7daea..66cc992 100644 --- a/examples/argparse_example7.jl +++ b/examples/argparse_example7.jl @@ -7,9 +7,9 @@ function main(args) s = ArgParseSettings("Example 7 for argparse.jl: " * "argument groups.") - add_arg_group(s, "stack options") # add a group and sets it as the default - @add_arg_table s begin # all options (and arguments) in this table - # will be assigned to the newly added group + add_arg_group!(s, "stack options") # add a group and sets it as the default + @add_arg_table! s begin # all options (and arguments) in this table + # will be assigned to the newly added group "--opt1" action = :append_const arg_type = String @@ -24,12 +24,12 @@ function main(args) help = "append O2 to the stack" end - add_arg_group(s, "weird options", "weird") # another group, this time with a tag which allows - # to refer to it + add_arg_group!(s, "weird options", "weird") # another group, this time with a tag which allows + # to refer to it - set_default_arg_group(s, "weird") # set the default group (useless here, since we just added it) + set_default_arg_group!(s, "weird") # set the default group (useless here, since we just added it) - @add_arg_table s begin + @add_arg_table! s begin "--awkward-option" nargs = '+' action = :append_arg @@ -41,10 +41,10 @@ function main(args) "stored in chunks" end - set_default_arg_group(s) # reset the default arg group (which means arguments - # are automatically assigned to commands/options/pos.args - # groups) - @add_arg_table s begin + set_default_arg_group!(s) # reset the default arg group (which means arguments + # are automatically assigned to commands/options/pos.args + # groups) + @add_arg_table! s begin "-k" action = :store_const default = 0 diff --git a/examples/argparse_example8.jl b/examples/argparse_example8.jl index c571592..b62deed 100644 --- a/examples/argparse_example8.jl +++ b/examples/argparse_example8.jl @@ -7,8 +7,8 @@ function main(args) s = ArgParseSettings("Example 8 for argparse.jl: " * "mutually exclusive and requiredd groups.") - add_arg_group(s, "Mutually exclusive options", exclusive=true) - @add_arg_table s begin + add_arg_group!(s, "Mutually exclusive options", exclusive=true) + @add_arg_table! s begin "--maybe", "-M" action = :store_true help = "maybe..." @@ -17,8 +17,8 @@ function main(args) help = "maybe not..." end - add_arg_group(s, "Required mutually exclusive options", exclusive=true, required=true) - @add_arg_table s begin + add_arg_group!(s, "Required mutually exclusive options", exclusive=true, required=true) + @add_arg_table! s begin "--either", "-E" action = :store_true help = "choose the `either` option" @@ -28,8 +28,8 @@ function main(args) help = "set the `or` option" end - add_arg_group(s, "Required arguments", required=true) - @add_arg_table s begin + add_arg_group!(s, "Required arguments", required=true) + @add_arg_table! s begin "--enhance", "-+" action = :store_const default = 0 diff --git a/src/ArgParse.jl b/src/ArgParse.jl index 136ce4f..75f4d14 100644 --- a/src/ArgParse.jl +++ b/src/ArgParse.jl @@ -19,10 +19,10 @@ export ArgParseError, # functions & macros - add_arg_table, - @add_arg_table, - add_arg_group, - set_default_arg_group, + add_arg_table!, + @add_arg_table!, + add_arg_group!, + set_default_arg_group!, import_settings!, usage_string, parse_args @@ -34,5 +34,6 @@ import Base: show, getindex, setindex!, haskey include("common.jl") include("settings.jl") include("parsing.jl") +include("deprecated.jl") end # module ArgParse diff --git a/src/deprecated.jl b/src/deprecated.jl new file mode 100644 index 0000000..ecd371b --- /dev/null +++ b/src/deprecated.jl @@ -0,0 +1,41 @@ + +@deprecate add_arg_table add_arg_table! +@deprecate import_settings(settings, other) import_settings!(settings, other) +@deprecate import_settings(settings, other, ao) import_settings!(settings, other; args_only=ao) +@deprecate add_arg_group(args...; kw...) add_arg_group!(args...; kw...) +@deprecate set_default_arg_group set_default_arg_group! + +# The Base.@deprecate macro doesn't work with macros +# Here's an attempt at mimicking most of what that does +# and deprecate @add_arg_table -> @add_arg_table! +using Base: JLOptions, CoreLogging +using Logging: @logmsg + +function callframe(st, name) + found = false + for sf in st + sf == StackTraces.UNKNOWN && continue + if found && sf.func == Symbol("top-level scope") + return sf + end + sf.func == name && (found = true) + end + return StackTraces.UNKNOWN +end + +export @add_arg_table +macro add_arg_table(s, x...) + opts = JLOptions() + msg = "`@add_arg_table` is deprecated, use `@add_arg_table!` instead" + opts.depwarn == 2 && throw(ErrorException(msg)) + deplevel = opts.depwarn == 1 ? CoreLogging.Warn : CoreLogging.BelowMinLevel + st = stacktrace() + caller = callframe(st, Symbol("@add_arg_table")) + @logmsg(deplevel, msg, + _file = String(caller.file), + _line = caller.line, + _group = :depwarn, + maxlog = 1) + + return _add_arg_table!(s, x...) +end diff --git a/src/parsing.jl b/src/parsing.jl index 823af3c..64c61ea 100644 --- a/src/parsing.jl +++ b/src/parsing.jl @@ -502,7 +502,7 @@ mutable struct ParserState end found_command(state::ParserState) = state.command ≢ nothing -function parse_command_args(state::ParserState, settings::ArgParseSettings) +function parse_command_args!(state::ParserState, settings::ArgParseSettings) cmd = state.command haskey(settings, cmd) || argparse_error("unknown command: $cmd") #state.out_dict[cmd] = parse_args(state.args_list, settings[cmd]) @@ -518,7 +518,7 @@ function parse_command_args(state::ParserState, settings::ArgParseSettings) return state.out_dict[cmd] end -function preparse(c::Channel, state::ParserState, settings::ArgParseSettings) +function preparse!(c::Channel, state::ParserState, settings::ArgParseSettings) args_list = state.args_list while !isempty(args_list) state.arg_delim_found && (put!(c, :pos_arg); continue) @@ -602,7 +602,7 @@ function parse_args_unhandled(args_list::Vector, if settings.add_version settings.add_version = false - add_arg_field(settings, "--version", + add_arg_field!(settings, "--version", action = :show_version, help = "show version information and exit", group = "" @@ -611,7 +611,7 @@ function parse_args_unhandled(args_list::Vector, end if settings.add_help settings.add_help = false - add_arg_field(settings, ["--help", "-h"], + add_arg_field!(settings, ["--help", "-h"], action = :show_help, help = "show this help message and exit", group = "" @@ -620,16 +620,16 @@ function parse_args_unhandled(args_list::Vector, end state = ParserState(args_list, settings, truncated_shopts) - preparser = Channel(c->preparse(c, state, settings)) + preparser = Channel(c->preparse!(c, state, settings)) try for tag in preparser if tag == :long_option - parse_long_opt(state, settings) + parse_long_opt!(state, settings) elseif tag == :short_option_list - parse_short_opt(state, settings) + parse_short_opt!(state, settings) elseif tag == :pos_arg - parse_arg(state, settings) + parse_arg!(state, settings) else found_a_bug() end @@ -638,7 +638,7 @@ function parse_args_unhandled(args_list::Vector, end test_required_args(settings, state.found_args) if found_command(state) - cmd_dict = parse_command_args(state, settings) + cmd_dict = parse_command_args!(state, settings) cmd_dict ≡ nothing && return nothing elseif settings.commands_are_required && has_cmd(settings) argparse_error("no command given") @@ -660,8 +660,8 @@ function parse_args_unhandled(args_list::Vector, end # common parse functions -function parse1_flag(state::ParserState, settings::ArgParseSettings, f::ArgParseField, - has_arg::Bool, opt_name::AbstractString) +function parse1_flag!(state::ParserState, settings::ArgParseSettings, f::ArgParseField, + has_arg::Bool, opt_name::AbstractString) has_arg && argparse_error("option $opt_name takes no arguments") test_exclusive_groups!(state.exc_groups, settings, f, opt_name) command = nothing @@ -690,8 +690,8 @@ function parse1_flag(state::ParserState, settings::ArgParseSettings, f::ArgParse return end -function parse1_optarg(state::ParserState, settings::ArgParseSettings, f::ArgParseField, - rest, name::AbstractString) +function parse1_optarg!(state::ParserState, settings::ArgParseSettings, f::ArgParseField, + rest, name::AbstractString) args_list = state.args_list arg_delim_found = state.arg_delim_found out_dict = state.out_dict @@ -815,7 +815,7 @@ function parse1_optarg(state::ParserState, settings::ArgParseSettings, f::ArgPar end # parse long opts -function parse_long_opt(state::ParserState, settings::ArgParseSettings) +function parse_long_opt!(state::ParserState, settings::ArgParseSettings) opt_name = state.token arg_after_eq = state.token_arg local f::ArgParseField @@ -844,16 +844,16 @@ function parse_long_opt(state::ParserState, settings::ArgParseSettings) opt_name = fln if is_flag(f) - parse1_flag(state, settings, f, arg_after_eq ≢ nothing, "--"*opt_name) + parse1_flag!(state, settings, f, arg_after_eq ≢ nothing, "--"*opt_name) else - parse1_optarg(state, settings, f, arg_after_eq, "--"*opt_name) + parse1_optarg!(state, settings, f, arg_after_eq, "--"*opt_name) end push!(state.found_args, idstring(f)) return end # parse short opts -function parse_short_opt(state::ParserState, settings::ArgParseSettings) +function parse_short_opt!(state::ParserState, settings::ArgParseSettings) shopts_lst = state.token rest_as_arg = nothing sind = firstindex(shopts_lst) @@ -883,9 +883,9 @@ function parse_short_opt(state::ParserState, settings::ArgParseSettings) end found || argparse_error("unrecognized option -$opt_name") if is_flag(f) - parse1_flag(state, settings, f, next_is_eq, "-"*opt_name) + parse1_flag!(state, settings, f, next_is_eq, "-"*opt_name) else - parse1_optarg(state, settings, f, rest_as_arg, "-"*opt_name) + parse1_optarg!(state, settings, f, rest_as_arg, "-"*opt_name) end push!(state.found_args, idstring(f)) state.arg_consumed && break @@ -904,7 +904,7 @@ function parse_short_opt(state::ParserState, settings::ArgParseSettings) end # parse arg -function parse_arg(state::ParserState, settings::ArgParseSettings) +function parse_arg!(state::ParserState, settings::ArgParseSettings) found = false local f::ArgParseField for new_arg_ind = state.last_arg+1:length(settings.args_table.fields) @@ -917,7 +917,7 @@ function parse_arg(state::ParserState, settings::ArgParseSettings) end found || argparse_error("too many arguments") - parse1_optarg(state, settings, f, nothing, f.dest_name) + parse1_optarg!(state, settings, f, nothing, f.dest_name) push!(state.found_args, idstring(f)) return diff --git a/src/settings.jl b/src/settings.jl index b71f975..c4ca00e 100644 --- a/src/settings.jl +++ b/src/settings.jl @@ -133,7 +133,7 @@ end The `ArgParseSettings` object contains all the settings to be used during argument parsing. Settings are divided in two groups: general settings and argument-table-related settings. -While the argument table requires specialized functions such as [`@add_arg_table`](@ref) to be +While the argument table requires specialized functions such as [`@add_arg_table!`](@ref) to be defined and manipulated, general settings are simply object fields (most of them are `Bool` or `String`) and can be passed to the constructor as keyword arguments, or directly set at any time. @@ -597,8 +597,8 @@ function check_group_name(name::AbstractString) return true end -# add_arg_table and related -function name_to_fieldnames(name::ArgName, settings::ArgParseSettings) +# add_arg_table! and related +function name_to_fieldnames!(settings::ArgParseSettings, name::ArgName) pos_arg = "" long_opts = AbstractString[] short_opts = AbstractString[] @@ -662,7 +662,7 @@ end """ - add_arg_table(settings, [arg_name [,arg_options]]...) + add_arg_table!(settings, [arg_name [,arg_options]]...) This function is very similar to the macro version [`@add_arg_table`](@ref). Its syntax is stricter: tuples and blocks are not allowed and argument options are explicitly specified as `Dict` objects. @@ -673,7 +673,7 @@ However, since it doesn't involve macros, it offers more flexibility in other re Example: ```julia -add_arg_table(settings, +add_arg_table!(settings, ["--opt1", "-o"], Dict( :help => "an option with an argument" @@ -686,7 +686,7 @@ add_arg_table(settings, )) ``` """ -function add_arg_table(settings::ArgParseSettings, table::Union{ArgName,Vector,Dict}...) +function add_arg_table!(settings::ArgParseSettings, table::Union{ArgName,Vector,Dict}...) has_name = false for i = 1:length(table) !has_name && !(table[i] isa ArgName) && @@ -696,10 +696,10 @@ function add_arg_table(settings::ArgParseSettings, table::Union{ArgName,Vector,D i = 1 while i ≤ length(table) if i+1 ≤ length(table) && !(table[i+1] isa ArgName) - add_arg_field(settings, table[i]; table[i+1]...) + add_arg_field!(settings, table[i]; table[i+1]...) i += 2 else - add_arg_field(settings, table[i]) + add_arg_field!(settings, table[i]) i += 1 end end @@ -707,7 +707,7 @@ function add_arg_table(settings::ArgParseSettings, table::Union{ArgName,Vector,D end """ - @add_arg_table(settings, table...) + @add_arg_table!(settings, table...) This macro adds a table of arguments and options to the given `settings`. It can be invoked multiple times. The arguments groups are determined automatically, or the current default group is used if @@ -730,7 +730,7 @@ These rules allow for a variety usage styles, which are discussed in the style: ```julia -@add_arg_table settings begin +@add_arg_table! settings begin "--opt1", "-o" help = "an option with an argument" "--opt2" @@ -743,9 +743,14 @@ end In the above example, the `table` is put in a single `begin...end` block and the line `"--opt1", "-o"` is parsed as a tuple; indentation is used to help readability. -See also the function [`add_arg_table`](@ref). +See also the function [`add_arg_table!`](@ref). """ -macro add_arg_table(s, x...) +macro add_arg_table!(s, x...) + _add_arg_table!(s, x...) +end + +# Moved all the code to a function just to make the deprecation work +function _add_arg_table!(s, x...) # transform the tuple into a vector, so that # we can manipulate it x = Any[x...] @@ -756,7 +761,7 @@ macro add_arg_table(s, x...) exret = quote $z = $s $z isa ArgParseSettings || - error("first argument to @add_arg_table must be of type ArgParseSettings") + error("first argument to @add_arg_table! must be of type ArgParseSettings") end # initialize the name and the options expression name = nothing @@ -791,8 +796,8 @@ macro add_arg_table(s, x...) # first, concretely build the options opt = Expr(:call, exopt...) kopts = Expr(:parameters, Expr(:(...), opt)) - # then, call add_arg_field - aaf = Expr(:call, :add_arg_field, kopts, z, name) + # then, call add_arg_field! + aaf = Expr(:call, :add_arg_field!, kopts, z, name) # store it in the output expression exret = quote $exret @@ -821,7 +826,7 @@ macro add_arg_table(s, x...) continue else # anything else: ignore, but issue a warning - @warn "@add_arg_table: ignoring expression $y" + @warn "@add_arg_table!: ignoring expression $y" i += 1 end end @@ -830,7 +835,7 @@ macro add_arg_table(s, x...) # same as above opt = Expr(:call, exopt...) kopts = Expr(:parameters, Expr(:(...), opt)) - aaf = Expr(:call, :add_arg_field, kopts, z, name) + aaf = Expr(:call, :add_arg_field!, kopts, z, name) exret = quote $exret $aaf @@ -857,12 +862,12 @@ function get_group(group::AbstractString, arg::ArgParseField, settings::ArgParse for ag in settings.args_groups group == ag.name && return ag end - error("group $group not found, use add_arg_group to add it") + error("group $group not found, use add_arg_group! to add it") end found_a_bug() end -function add_arg_field(settings::ArgParseSettings, name::ArgName; desc...) +function add_arg_field!(settings::ArgParseSettings, name::ArgName; desc...) check_name_format(name) supplied_opts = keys(desc) @@ -925,7 +930,7 @@ function add_arg_field(settings::ArgParseSettings, name::ArgName; desc...) metavar isa Vector && error("multiple metavars only supported for optional arguments") end - pos_arg, long_opts, short_opts, cmd_aliases = name_to_fieldnames(name, settings) + pos_arg, long_opts, short_opts, cmd_aliases = name_to_fieldnames!(settings, name) if !isempty(cmd_aliases) is_command_action(action) || error("only command arguments can have multiple names (aliases)") @@ -1087,22 +1092,22 @@ function add_arg_field(settings::ArgParseSettings, name::ArgName; desc...) check_conflicts_with_commands(settings, new_arg, false) if force_override - override_duplicates(settings.args_table.fields, new_arg) + override_duplicates!(settings.args_table.fields, new_arg) else check_for_duplicates(settings.args_table.fields, new_arg) end push!(settings.args_table.fields, new_arg) - is_command_action(action) && add_command(settings, cmd_name, cmd_prog_hint, force_override) + is_command_action(action) && add_command!(settings, cmd_name, cmd_prog_hint, force_override) return end -function add_command(settings::ArgParseSettings, - command::AbstractString, - prog_hint::AbstractString, - force_override::Bool) +function add_command!(settings::ArgParseSettings, + command::AbstractString, + prog_hint::AbstractString, + force_override::Bool) haskey(settings, command) && error("command $command already added") if force_override - override_conflicts_with_commands(settings, command) + override_conflicts_with_commands!(settings, command) else check_conflicts_with_commands(settings, command) end @@ -1130,13 +1135,13 @@ end autogen_group_name(desc::AbstractString) = "#$(hash(desc))" -add_arg_group(settings::ArgParseSettings, desc::AbstractString; - exclusive::Bool = false, required::Bool = false) = - _add_arg_group(settings, desc, autogen_group_name(desc), true, exclusive, required) +add_arg_group!(settings::ArgParseSettings, desc::AbstractString; + exclusive::Bool = false, required::Bool = false) = + _add_arg_group!(settings, desc, autogen_group_name(desc), true, exclusive, required) """ - add_arg_group(settings, description, [name , [set_as_default]]; keywords...) + add_arg_group!(settings, description, [name , [set_as_default]]; keywords...) This function adds an argument group to the argument table in `settings`. The `description` is a `String` used in the help screen as a title for that group. The `name` is a unique name which can be @@ -1144,8 +1149,8 @@ provided to refer to that group at a later time. Groups can be declared to be mutually exclusive and/or required, see below. -After invoking this function, all subsequent invocations of the [`@add_arg_table`](@ref) macro and -[`add_arg_table`](@ref) function will use the new group as the default, unless `set_as_default` is +After invoking this function, all subsequent invocations of the [`@add_arg_table!`](@ref) macro and +[`add_arg_table!`](@ref) function will use the new group as the default, unless `set_as_default` is set to `false` (the default is `true`, and the option can only be set if providing a `name`). Therefore, the most obvious usage pattern is: for each group, add it and populate the argument table of that group. Example: @@ -1153,9 +1158,9 @@ table of that group. Example: ``` julia> settings = ArgParseSettings(); -julia> add_arg_group(settings, "custom group"); +julia> add_arg_group!(settings, "custom group"); -julia> @add_arg_table settings begin +julia> @add_arg_table! settings begin "--opt" "arg" end; @@ -1183,25 +1188,25 @@ than one option from the group is provided. A group can be declared as required using the `required = true` keyword, in which case at least one option or positional argument or command from the group must be provided. """ -function add_arg_group(settings::ArgParseSettings, - desc::AbstractString, - tag::Union{AbstractString,Symbol}, - set_as_default::Bool = true; - exclusive::Bool = false, - required::Bool = false - ) +function add_arg_group!(settings::ArgParseSettings, + desc::AbstractString, + tag::Union{AbstractString,Symbol}, + set_as_default::Bool = true; + exclusive::Bool = false, + required::Bool = false + ) name = string(tag) check_group_name(name) - _add_arg_group(settings, desc, name, set_as_default, exclusive, required) + _add_arg_group!(settings, desc, name, set_as_default, exclusive, required) end -function _add_arg_group(settings::ArgParseSettings, - desc::AbstractString, - name::AbstractString, - set_as_default::Bool, - exclusive::Bool, - required::Bool - ) +function _add_arg_group!(settings::ArgParseSettings, + desc::AbstractString, + name::AbstractString, + set_as_default::Bool, + exclusive::Bool, + required::Bool + ) already_added = any(ag->ag.name==name, settings.args_groups) already_added || push!(settings.args_groups, ArgParseGroup(name, desc, exclusive, required)) set_as_default && (settings.default_group = name) @@ -1209,18 +1214,18 @@ function _add_arg_group(settings::ArgParseSettings, end """ - set_default_arg_group(settings, [name]) + set_default_arg_group!(settings, [name]) -Set the default group for subsequent invocations of the [`@add_arg_table`](@ref) macro and -[`add_arg_table`](@ref) function. `name` is a `String`, and must be one of the standard group names +Set the default group for subsequent invocations of the [`@add_arg_table!`](@ref) macro and +[`add_arg_table!`](@ref) function. `name` is a `String`, and must be one of the standard group names (`"command"`, `"positional"` or `"optional"`) or one of the user-defined names given in -`add_arg_group` (groups with no assigned name cannot be used with this function). +`add_arg_group!` (groups with no assigned name cannot be used with this function). If `name` is not provided or is the empty string `""`, then the default behavior is reset (i.e. arguments will be automatically assigned to the standard groups). The `name` can also be passed as a `Symbol`. """ -function set_default_arg_group(settings::ArgParseSettings, name::Union{AbstractString,Symbol} = "") +function set_default_arg_group!(settings::ArgParseSettings, name::Union{AbstractString,Symbol} = "") name = string(name) startswith(name, '#') && error("invalid group name: $name (begins with #)") isempty(name) && (settings.default_group = ""; return) @@ -1231,7 +1236,7 @@ function set_default_arg_group(settings::ArgParseSettings, name::Union{AbstractS end # import_settings! & friends -function override_conflicts_with_commands(settings::ArgParseSettings, new_cmd::AbstractString) +function override_conflicts_with_commands!(settings::ArgParseSettings, new_cmd::AbstractString) ids0 = Int[] for ia in 1:length(settings.args_table.fields) a = settings.args_table.fields[ia] @@ -1241,7 +1246,7 @@ function override_conflicts_with_commands(settings::ArgParseSettings, new_cmd::A splice!(settings.args_table.fields, pop!(ids0)) end end -function override_duplicates(args::Vector{ArgParseField}, new_arg::ArgParseField) +function override_duplicates!(args::Vector{ArgParseField}, new_arg::ArgParseField) ids0 = Int[] for (ia,a) in enumerate(args) if (a.dest_name == new_arg.dest_name) && @@ -1284,7 +1289,7 @@ function override_duplicates(args::Vector{ArgParseField}, new_arg::ArgParseField if is_cmd(a) && is_cmd(new_arg) && a.constant == new_arg.constant && !is_arg(a) is_arg(new_arg) && found_a_bug() # this is ensured by check_settings_are_compatible # two command flags with the same command -> should have already been taken care of, - # by either check_settings_are_compatible or merge_commands + # by either check_settings_are_compatible or merge_commands! continue end @@ -1335,7 +1340,7 @@ function check_settings_are_compatible(settings::ArgParseSettings, other::ArgPar return true end -function merge_commands(fields::Vector{ArgParseField}, ofields::Vector{ArgParseField}) +function merge_commands!(fields::Vector{ArgParseField}, ofields::Vector{ArgParseField}) oids = Int[] for a in fields, ioa = 1:length(ofields) oa = ofields[ioa] @@ -1360,7 +1365,7 @@ function merge_commands(fields::Vector{ArgParseField}, ofields::Vector{ArgParseF return oids end -function fix_commands_fields(fields::Vector{ArgParseField}) +function fix_commands_fields!(fields::Vector{ArgParseField}) cmd_found = false for a in fields if is_arg(a) && is_cmd(a) @@ -1370,13 +1375,6 @@ function fix_commands_fields(fields::Vector{ArgParseField}) end end -# TODO: remove after minor version bump -export import_settings -function import_settings(args...; kw...) - @warn "`import_settings` is depreacted, use `import_settings!`" - import_settings!(args...; kw...) -end - """ import_settings!(settings, other_settings [,args_only]) @@ -1401,19 +1399,19 @@ will not have any effect on `settings`. This function can be used at any time. """ function import_settings!(settings::ArgParseSettings, - other::ArgParseSettings, + other::ArgParseSettings; args_only::Bool = true) check_settings_are_compatible(settings, other) fields = settings.args_table.fields ofields = deepcopy(other.args_table.fields) - merged_oids = merge_commands(fields, ofields) + merged_oids = merge_commands!(fields, ofields) if !settings.error_on_conflict for a in ofields - override_duplicates(fields, a) + override_duplicates!(fields, a) end for (subk, subs) in other.args_table.subsettings - override_conflicts_with_commands(settings, subk) + override_conflicts_with_commands!(settings, subk) end end while !isempty(merged_oids) @@ -1433,7 +1431,7 @@ function import_settings!(settings::ArgParseSettings, push!(settings.args_groups, deepcopy(oag)) end - fix_commands_fields(fields) + fix_commands_fields!(fields) if !args_only settings.add_help = other.add_help @@ -1459,11 +1457,11 @@ function import_settings!(settings::ArgParseSettings, end end if !haskey(settings, subk) - add_command(settings, subk, cmd_prog_hint, !settings.error_on_conflict) + add_command!(settings, subk, cmd_prog_hint, !settings.error_on_conflict) elseif !isempty(cmd_prog_hint) settings[subk].prog = "$(settings.prog) $cmd_prog_hint" end - import_settings!(settings[subk], subs, args_only) + import_settings!(settings[subk], subs, args_only=args_only) end return settings end diff --git a/test/argparse_test01.jl b/test/argparse_test01.jl index f252e61..2c2f39b 100644 --- a/test/argparse_test01.jl +++ b/test/argparse_test01.jl @@ -1,5 +1,5 @@ # test 01: minimal options/arguments, auto-generated help/version; -# function version of add_arg_table +# function version of add_arg_table! @testset "test 01" begin @@ -7,7 +7,7 @@ function ap_settings1() s = ArgParseSettings() - @add_arg_table s begin + @add_arg_table! s begin "--opt1" # an option (will take an argument) "--opt2", "-o" # another option, with short form "arg1" # a positional argument @@ -22,7 +22,7 @@ function ap_settings1b() s = ArgParseSettings(exc_handler = ArgParse.debug_handler) - add_arg_table(s, + add_arg_table!(s, "--opt1", ["--opt2", "-o"], "arg1") @@ -57,20 +57,20 @@ for s = [ap_settings1(), ap_settings1b()] @ap_test_throws ap_test1(["-o"]) @ap_test_throws ap_test1(["--opt1"]) - @ee_test_throws @add_arg_table(s, "--opt1") # long option already added - @ee_test_throws @add_arg_table(s, "-o") # short option already added + @ee_test_throws @add_arg_table!(s, "--opt1") # long option already added + @ee_test_throws @add_arg_table!(s, "-o") # short option already added end # test malformed tables function ap_settings1c() - @ee_test_throws @add_arg_table begin + @ee_test_throws @add_arg_table! begin "-a" end s = ArgParseSettings(exc_handler = ArgParse.debug_handler) - @ee_test_throws add_arg_table(s, Dict(:action => :store_true), "-a") + @ee_test_throws add_arg_table!(s, Dict(:action => :store_true), "-a") @test_addtable_failure s begin action = :store_true "-a" @@ -78,8 +78,8 @@ function ap_settings1c() @test_addtable_failure s begin action => :store_true end - @ee_test_throws add_arg_table(s, "-a", Dict(:wat => :store_true)) - @ee_test_throws @add_arg_table s begin + @ee_test_throws add_arg_table!(s, "-a", Dict(:wat => :store_true)) + @ee_test_throws @add_arg_table! s begin "-a" wat => :store_true end diff --git a/test/argparse_test02.jl b/test/argparse_test02.jl index 6ac94f0..6281465 100644 --- a/test/argparse_test02.jl +++ b/test/argparse_test02.jl @@ -1,7 +1,7 @@ # test 02: version information, default values, flags, # options with types, optional arguments, variable # number of arguments; -# function version of add_arg_table +# function version of add_arg_table! @testset "test 02" begin @@ -13,7 +13,7 @@ function ap_settings2() add_version = true, exc_handler = ArgParse.debug_handler) - @add_arg_table s begin + @add_arg_table! s begin "--opt1" nargs = '?' # '?' means optional argument arg_type = Int # only Int arguments allowed @@ -51,7 +51,7 @@ function ap_settings2b() add_version = true, exc_handler = ArgParse.debug_handler) - add_arg_table(s, + add_arg_table!(s, "--opt1", Dict( :nargs => '?', # '?' means optional argument :arg_type => Int, # only Int arguments allowed @@ -89,7 +89,7 @@ function ap_settings2c() add_version = true, exc_handler = ArgParse.debug_handler) - @add_arg_table(s + @add_arg_table!(s , "--opt1" , nargs = '?' # '?' means optional argument , arg_type = Int # only Int arguments allowed @@ -127,7 +127,7 @@ function ap_settings2d() add_version = true, exc_handler = ArgParse.debug_handler) - @add_arg_table s begin + @add_arg_table! s begin ("--opt1"; nargs = '?'; # '?' means optional argument arg_type = Int; # only Int arguments allowed @@ -165,7 +165,7 @@ function ap_settings2e() add_version = true, exc_handler = ArgParse.debug_handler) - @add_arg_table(s, + @add_arg_table!(s, "--opt1", begin nargs = '?' # '?' means optional argument @@ -240,12 +240,12 @@ for s = [ap_settings2(), ap_settings2b(), ap_settings2c(), ap_settings2d(), ap_s @ap_test_throws ap_test2(["--opt", "", "X", "Y"]) @ap_test_throws ap_test2(["--opt", "1e-2", "X", "Y"]) - @ee_test_throws @add_arg_table(s, "required_arg_after_optional_args", required = true) + @ee_test_throws @add_arg_table!(s, "required_arg_after_optional_args", required = true) # wrong default - @ee_test_throws @add_arg_table(s, "--opt", arg_type = Int, default = 1.5) + @ee_test_throws @add_arg_table!(s, "--opt", arg_type = Int, default = 1.5) # wrong range tester - @ee_test_throws @add_arg_table(s, "--opt", arg_type = Int, range_tester = x->string(x), default = 1) - @ee_test_throws @add_arg_table(s, "--opt", arg_type = Int, range_tester = x->sqrt(x)<1, default = -1) + @ee_test_throws @add_arg_table!(s, "--opt", arg_type = Int, range_tester = x->string(x), default = 1) + @ee_test_throws @add_arg_table!(s, "--opt", arg_type = Int, range_tester = x->sqrt(x)<1, default = -1) end end diff --git a/test/argparse_test03.jl b/test/argparse_test03.jl index 9c62b39..bf6aec8 100644 --- a/test/argparse_test03.jl +++ b/test/argparse_test03.jl @@ -19,7 +19,7 @@ function ap_settings3() s = ArgParseSettings("Test 3 for ArgParse.jl", exc_handler = ArgParse.debug_handler) - @add_arg_table s begin + @add_arg_table! s begin "--opt1" action = :append_const # appends 'constant' to 'dest_name' arg_type = String @@ -115,33 +115,33 @@ let s = ap_settings3() @ap_test_throws ap_test3(["--collect", "0.5"]) # invalid option name - @ee_test_throws @add_arg_table(s, "-2", action = :store_true) + @ee_test_throws @add_arg_table!(s, "-2", action = :store_true) # wrong constants - @ee_test_throws @add_arg_table(s, "--opt", action = :store_const, arg_type = Int, default = 1, constant = 1.5) - @ee_test_throws @add_arg_table(s, "--opt", action = :append_const, arg_type = Int, constant = 1.5) + @ee_test_throws @add_arg_table!(s, "--opt", action = :store_const, arg_type = Int, default = 1, constant = 1.5) + @ee_test_throws @add_arg_table!(s, "--opt", action = :append_const, arg_type = Int, constant = 1.5) # wrong defaults - @ee_test_throws @add_arg_table(s, "--opt", action = :append_arg, arg_type = Int, default = Float64[]) - @ee_test_throws @add_arg_table(s, "--opt", action = :append_arg, nargs = '+', arg_type = Int, default = Vector{Float64}[]) - @ee_test_throws @add_arg_table(s, "--opt", action = :store_arg, nargs = '+', arg_type = Int, default = [1.5]) - @ee_test_throws @add_arg_table(s, "--opt", action = :store_arg, nargs = '+', arg_type = Int, default = 1) - @ee_test_throws @add_arg_table(s, "--opt", action = :append_arg, arg_type = Int, range_tester=x->x<=1, default = Int[0, 1, 2]) - @ee_test_throws @add_arg_table(s, "--opt", action = :append_arg, nargs = '+', arg_type = Int, range_tester=x->x<=1, default = Vector{Int}[[1,1],[0,2]]) - @ee_test_throws @add_arg_table(s, "--opt", action = :store_arg, nargs = '+', range_tester = x->x<=1, default = [1.5]) + @ee_test_throws @add_arg_table!(s, "--opt", action = :append_arg, arg_type = Int, default = Float64[]) + @ee_test_throws @add_arg_table!(s, "--opt", action = :append_arg, nargs = '+', arg_type = Int, default = Vector{Float64}[]) + @ee_test_throws @add_arg_table!(s, "--opt", action = :store_arg, nargs = '+', arg_type = Int, default = [1.5]) + @ee_test_throws @add_arg_table!(s, "--opt", action = :store_arg, nargs = '+', arg_type = Int, default = 1) + @ee_test_throws @add_arg_table!(s, "--opt", action = :append_arg, arg_type = Int, range_tester=x->x<=1, default = Int[0, 1, 2]) + @ee_test_throws @add_arg_table!(s, "--opt", action = :append_arg, nargs = '+', arg_type = Int, range_tester=x->x<=1, default = Vector{Int}[[1,1],[0,2]]) + @ee_test_throws @add_arg_table!(s, "--opt", action = :store_arg, nargs = '+', range_tester = x->x<=1, default = [1.5]) # no constants - @ee_test_throws @add_arg_table(s, "--opt", action = :store_const, arg_type = Int, default = 1) - @ee_test_throws @add_arg_table(s, "--opt", action = :append_const, arg_type = Int) + @ee_test_throws @add_arg_table!(s, "--opt", action = :store_const, arg_type = Int, default = 1) + @ee_test_throws @add_arg_table!(s, "--opt", action = :append_const, arg_type = Int) # incompatible action - @ee_test_throws @add_arg_table(s, "--opt3", action = :store_const, arg_type = String, constant = "O3", dest_name = "O_stack", help = "append O3") + @ee_test_throws @add_arg_table!(s, "--opt3", action = :store_const, arg_type = String, constant = "O3", dest_name = "O_stack", help = "append O3") # wrong range tester - @ee_test_throws @add_arg_table(s, "--opt", action = :append_arg, arg_type = Int, range_tester=x->string(x), default = Int[0, 1, 2]) - @ee_test_throws @add_arg_table(s, "--opt", action = :append_arg, nargs = '+', arg_type = Int, range_tester=x->string(x), default = Vector{Int}[[1,1],[0,2]]) - @ee_test_throws @add_arg_table(s, "--opt", action = :store_arg, nargs = '+', range_tester = x->string(x), default = [1.5]) - @ee_test_throws @add_arg_table(s, "--opt", action = :store_arg, nargs = '+', range_tester = x->sqrt(x)<2, default = [-1.5]) - @ee_test_throws @add_arg_table(s, "--opt", action = :append_arg, nargs = '+', arg_type = Int, range_tester=x->sqrt(x)<2, default = Vector{Int}[[1,1],[0,-2]]) + @ee_test_throws @add_arg_table!(s, "--opt", action = :append_arg, arg_type = Int, range_tester=x->string(x), default = Int[0, 1, 2]) + @ee_test_throws @add_arg_table!(s, "--opt", action = :append_arg, nargs = '+', arg_type = Int, range_tester=x->string(x), default = Vector{Int}[[1,1],[0,2]]) + @ee_test_throws @add_arg_table!(s, "--opt", action = :store_arg, nargs = '+', range_tester = x->string(x), default = [1.5]) + @ee_test_throws @add_arg_table!(s, "--opt", action = :store_arg, nargs = '+', range_tester = x->sqrt(x)<2, default = [-1.5]) + @ee_test_throws @add_arg_table!(s, "--opt", action = :append_arg, nargs = '+', arg_type = Int, range_tester=x->sqrt(x)<2, default = Vector{Int}[[1,1],[0,-2]]) # allow ambiguous options s.allow_ambiguous_opts = true - @add_arg_table(s, "-2", action = :store_true) + @add_arg_table!(s, "-2", action = :store_true) @test ap_test3([]) == Dict{String,Any}("O_stack"=>String[], "k"=>0, "u"=>0, "array"=>[7, 3, 2], "custom"=>CustomType(), "oddint"=>1, "collect"=>[], "awk"=>Any[Any["X"]], "2"=>false) @test ap_test3(["-2"]) == Dict{String,Any}("O_stack"=>String[], "k"=>0, "u"=>0, "array"=>[7, 3, 2], "custom"=>CustomType(), "oddint"=>1, "collect"=>[], "awk"=>Any[["X"]], "2"=>true) @test ap_test3(["--awk", "X", "-2"]) == Dict{String,Any}("O_stack"=>String[], "k"=>0, "u"=>0, "array"=>[7, 3, 2], "custom"=>CustomType(), "oddint"=>1, "collect"=>[], "awk"=>Any[Any["X"], Any["X"]], "2"=>true) diff --git a/test/argparse_test04.jl b/test/argparse_test04.jl index 20ed087..1eaff1f 100644 --- a/test/argparse_test04.jl +++ b/test/argparse_test04.jl @@ -8,7 +8,7 @@ function ap_settings4() # which we want to extend # So we just add a simple table - @add_arg_table s0 begin + @add_arg_table! s0 begin "--parent-flag", "-o" action = "store_true" help = "parent flag" @@ -29,7 +29,7 @@ function ap_settings4() import_settings!(s, s0) # now s has all of s0 arguments (except help/version) - @add_arg_table s begin + @add_arg_table! s begin "-o" # this will partially override s0's --parent-flag action = :store_true help = "child flag" @@ -60,7 +60,7 @@ function ap_settings4b() exc_handler = ArgParse.debug_handler) # So we just add a simple table - @add_arg_table s0 begin + @add_arg_table! s0 begin "--parent-flag", "-o" action = "store_true" help = "parent flag" @@ -76,9 +76,9 @@ function ap_settings4b() s = ArgParseSettings("Test 4 for ArgParse.jl", version = "Version 1.0") - import_settings!(s, s0, false) # args_only set to false + import_settings!(s, s0, args_only=false) - @add_arg_table s begin + @add_arg_table! s begin "-o" action = :store_true help = "child flag" @@ -131,7 +131,7 @@ for s = [ap_settings4(), ap_settings4b()] # same metavar as another argument s.error_on_conflict = true - @ee_test_throws @add_arg_table(s, "other-arg", metavar="parent-argument") + @ee_test_throws @add_arg_table!(s, "other-arg", metavar="parent-argument") end @@ -142,7 +142,7 @@ function ap_settings4_base() version = "Version 1.0", exc_handler = ArgParse.debug_handler) - @add_arg_table s begin + @add_arg_table! s begin "-o" action = :store_true help = "child flag" @@ -158,7 +158,7 @@ function ap_settings4_conflict1() s0 = ArgParseSettings() - @add_arg_table s0 begin + @add_arg_table! s0 begin "--parent-flag", "-o" action = "store_true" help = "parent flag" @@ -171,7 +171,7 @@ function ap_settings4_conflict2() s0 = ArgParseSettings() - @add_arg_table s0 begin + @add_arg_table! s0 begin "--flag" action = "store_true" help = "another parent flag" diff --git a/test/argparse_test05.jl b/test/argparse_test05.jl index 659e847..402d501 100644 --- a/test/argparse_test05.jl +++ b/test/argparse_test05.jl @@ -8,7 +8,7 @@ function ap_settings5() exc_handler = ArgParse.debug_handler, exit_after_help = false) - @add_arg_table s begin + @add_arg_table! s begin "run" action = :command help = "start running mode" @@ -17,7 +17,7 @@ function ap_settings5() help = "start jumping mode" end - @add_arg_table s["run"] begin + @add_arg_table! s["run"] begin "--speed" arg_type = Float64 default = 10. @@ -28,7 +28,7 @@ function ap_settings5() s["jump"].commands_are_required = false s["jump"].autofix_names = true - @add_arg_table s["jump"] begin + @add_arg_table! s["jump"] begin "--higher" action = :store_true help = "enhance jumping" @@ -43,7 +43,7 @@ function ap_settings5() s["jump"]["som"].description = "Somersault jump mode" - @add_arg_table s["jump"]["som"] begin + @add_arg_table! s["jump"]["som"] begin "-t" nargs = '?' arg_type = Int @@ -136,32 +136,32 @@ let s = ap_settings5() @test ap_test5(["run", "--speed", "3"], as_symbols = true) == Dict{Symbol,Any}(:_COMMAND_=>:run, :run=>Dict{Symbol,Any}(:speed=>3.0)) # argument after command - @ee_test_throws @add_arg_table(s, "arg_after_command") + @ee_test_throws @add_arg_table!(s, "arg_after_command") # same name as command - @ee_test_throws @add_arg_table(s, "run") - @ee_test_throws @add_arg_table(s["jump"], "-c") - @ee_test_throws @add_arg_table(s["jump"], "--somersault") + @ee_test_throws @add_arg_table!(s, "run") + @ee_test_throws @add_arg_table!(s["jump"], "-c") + @ee_test_throws @add_arg_table!(s["jump"], "--somersault") # same dest_name as command - @ee_test_throws @add_arg_table(s["jump"], "--som") - @ee_test_throws @add_arg_table(s["jump"], "-s", dest_name = "som") + @ee_test_throws @add_arg_table!(s["jump"], "--som") + @ee_test_throws @add_arg_table!(s["jump"], "-s", dest_name = "som") # same name as command alias - @ee_test_throws @add_arg_table(s, "ju") - @ee_test_throws @add_arg_table(s, "J") + @ee_test_throws @add_arg_table!(s, "ju") + @ee_test_throws @add_arg_table!(s, "J") # new command with the same name as another one - @ee_test_throws @add_arg_table(s, ["run", "R"], action = :command) - @ee_test_throws @add_arg_table(s, "jump", action = :command) + @ee_test_throws @add_arg_table!(s, ["run", "R"], action = :command) + @ee_test_throws @add_arg_table!(s, "jump", action = :command) # new command with the same name as another one's alias - @ee_test_throws @add_arg_table(s, "ju", action = :command) - @ee_test_throws @add_arg_table(s, "J", action = :command) + @ee_test_throws @add_arg_table!(s, "ju", action = :command) + @ee_test_throws @add_arg_table!(s, "J", action = :command) # new command with an alias which is the same as another command - @ee_test_throws @add_arg_table(s, ["fast", "run"], action = :command) - @ee_test_throws @add_arg_table(s, ["R", "jump"], action = :command) + @ee_test_throws @add_arg_table!(s, ["fast", "run"], action = :command) + @ee_test_throws @add_arg_table!(s, ["R", "jump"], action = :command) # new command with an alias which is already in use - @ee_test_throws @add_arg_table(s, ["R", "ju"], action = :command) - @ee_test_throws @add_arg_table(s, ["R", "S", "J"], action = :command) + @ee_test_throws @add_arg_table!(s, ["R", "ju"], action = :command) + @ee_test_throws @add_arg_table!(s, ["R", "S", "J"], action = :command) # alias overriding by a command name - @add_arg_table(s, "J", action = :command, force_override = true, help = "the J command") + @add_arg_table!(s, "J", action = :command, force_override = true, help = "the J command") @test stringhelp(s) == """ usage: $(basename(Base.source_path())) {run|jump|J} @@ -175,7 +175,7 @@ let s = ap_settings5() """ # alias overriding by a command alias - @add_arg_table(s, ["S", "ju"], action = :command, force_override = true, help = "the S command") + @add_arg_table!(s, ["S", "ju"], action = :command, force_override = true, help = "the S command") @test stringhelp(s) == """ usage: $(basename(Base.source_path())) {run|jump|J|S} @@ -190,11 +190,11 @@ let s = ap_settings5() """ # cannot override a command name - @ee_test_throws @add_arg_table(s, ["J", "R"], action = :command, force_override = true) - @ee_test_throws @add_arg_table(s, ["R", "J"], action = :command, force_override = true) + @ee_test_throws @add_arg_table!(s, ["J", "R"], action = :command, force_override = true) + @ee_test_throws @add_arg_table!(s, ["R", "J"], action = :command, force_override = true) # conflict between dest_name and a reserved Symbol - @add_arg_table(s, "--COMMAND", dest_name="_COMMAND_") + @add_arg_table!(s, "--COMMAND", dest_name="_COMMAND_") @ee_test_throws ap_test5(["run", "--speed", "3"], as_symbols = true) end @@ -206,7 +206,7 @@ function ap_settings5b() exc_handler = ArgParse.debug_handler, exit_after_help = false) - @add_arg_table s0 begin + @add_arg_table! s0 begin "run", "R" action = :command help = "start running mode" @@ -221,7 +221,7 @@ function ap_settings5b() "perform the command" end - @add_arg_table s0["run"] begin + @add_arg_table! s0["run"] begin "--speed" arg_type = Float64 default = 10. @@ -233,10 +233,10 @@ function ap_settings5b() s0["jump"].autofix_names = true s0["jump"].add_help = false - add_arg_group(s0["jump"], "modifiers", "modifiers") - set_default_arg_group(s0["jump"]) + add_arg_group!(s0["jump"], "modifiers", "modifiers") + set_default_arg_group!(s0["jump"]) - @add_arg_table s0["jump"] begin + @add_arg_table! s0["jump"] begin "--higher" action = :store_true help = "enhance jumping" @@ -250,8 +250,8 @@ function ap_settings5b() help = "clap feet jumping mode" end - add_arg_group(s0["jump"], "other") - @add_arg_table s0["jump"] begin + add_arg_group!(s0["jump"], "other") + @add_arg_table! s0["jump"] begin "--help" action = :show_help help = "show this help message " * @@ -260,7 +260,7 @@ function ap_settings5b() s0["jump"]["som"].description = "Somersault jump mode" - @add_arg_table s begin + @add_arg_table! s begin "jump", "run", "J" # The "run" alias will be overridden action = :command help = "start jumping mode" @@ -277,17 +277,17 @@ function ap_settings5b() s["jump"].autofix_names = true s["jump"].add_help = false - add_arg_group(s["jump"], "modifiers", "modifiers") - @add_arg_table s["jump"] begin + add_arg_group!(s["jump"], "modifiers", "modifiers") + @add_arg_table! s["jump"] begin "--lower" action = :store_false dest_name = "higher" help = "reduce jumping" end - set_default_arg_group(s["jump"]) + set_default_arg_group!(s["jump"]) - @add_arg_table s["jump"] begin + @add_arg_table! s["jump"] begin "--clap-feet" action = :command help = "clap feet jumping mode" @@ -299,7 +299,7 @@ function ap_settings5b() help = "overridden" end - @add_arg_table s["fly"] begin + @add_arg_table! s["fly"] begin "--glade" action = :store_true help = "glade mode" @@ -307,7 +307,7 @@ function ap_settings5b() s["jump"]["clap_feet"].add_version = true - @add_arg_table s["jump"]["clap_feet"] begin + @add_arg_table! s["jump"]["clap_feet"] begin "--whistle" action = :store_true end @@ -366,11 +366,11 @@ let s = ap_settings5b() end let - s1 = @add_arg_table(ArgParseSettings(), "run", action = :command) - s2 = @add_arg_table(ArgParseSettings(), "--run", action = :store_true) + s1 = @add_arg_table!(ArgParseSettings(), "run", action = :command) + s2 = @add_arg_table!(ArgParseSettings(), "--run", action = :store_true) @ee_test_throws import_settings!(s1, s2) @ee_test_throws import_settings!(s2, s1) # this fails since error_on_conflict=true - s2 = @add_arg_table(ArgParseSettings(), ["R", "run"], action = :command) + s2 = @add_arg_table!(ArgParseSettings(), ["R", "run"], action = :command) @ee_test_throws import_settings!(s1, s2) @ee_test_throws import_settings!(s2, s1) # this fails since error_on_conflict=true end diff --git a/test/argparse_test06.jl b/test/argparse_test06.jl index 066eed6..187ea4b 100644 --- a/test/argparse_test06.jl +++ b/test/argparse_test06.jl @@ -7,8 +7,8 @@ function ap_settings6() s = ArgParseSettings("Test 6 for ArgParse.jl", exc_handler = ArgParse.debug_handler) - add_arg_group(s, "stack options") - @add_arg_table s begin + add_arg_group!(s, "stack options") + @add_arg_table! s begin "--opt1" action = :append_const arg_type = String @@ -23,11 +23,11 @@ function ap_settings6() help = "append O2 to the stack" end - add_arg_group(s, "weird options", "weird") + add_arg_group!(s, "weird options", "weird") - set_default_arg_group(s, "weird") + set_default_arg_group!(s, "weird") - @add_arg_table s begin + @add_arg_table! s begin "--awkward-option" nargs = '+' action = :append_arg @@ -39,9 +39,9 @@ function ap_settings6() "stored in chunks" end - set_default_arg_group(s) + set_default_arg_group!(s) - @add_arg_table s begin + @add_arg_table! s begin "-k" action = :store_const default = 0 @@ -55,9 +55,9 @@ function ap_settings6() group = "weird" end - set_default_arg_group(s, "weird") + set_default_arg_group!(s, "weird") - @add_arg_table s begin + @add_arg_table! s begin "--rest" nargs = 'R' help = "an option which will consume " * @@ -108,9 +108,9 @@ let s = ap_settings6() @ap_test_throws ap_test6(["--şİł", "-1", "-2", "-3", "-4"]) # invalid groups - @ee_test_throws add_arg_group(s, "invalid commands", "") - @ee_test_throws add_arg_group(s, "invalid commands", "#invalid") - @ee_test_throws @add_arg_table(s, "--opt", action = :store_true, group = "none") + @ee_test_throws add_arg_group!(s, "invalid commands", "") + @ee_test_throws add_arg_group!(s, "invalid commands", "#invalid") + @ee_test_throws @add_arg_table!(s, "--opt", action = :store_true, group = "none") end end diff --git a/test/argparse_test07.jl b/test/argparse_test07.jl index 68f2509..36389ea 100644 --- a/test/argparse_test07.jl +++ b/test/argparse_test07.jl @@ -7,7 +7,7 @@ function ap_settings7() s = ArgParseSettings(description = "Test 7 for ArgParse.jl\n\nTesting oxymoronic options", exc_handler = ArgParse.debug_handler) - @add_arg_table s begin + @add_arg_table! s begin "--oxymoronic", "-x" required = true help = "a required option" @@ -65,7 +65,7 @@ let s = ap_settings7() @ap_test_throws ap_test7(["--oxymoronic=A", "--opt=B"]) @ap_test_throws ap_test7(["--opt=A, -o=B"]) s.suppress_warnings = true - add_arg_table(s, "-g", Dict(:action=>:store_true, :required=>true)) + add_arg_table!(s, "-g", Dict(:action=>:store_true, :required=>true)) @test ap_test7(["--oxymoronic=A", "-o=B"]) == Dict{String,Any}("oxymoronic"=>"A", "opt"=>nothing, "o"=>"B", "flag"=>false, "g"=>false) end diff --git a/test/argparse_test08.jl b/test/argparse_test08.jl index 1b9adba..47e57c9 100644 --- a/test/argparse_test08.jl +++ b/test/argparse_test08.jl @@ -6,7 +6,7 @@ function ap_settings8a() s = ArgParseSettings(fromfile_prefix_chars=['@']) - @add_arg_table s begin + @add_arg_table! s begin "--opt1" # an option (will take an argument) "--opt2", "-o" # another option, with short form "arg1" # a positional argument @@ -21,7 +21,7 @@ function ap_settings8b() # unicode s = ArgParseSettings(fromfile_prefix_chars="@∘") - @add_arg_table s begin + @add_arg_table! s begin "--opt1" # an option (will take an argument) "--opt2", "-o" # another option, with short form "arg1" # a positional argument diff --git a/test/argparse_test09.jl b/test/argparse_test09.jl index 8ca3246..bbce9e4 100644 --- a/test/argparse_test09.jl +++ b/test/argparse_test09.jl @@ -16,7 +16,7 @@ function ap_settings9() preformatted_description=true, exc_handler = ArgParse.debug_handler) - @add_arg_table s begin + @add_arg_table! s begin "--opt" required = true help = "a required option" diff --git a/test/argparse_test10.jl b/test/argparse_test10.jl index 329c8cc..27ef581 100644 --- a/test/argparse_test10.jl +++ b/test/argparse_test10.jl @@ -1,5 +1,5 @@ # test 10: multiple metavars -# function version of add_arg_table +# function version of add_arg_table! @testset "test 10" begin @@ -11,7 +11,7 @@ function ap_settings10() add_version = true, exc_handler = ArgParse.debug_handler) - @add_arg_table s begin + @add_arg_table! s begin "--opt1" nargs => 2 # exactly 2 arguments must be specified arg_type => Int # only Int arguments allowed @@ -49,7 +49,7 @@ function ap_settings10b() add_version = true, exc_handler = ArgParse.debug_handler) - add_arg_table(s, + add_arg_table!(s, "--opt1", Dict( :nargs => 2, # exactly 2 arguments :arg_type => Int, # only Int arguments allowed @@ -89,7 +89,7 @@ function ap_settings10c(in_nargs) add_version = true, exc_handler = ArgParse.debug_handler) - add_arg_table(s, + add_arg_table!(s, "--opt1", Dict( :nargs => in_nargs, :arg_type => Int, @@ -119,7 +119,7 @@ function ap_settings10d() add_version = true, exc_handler = ArgParse.debug_handler) - add_arg_table(s, + add_arg_table!(s, "opt1", Dict( :nargs => 2, :arg_type => Int, @@ -167,12 +167,12 @@ for s = [ap_settings10(), ap_settings10b()] @ap_test_throws ap_test10(["X", "Y", "--opt1", "1"]) @ap_test_throws ap_test10(["X", "Y", "--opt1", "a", "b"]) - @ee_test_throws @add_arg_table(s, "required_arg_after_optional_args", required = true) + @ee_test_throws @add_arg_table!(s, "required_arg_after_optional_args", required = true) # wrong default - @ee_test_throws @add_arg_table(s, "--opt", arg_type = Int, default = 1.5) + @ee_test_throws @add_arg_table!(s, "--opt", arg_type = Int, default = 1.5) # wrong range tester - @ee_test_throws @add_arg_table(s, "--opt", arg_type = Int, range_tester = x->string(x), default = 1) - @ee_test_throws @add_arg_table(s, "--opt", arg_type = Int, range_tester = x->sqrt(x)<1, default = -1) + @ee_test_throws @add_arg_table!(s, "--opt", arg_type = Int, range_tester = x->string(x), default = 1) + @ee_test_throws @add_arg_table!(s, "--opt", arg_type = Int, range_tester = x->sqrt(x)<1, default = -1) end end diff --git a/test/argparse_test11.jl b/test/argparse_test11.jl index 68b10e2..352ed3d 100644 --- a/test/argparse_test11.jl +++ b/test/argparse_test11.jl @@ -4,12 +4,12 @@ s = ArgParseSettings() - @add_arg_table s begin + @add_arg_table! s begin "say" action = :command end - @add_arg_table s["say"] begin + @add_arg_table! s["say"] begin "what" help = "a positional argument" required = true diff --git a/test/argparse_test12.jl b/test/argparse_test12.jl index 0b58bba..d10c933 100644 --- a/test/argparse_test12.jl +++ b/test/argparse_test12.jl @@ -7,8 +7,8 @@ function ap_settings12() s = ArgParseSettings("Test 12 for ArgParse.jl", exc_handler = ArgParse.debug_handler) - add_arg_group(s, "mutually exclusive options", exclusive=true) - @add_arg_table s begin + add_arg_group!(s, "mutually exclusive options", exclusive=true) + @add_arg_table! s begin "--maybe", "-M" action = :store_true help = "maybe..." @@ -17,15 +17,15 @@ function ap_settings12() help = "maybe not..." end - add_arg_group(s, "required mutually exclusive options", "reqexc", exclusive=true, required=true) - @add_arg_table s begin + add_arg_group!(s, "required mutually exclusive options", "reqexc", exclusive=true, required=true) + @add_arg_table! s begin "--either", "-E" action = :store_true help = "choose the `either` option" end - add_arg_group(s, "required arguments", required=true) - @add_arg_table s begin + add_arg_group!(s, "required arguments", required=true) + @add_arg_table! s begin "--enhance", "-+" action = :store_true help = "set the enhancement option" @@ -35,8 +35,8 @@ function ap_settings12() "entries at once" end - set_default_arg_group(s, "reqexc") - @add_arg_table s begin + set_default_arg_group!(s, "reqexc") + @add_arg_table! s begin "--or", "-O" action = :store_arg arg_type = Int @@ -44,8 +44,8 @@ function ap_settings12() help = "set the `or` option" end - set_default_arg_group(s) - @add_arg_table s begin + set_default_arg_group!(s) + @add_arg_table! s begin "-k" action = :store_const default = 0 @@ -116,9 +116,9 @@ let s = ap_settings12() @ap_test_throws ap_test12(["-MO55", "A", "A", "--or-perhaps=?"]) @ap_test_throws ap_test12(["--enhanced", "-+MkO55", "A", "A", "--or-perhaps=?"]) # invalid arguments in mutually exclusive groups - @ee_test_throws @add_arg_table(s, "arg2", action = :store_arg, group = "reqexc") - set_default_arg_group(s, "reqexc") - @ee_test_throws @add_arg_table(s, "arg2", action = :store_arg) + @ee_test_throws @add_arg_table!(s, "arg2", action = :store_arg, group = "reqexc") + set_default_arg_group!(s, "reqexc") + @ee_test_throws @add_arg_table!(s, "arg2", action = :store_arg) end end diff --git a/test/common.jl b/test/common.jl index 5b8aae8..c0300af 100644 --- a/test/common.jl +++ b/test/common.jl @@ -21,7 +21,7 @@ end macro test_addtable_failure(ex...) ex = [nothing, ex...] - ex = Expr(:call, :macroexpand, @__MODULE__, Expr(:quote, Expr(:macrocall, Symbol("@add_arg_table"), ex...))) + ex = Expr(:call, :macroexpand, @__MODULE__, Expr(:quote, Expr(:macrocall, Symbol("@add_arg_table!"), ex...))) quote @test_throws LoadError $ex end