From ee85769a350bf82190d0f2d50a0aa99e2d7beab8 Mon Sep 17 00:00:00 2001 From: jinshaoliang <18322825326@163.com> Date: Sat, 4 May 2024 09:51:48 +0800 Subject: [PATCH] print unparsed arguments --- .gitignore | 4 +++- src/argparse-f.f90 | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5a89f9c..3e12e7a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ build/ .vscode/ -*.mod \ No newline at end of file +*.mod +*.exe +*.obj diff --git a/src/argparse-f.f90 b/src/argparse-f.f90 index b1b3771..0996927 100644 --- a/src/argparse-f.f90 +++ b/src/argparse-f.f90 @@ -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 @@ -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