Skip to content

Commit

Permalink
Relaxed macro ordering rules for help text to match documented behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmatson committed May 18, 2020
1 parent fc82d4c commit 981f7e9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/argsparsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ end
Convert string to Number type with parse or other type with direct conversion.
Quit program if s is nothing or conversion fails.
"""
function _converttype!(::Type{T}, s::Union{AbstractString, Nothing}, name::String)::T where T
function _converttype!(::Type{T}, s::Union{String, Nothing}, name::String)::T where T
if isnothing(s)
_quit_try_help("Argument $name missing")
end
Expand Down
22 changes: 1 addition & 21 deletions src/handleast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ Enforce argument declaration ordering:
Throw `ArgumentError` if ordering violates this rule.
"""
function _validateorder(block::Expr)
encountered_description = false
encountered_argument = false
encountered_positional = false
encoundered_optional_positional = false

Expand All @@ -26,30 +24,13 @@ function _validateorder(block::Expr)
# Fix namespace issues
macroname::Symbol = _get_macroname(arg)

if macroname == usage_symbol
if encountered_description || encountered_argument
throw(ArgumentError(
"Usage must be stated before description or arguments.\nFrom: $arg"
))
end
elseif macroname == description_symbol
encountered_description = true

if encountered_argument
throw(ArgumentError(
"Description must be stated before any arguments.\nFrom: $arg"
))
end
elseif macroname in flagged_symbols
encountered_argument = true

if macroname in flagged_symbols
if encountered_positional
throw(ArgumentError(
"Positional arguments must be declared after all flagged arguments.\nFrom: $arg"
))
end
elseif macroname == positional_required_symbol
encountered_argument = true
encountered_positional = true

if encoundered_optional_positional
Expand All @@ -58,7 +39,6 @@ function _validateorder(block::Expr)
))
end
elseif macroname in positional_optional_symbols
encountered_argument = true
encountered_positional = true
encoundered_optional_positional = true
end
Expand Down
4 changes: 2 additions & 2 deletions src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ macro argtest(argname::Symbol, func::Union{Symbol, Expr}, desc::Union{String, No
end

"""
@allowextraargs
@allowextraarguments
Disables the default behavior of printing a message and exiting
the program when not all values in `ARGS` could be assigned to
Expand All @@ -311,7 +311,7 @@ Must be used in `@beginarguments begin ... end` block
```julia
@beginarguments begin
...
@allowextraargs
@allowextraarguments
end
```
"""
Expand Down

2 comments on commit 981f7e9

@zachmatson
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:
Initial version

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/14939

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.0 -m "<description of version>" 981f7e9e57cd5d9a2e491e35127ca1817976eb12
git push origin v0.1.0

Please sign in to comment.