Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option dont_prefill_defaults to ArgParseSettings #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/ArgParse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ This is the list of general settings currently available:
```

The module also provides a function `ArgParse.debug_handler` (not exported) which will just rethrow the error.
* `dont_prefill_defaults` (default = `false`): if `true`, the dictionary returned by [`parse_args`](@ref)
will only contain the entries corresponding to the options present in the given argument list.

Here is a usage example:

Expand Down Expand Up @@ -284,6 +286,7 @@ type ArgParseSettings
exc_handler::Function
preformatted_description::Bool
preformatted_epilog::Bool
dont_prefill_defaults::Bool

function ArgParseSettings(;prog::AbstractString = Base.source_path() != nothing ? basename(Base.source_path()) : "",
description::AbstractString = "",
Expand All @@ -301,6 +304,7 @@ type ArgParseSettings
exc_handler::Function = default_handler,
preformatted_description::Bool=false,
preformatted_epilog::Bool=false,
dont_prefill_defaults::Bool=false,
)
fromfile_prefix_chars = check_prefix_chars(fromfile_prefix_chars)
return new(
Expand All @@ -309,6 +313,7 @@ type ArgParseSettings
suppress_warnings, allow_ambiguous_opts, commands_are_required,
copy(std_groups), "", ArgParseTable(), exc_handler,
preformatted_description, preformatted_epilog,
dont_prefill_defaults
)
end
end
Expand Down Expand Up @@ -1886,9 +1891,11 @@ type ParserState
out_dict::Dict{String,Any}
function ParserState(args_list::Vector, settings::ArgParseSettings, truncated_shopts::Bool)
out_dict = Dict{String,Any}()
for f in settings.args_table.fields
(f.action == :show_help || f.action == :show_version) && continue
out_dict[f.dest_name] = deepcopy(f.default)
if !settings.dont_prefill_defaults
for f in settings.args_table.fields
(f.action == :show_help || f.action == :show_version) && continue
out_dict[f.dest_name] = deepcopy(f.default)
end
end
new(deepcopy(args_list), false, nothing, nothing, false, 0, Set{AbstractString}(), nothing, truncated_shopts, out_dict)
end
Expand Down