Actions
clap.ArgAction
Bases: StrEnum
Classes:
-
Help–When encountered, display help information.
-
HelpLong–When encountered, display long help information.
-
HelpShort–When encountered, display short help information.
-
Version–When encountered, display version information.
Attributes:
-
Append–When encountered, store the associated value(s) in a
list. -
Count–When encountered, increment an
intcounter starting from0. -
Set–When encountered, store the associated value(s).
-
SetFalse–When encountered, act as if
Falsewas encountered on the command-line. -
SetTrue–When encountered, act as if
Truewas encountered on the command-line.
Append
class-attribute
instance-attribute
Append = 'append'
When encountered, store the associated value(s) in a list.
Example:
import clap
from clap import ArgAction, long
@clap.command
class Cli(clap.Parser):
files: list[str] = arg(long, action=ArgAction.Append)
args = Cli.parse(["--files", "a.txt", "--files", "b.txt"])
assert args.files == ["a.txt", "b.txt"]
args = Cli.parse([])
assert args.files == []
Count
class-attribute
instance-attribute
Count = 'count'
When encountered, increment an int counter starting from 0.
Example:
import clap
from clap import ArgAction, short
@clap.command
class Cli(clap.Parser):
verbose: int = arg(short, action=ArgAction.Count)
args = Cli.parse(["-vvv"])
assert args.verbose == 3
args = Cli.parse([])
assert args.verbose == 0
Set
class-attribute
instance-attribute
Set = 'store'
When encountered, store the associated value(s).
Example:
import clap
from clap import ArgAction, long
@clap.command
class Cli(clap.Parser):
output: str = arg(long, action=ArgAction.Set)
args = Cli.parse(["--output", "file.txt"])
assert args.output == "file.txt"
SetFalse
class-attribute
instance-attribute
SetFalse = 'store_false'
When encountered, act as if False was encountered on the command-line.
Example:
import clap
from clap import ArgAction, long
@clap.command
class Cli(clap.Parser):
quiet: bool = arg(long, action=ArgAction.SetFalse)
args = Cli.parse(["--quiet"])
assert args.quiet == False
args = Cli.parse([])
assert args.quiet == True
SetTrue
class-attribute
instance-attribute
SetTrue = 'store_true'
When encountered, act as if True was encountered on the command-line.
Example:
import clap
from clap import ArgAction, long
@clap.command
class Cli(clap.Parser):
verbose: bool = arg(long, action=ArgAction.SetTrue)
args = Cli.parse(["--verbose"])
assert args.verbose == True
args = Cli.parse([])
assert args.verbose == False
Help
Bases: Action
When encountered, display help information.
Depending on the flag, long_help may be shown.
Source code in clap/core.py
148 149 | |
HelpLong
Bases: Action
When encountered, display long help information.
Source code in clap/core.py
174 175 | |
HelpShort
Bases: Action
When encountered, display short help information.
Source code in clap/core.py
163 164 | |
Version
Version(option_strings, dest, **kwargs)
Bases: Action
When encountered, display version information.
Depending on the flag, long_version may be shown.
Source code in clap/core.py
130 131 | |