Skip to content

Commit b082105

Browse files
committed
Remove -- from args after processing many positional arguments
1 parent a8a92b8 commit b082105

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/clip/arg.gleam

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,11 @@ fn run_many_aux(
187187
_ ->
188188
case run(arg, args) {
189189
Ok(#(a, rest)) -> run_many_aux([a, ..acc], arg, rest)
190-
Error(_) -> Ok(#(list.reverse(acc), args))
190+
Error(_) -> {
191+
let clean_args = list.drop_while(args, fn(a) { a == "--" })
192+
193+
Ok(#(list.reverse(acc), clean_args))
194+
}
191195
}
192196
}
193197
}

test/clip/arg_test.gleam

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,16 @@ pub fn float_test() {
9696

9797
assert result == Ok(i)
9898
}
99+
100+
pub fn run_many_does_not_leave_double_dash_test() {
101+
use cli_args <- qcheck.given(qcheck.generic_list(
102+
qcheck.non_empty_string(),
103+
qcheck.bounded_int(2, 5),
104+
))
105+
106+
let arg = arg.new("foo")
107+
108+
let result = arg.run_many(arg, ["--", ..cli_args])
109+
110+
assert result == Ok(#(cli_args, []))
111+
}

0 commit comments

Comments
 (0)