ezflags package

ezflags.flagparser module

class ezflags.flagparser.FlagParser(program_name: str = None, description: str = None, epilogue: str = None, prefix_chars: str = None, debug: bool = False, debug_file=None)

Bases: object

This is the main class for parsing flags.

Parameters:
  • program_name (str, optional) – The name of the program. Defaults to sys.argv[0]
  • description (str, optional) – The message to display before the arguments.
  • epilogue (str, optional) – The message to display at the end of the help message
  • prefix_chars (str, optional) – The prefix of each argument. Defaults to ‘-‘
  • debug (bool, optional) – Turns on or off debug mode. Defaults to false.
  • debug_file (file, optional) – The file to write to in debug mode. Needs to be a file object as returned by open. Defaults to :class`sys.stdout`.
flags

A dictionary of flags and their values. For example:

{"--flag, -f": True}
add_flag(*args, value: bool, help: str = None)

Add a flag to the parser.

Parameters:
  • args (str) – Things to name the flag. Maximum of two values.
  • value (bool) – The value of the flag when present.
  • help (str, optional) – A brief description of the flag. These descriptions will be displayed when the -h or –help flags are present.
parse_flags(flag_list: List[str] = None)

Parse the flag inputs. Returns an object with the values of each flag. See Parsing flags for more info.

Parameters:flag_list (list, optional) – List of flags to parse. This can be used for testing. Defaults to sys.argv[1:].
Returns:Returns an object containing the values of all the flags.
Return type:_ParsedObj
class ezflags.ext.exflagparser.FlagParserExtended(program_name: str = None, description: str = None, epilogue: str = None, prefix_chars: str = None, debug: bool = False, debug_file=None)

Bases: argparse.ArgumentParser

This is the class for using flags and argparse arguments in conjunction. It uses the same parameters as FlagParser.

Parameters:
  • program_name (str, optional) – The name of the program. Defaults to sys.argv[0]
  • description (str, optional) – The message to display before the arguments.
  • epilogue (str, optional) – The message to display at the end of the help message
  • prefix_chars (str, optional) – The prefix of each argument. Defaults to ‘-‘
  • debug (bool, optional) – Turns on or off debug mode. Defaults to false.
  • debug_file (file, optional) – The file to write to in debug mode. Needs to be a file object as returned by open. Defaults to :class`sys.stdout`.
flags

A dictionary of flags and their values. For example:

{"--flag, -f": True}
add_flag(*args, value: bool, help: str = None, required: bool = False)

Add a flag to the parser.

Parameters:
  • args (str) – Things to name the flag. Maximum of two values.
  • value (bool) – The value of the flag when present.
  • required (bool, optional) – Whether the flag is required for the script to run. Defaults to False.
  • help (str, optional) – A brief description of the flag. These descriptions will be displayed when the -h or –help flags are present.
parse_flags(flag_list: List[str] = None) → argparse.Namespace

Parse the flag inputs. Returns an argparse.Namespace object with each flag. See Parsing flags for more info.

Parameters:flag_list (list, optional) – List of flags to parse. This can be used for testing. Defaults to sys.argv[1:].
Returns:Returns an object containing the values of all the flags.
Return type:Instance of argparse.Namespace