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

Allow default values convertible to arg_type #123

Closed
baumgold opened this issue Jun 8, 2023 · 0 comments · Fixed by #133
Closed

Allow default values convertible to arg_type #123

baumgold opened this issue Jun 8, 2023 · 0 comments · Fixed by #133

Comments

@baumgold
Copy link

baumgold commented Jun 8, 2023

Currently default values that are not of the same type as the arg_type are disallowed. This is overly restrictive and could be relaxed to allow default values that can be automatically converted to arg_type. For example, I believe the following should be supported but it currently throws an error:

julia> using ArgParse, Dates

julia> s = ArgParseSettings();

julia> @add_arg_table s begin
           "--foo"
           arg_type = Second
           default = Minute(1)
       end
ERROR: typeof(default)=Minute is incompatible with arg_type=Second)
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] check_default_type(default::Minute, arg_type::Type)
   @ ArgParse ~/.julia/packages/ArgParse/bylyV/src/settings.jl:501
 [3] add_arg_field!(settings::ArgParseSettings, name::Union{Vector{T}, T} where T<:AbstractString; desc::Base.Pairs{Symbol, V, Tuple{Vararg{Symbol, N}}, NamedTuple{names, T}} where {V, N, names, T<:Tuple{Vararg{Any, N}}})
   @ ArgParse ~/.julia/packages/ArgParse/bylyV/src/settings.jl:1055
 [4] top-level scope
   @ ~/.julia/packages/ArgParse/bylyV/src/settings.jl:841

Note the following works fine:

julia> @add_arg_table s begin
           "--foo"
           arg_type = Second
           default = convert(Second, Minute(1))
       end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant