Skip to content

Commit

Permalink
print unparsed arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
0382 committed May 4, 2024
1 parent 4373d34 commit ee85769
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
build/
.vscode/
*.mod
*.mod
*.exe
*.obj
10 changes: 10 additions & 0 deletions src/argparse-f.f90
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ subroutine argp_parse(this)
tok(1:value_len - 1) = tok(2:value_len)
do i = 1, len_trim(tok)
idx = this%short_name_index(ichar(tok(i:i)))
if (idx == default_index_value) then
error stop "(parse error) unrecognized short name option '-"//tok(i:i)//"' in -"//trim(tok)
end if
! short circuit option
if (idx <= this%sc_option_size .and. this%sc_options(idx)%short_name(2:2) == tok(i:i)) then
if (associated(this%sc_options(idx)%callback, dummy_print_help_wrapper)) then
Expand Down Expand Up @@ -262,6 +265,13 @@ subroutine argp_parse(this)
! start parse position argument
if (argc /= this%argument_size) then
print '(A,I0,A,I0)', "(parse error) position argument number missmatching, give ", argc, ", but need ", this%argument_size
if (argc /= 0) then
write (*, '("unparsed arguments: ")', advance='no')
do i = 1, argc
write (*, '(" ",A)', advance='no') trim(tokens(i))
end do
print *
end if
error stop
end if
do i = 1, this%argument_size
Expand Down

0 comments on commit ee85769

Please sign in to comment.