Module argparsejson.argparsejson

Functions

def getType(s: str)
Expand source code
def getType(s:str):
    if s is None:
        return

    if type(s) != str:
        return type(s)

    s = s.lower()

    if s == "int" or s == "integer":
        return int
    elif s == "bool" or s == "boolean":
        return bool
    elif s == "str" or s == "string":
        return str
    elif s == "float":
        return float
    else:
        return None
def parse_arguments(commands_file, prog=None, add_help=True)
Expand source code
def parse_arguments(commands_file, prog=None, add_help=True):
    if isinstance(commands_file, str):
        commands = json.load(open(os.path.abspath(commands_file), "r"))
    elif isinstance(commands_file, dict):
        commands = commands_file
    else:
        raise TypeError("Expected either parameter of type '{}' or '{}' for parameter '{}', but instead received type '{}'".format(str, dict, "commands_file", type(commands_file)))

    validate(instance=commands, schema=SCHEMA)

    parser = MyArgParser(prog=prog, add_help=add_help)

    _parse_args(parser, commands)

    _parse_subparsers(parser, commands)

    return parser

Classes

class MyArgParser (prog=None, add_help=True)
Expand source code
class MyArgParser(argparse.ArgumentParser):
    def __init__(self, prog=None, add_help=True):
        self.add_help=add_help
        super().__init__(prog=prog, add_help=add_help)

    def exit(self, status=0, message=None):
        if status:
            if self.add_help:
                super().exit(status=status, message=message)

Object for parsing command line strings into Python objects.

Keyword Arguments: - prog – The name of the program (default: os.path.basename(sys.argv[0])) - usage – A usage message (default: auto-generated from arguments) - description – A description of what the program does - epilog – Text following the argument descriptions - parents – Parsers whose arguments should be copied into this one - formatter_class – HelpFormatter class for printing help messages - prefix_chars – Characters that prefix optional arguments - fromfile_prefix_chars – Characters that prefix files containing additional arguments - argument_default – The default value for all arguments - conflict_handler – String indicating how to handle conflicts - add_help – Add a -h/-help option - allow_abbrev – Allow long options to be abbreviated unambiguously - exit_on_error – Determines whether or not ArgumentParser exits with error info when an error occurs

Ancestors

  • argparse.ArgumentParser
  • argparse._AttributeHolder
  • argparse._ActionsContainer

Methods

def exit(self, status=0, message=None)
Expand source code
def exit(self, status=0, message=None):
    if status:
        if self.add_help:
            super().exit(status=status, message=message)