Skip to content

Flags

Flags are similar to options as they are referenced by name, but they can only represent a boolean value (True / False) and do not recieve an associated value.

Flags are defined by annotating an argument with the bool type.

examples/parameter_flag.py
import arc


@arc.command
def hello(firstname: str, reverse: bool):
    if reverse:
        firstname = firstname[::-1]

    arc.print(f"Hello, {firstname}! Hope you have a wonderful day!")


hello()
$ python parameter_flag.py Joseph
Hello, Joseph! Hope you have a wonderful day!
$ python parameter_flag.py Joseph --reverse
Hello, hpesoJ! Hope you have a wonderful day!

Default Values

Unlike arguments and options, flags are always optional. Thie is because they can only represent two possible values (True / False). Absence of the flag implies False; presence of the flag implies True. If a flag is given a default of True then this relationship is inversed.

Alternative Syntax

Once again, like arguments and options, flags also have an alternative syntax

reverse: bool

reverse = arc.Flag()
The bool type is no longer required, but it's still generally recommended

Check the reference for all the options that arc.Flag() can recieve