Skip to content

Commit

Permalink
[internal] Add a way to append values to optional arguments in `parse…
Browse files Browse the repository at this point in the history
…_arguments` decorator (#1122)

Add support for the `append` action for ArgumentParser in the `parse_arguments` decorator on optional arguments.

This makes us able to support this:

```
command --arg 1 --arg 2 --arg 3
```

And get `[1, 2, 3]` as the `arg` value.

This CL is required to make changes to
#1120 before merging.

---------

Co-authored-by: crazy hugsy <[email protected]>
  • Loading branch information
ValekoZ and hugsy authored Jun 24, 2024
1 parent c450a2d commit 6ddd780
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,10 @@ def wrapper(*args: Any, **kwargs: Any) -> Callable:
elif argtype is bool:
parser.add_argument(*argname, action="store_false" if argvalue else "store_true")
continue
elif argtype in (list, tuple):
parser.add_argument(*argname, type=type(argvalue[0]),
default=[], action="append")
continue
parser.add_argument(*argname, type=argtype, default=argvalue)

parsed_args = parser.parse_args(*(args[1:]))
Expand Down

0 comments on commit 6ddd780

Please sign in to comment.