confu.cli
functions that allow you to generate CLI parameters from a confu schema for argparse or click
Functions
apply_arg
def apply_arg(original_key, args, config)
Function for applying arguments to a config. Applies to nested configs as well.
Arguments
- original_key (
str): the name of the argument in the argparse Namespace - args (
argparse.Namespace): the entire Namespace, ie the result of the parser - config (
Config): the config object
apply_argparse
def apply_argparse(args, config)
Takes the output of a parser and applies it to a Config object.
Arguments
- args (
argparse.Namespace): the result of parser.parse_args() - config (
Config): the config object
Returns
- config (
Config): now updated with args
argparse_options
def argparse_options(parser, schema, defaults=None, attributes=None, default_from_schema=True)
Add cli options to an argparse ArgumentParser instance
Arguments
- parser (
argparse.ArgumentParser) - schema (
Schema)
Keyword Arguments
- defaults (
dict): if specified will override defaults from here - attributes (
list<str>): can hold a list of attribute names. if specified only matching attributes will be aded - default_from_schema (
bool): determines if defaults for argparser should come from the schema
destination_name
def destination_name(path, delimiter=__)
Returns a cli option destination name from attribute path
Arguments
- path (
list): attribute path - delimiter (
str): delimiter for nested attributes
Returns
cli destination name (str)
option_name
def option_name(path, delimiter=--)
Returns a cli option name from attribute path
Arguments
- path (
list): attribute path - delimiter (
str): delimiter for nested attributes
Returns
cli option name (str)
Classes
click_options
click_options(builtins.object)
Add cli options to a click decorated function
Use like a decorator
Arguments
- schema (
Schema)
Keyword Arguments
- defaults (
dict): if specified will override defaults from here - attributes (
list<str>): can hold a list of attribute names. if specified only matching attributes will be aded
Methods
__call__
def __call__(self, fn)
Call self as a function.
__init__
def __init__(self, schema, defaults=None, attributes=None)
Initialize self. See help(type(self)) for accurate signature.