Multiple Values
arc allows you to collect multiple values from the command line into a single argument for your comamnd. To do this, you use the collection types: list
, set
and tuple
list
¶
list_argument.py
Because import arc
@arc.command()
def main(names: list):
for name in names:
arc.print(name)
main()
list
can accept any number of values, you won't be able to add additional arguments after names
. Any other positional arguments would have to come before names
.
set
¶
Similar to list
, but will filter out any non-unique elements.
set_argument.py
import arc
@arc.command()
def main(vals: set):
arc.print("Unique values:")
arc.print("\n".join(vals))
main()
tuple
¶
Similar to list
, but with some additional functionality.
According to PEP 484:
tuple
represents an arbitrarily sized tuple of any type. In arc, this will behave the same aslist
tuple[int, ...]
represents an arbitrarily sized tuple of integers. In arc, this will behave the same aslist[int]
tuple[int, int]
represents a size-two tuple of integers. In arc, this behavior is unique totuple
as the parameter will only select 2 values from input.
Sub Typing¶
Collections can be sub-typed so that each item will be converted to the proper type:
sum.py
import arc
@arc.command()
def main(nums: list[int]):
arc.print("The total is: ", sum(nums))
main()
Collections as Options¶
When used as an option, it allows the option to be used multiple times: