Skip to content

Duplo ArgType

This module contains the customizations to the Argparse library.

Arg

Bases: NewType

Duplo ArgType

A custom type for defining arguments in Duplo commands as annotations. This extends the NewType class so type hinting will work as expected and we get truly new types. Each instance of this class will be used to define a command line argument for a function. The values contained are the values needed for the argparse.ArgumentParser.add_argument method.

Example

Make a reusable arg type called foo

FOO = Arg("foo", "-f", help="A foo arg")

Parameters:

Name Type Description Default
name str

The name of the argument.

required
type Any

The type of the argument.

str
flags List[str]

The flag to use for the argument.

()
action str

The action to use for the argument.

None
nargs str

The number of arguments to use for the argument.

None
const str

The constant to use for the argument.

None
default any

The default value to use for the argument. This can be overriden by the default value of the arg in the function definition.

None
choices List[any]

The choices to use for the argument.

None
required bool

Whether the argument is required.

None
help str

The help text to use for the argument.

None
metavar tuple

The metavar to use for the argument.

None
dest str

The destination to use for the argument.

None
version bool

The version to use for the special version arg.

None
env str

The environment variable to use for the argument.

None

JsonPatchAction

Bases: _AppendAction

Json Patch Action

A custom argparse action that translates JSON Patch operations from the command line arguments.

YamlAction

Bases: Action

Yaml Action

A custom action for argparse that loads a yaml file into a python object. This is intended to be used alongside the File type in argparse. This way the file type (yaml) is enforced.