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

DataMapAction

Bases: Action

Data Map Action

A custom argparse action which allows for making key/value pairs from either literal values or files. This is fashioned after the kubectl params for secrets and configmaps, where you can specify a file or a literal value.

For files you specify --from-file <file name> which will use the file name as the key and the contents of the file as the value. If you want to change the name of the key, then simply specify --from-file <key>=<file name>. If you want to use stdin, then use --from-file - which will use "stdin" as the key. You can even do --from-file foo.txt=- to use stdin and name the key.

For literal values you specify --from-literal <key>=<value>. This will create a key/value pair in the data map. In this case the key and value must always be specified.

JsonPatchAction

Bases: _AppendAction

Json Patch Action

A custom argparse action that translates JSON Patch operations from the command line arguments. This allows users to specify operations like add, remove, copy, replace, test, and move directly in the command line.

To add a key/value pair, use --add <key> <value>. To remove a key, use --remove <key>. To copy a key from one path to another, use --copy <from> <to>. To replace a key's value, use --replace <key> <value>. To test a key's value, use --test <key> <value>. To move a key from one path to another, use --move <from> <to>.

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.