Skip to content

Commit 17e175f

Browse files
authored
Merge pull request #107 from Goddard-Fortran-Ecosystem/hotfix/#105-greedy-plus
Fixes #105
2 parents d7f63db + a2bf82f commit 17e175f

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.12)
22

33
project (FARGPARSE
44

5-
VERSION 1.3.0
5+
VERSION 1.3.1
66
LANGUAGES Fortran)
77

88
# Most users of this software do not (should not?) have permissions to

ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [1.3.1] 2022-09-15
11+
12+
### Fixed
13+
14+
- Fixed problem where `narguments='+'` was too greedy and absorbed all remaining arguments. (Issue #105) Reproducing unit test added.
15+
1016
## [1.3.0] 2022-06-02
1117

1218
### Changed

src/ArgParser.F90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,13 @@ subroutine handle_option(this, action, argument, iter, end, embedded_value, args
476476
if (n_arguments == '+' .and. iter == end) then
477477
! TODO: throw exception. '+' requires at least one value
478478
end if
479+
479480
do while (iter /= end)
480481
argument => iter%get()
482+
if (argument(1:1) == '-') then
483+
call iter%previous()
484+
exit
485+
end if
481486

482487
select case (action%get_type())
483488
case ('string')

tests/Test_ArgParser.pf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,4 +601,35 @@ contains
601601

602602
end subroutine test_unprocessed_argument
603603

604+
! Reproducer for issue #105
605+
@test
606+
subroutine test_greedy_plus
607+
use fp_CommandLineArguments
608+
use fp_String
609+
type (ArgParser) :: p
610+
type (StringVector) :: arguments
611+
type (StringUnlimitedMap) :: options
612+
class(*), pointer :: opt
613+
type(StringVector) :: p_vals
614+
615+
p = ArgParser()
616+
call p%add_argument('-p','--potential',type='string',n_arguments='+',help='...')
617+
call p%add_argument('-q','--query',type='string',help='...')
618+
619+
call arguments%push_back('-p')
620+
call arguments%push_back('s1')
621+
call arguments%push_back('s2')
622+
call arguments%push_back('s3')
623+
call arguments%push_back('-q')
624+
call arguments%push_back('hello')
625+
options = p%parse_args(arguments)
626+
@assert_that(int(options%size()), is(2))
627+
628+
call cast(options%at('potential'), p_vals)
629+
@assert_that(int(p_vals%size()), is(3))
630+
@assertEqual('s1', p_vals%of(1))
631+
@assertEqual('s2', p_vals%of(2))
632+
@assertEqual('s3', p_vals%of(3))
633+
634+
end subroutine test_greedy_plus
604635
end module Test_ArgParser

0 commit comments

Comments
 (0)