How to use the docopt.Option.parse function in docopt

To help you get started, we’ve selected a few docopt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github docopt / docopt.c / docopt.py View on Github external
def parse_defaults(doc):
    defaults = []
    for s in parse_section('options:', doc):
        # FIXME corner case "bla: options: --foo"
        _, _, s = s.partition(':')  # get rid of "options:"
        split = re.split('\n *(-\S+?)', '\n' + s)[1:]
        split = [s1 + s2 for s1, s2 in zip(split[::2], split[1::2])]
        options = [Option.parse(s) for s in split if s.startswith('-')]
        defaults += options
    return defaults
github sloria / konch / docopt.py View on Github external
def parse_defaults(doc):
    defaults = []
    for s in parse_section('options:', doc):
        # FIXME corner case "bla: options: --foo"
        _, _, s = s.partition(':')  # get rid of "options:"
        split = re.split('\n[ \t]*(-\S+?)', '\n' + s)[1:]
        split = [s1 + s2 for s1, s2 in zip(split[::2], split[1::2])]
        options = [Option.parse(s) for s in split if s.startswith('-')]
        defaults += options
    return defaults
github boutiques / boutiques / tools / python / boutiques / importer.py View on Github external
def loadDescriptionAndType(self):
        # using docopt code to extract description and type from args
        for line in (self._parse_section('arguments:', self.docopt_str) +
                     self._parse_section('options:', self.docopt_str)):
            _, _, s = line.partition(':')  # get rid of "options:"
            split = re.split(r'\n[ \t]*(-\S+?)', '\n' + s)[1:] if\
                line in self._parse_section('options:', self.docopt_str) else\
                re.split(r'\n[ \t]*(<\S+?)', '\n' + s)[1:]
            split = [s1 + s2 for s1, s2 in zip(split[::2], split[1::2])]
            # parse each line of Arguments and Options
            for arg_str in [s for s in split if (s.startswith('-') or
                                                 s.startswith('<'))]:
                arg = Option.parse(arg_str) if arg_str.startswith('-')\
                    else Argument.parse(arg_str)
                arg_segs = arg_str.partition('  ')
                # Add desc and type to all_desc_and_type
                # key is initial id/name
                self.all_desc_and_type[arg.name] = {
                    "desc": arg_segs[-1].replace('\n', ' ')
                                        .replace("  ", '').strip()}
                if hasattr(arg, "value") and arg.value is not None and\
                   arg.value is not False:
                    self.all_desc_and_type[arg.name]['default-value'] =\
                        arg.value
                if type(arg) is Option and arg.argcount > 0:
                    for typ in [seg for seg in arg_segs[0]
                                .replace(',', ' ')
                                .replace('=', ' ')
                                .split() if seg[0] != "-"]:
github boutiques / boutiques / tools / python / boutiques / util / docoptHelper.py View on Github external
def loadDescriptionAndType(self):
        # using docopt code to extract description and type from args
        for line in (dcpt.parse_section('arguments:', self.docopt_str) +
                     dcpt.parse_section('options:', self.docopt_str)):
            _, _, s = line.partition(':')  # get rid of "options:"
            split = re.split('\n[ \t]*(-\S+?)', '\n' + s)[1:] if\
                line in dcpt.parse_section('options:', self.docopt_str) else\
                re.split('\n[ \t]*(<\S+?)', '\n' + s)[1:]
            split = [s1 + s2 for s1, s2 in zip(split[::2], split[1::2])]
            # parse each line of Arguments and Options
            for arg_str in [s for s in split if (s.startswith('-') or
                            s.startswith('<'))]:
                arg = dcpt.Option.parse(arg_str) if arg_str.startswith('-')\
                    else dcpt.Argument.parse(arg_str)
                arg_segs = arg_str.partition('  ')
                self.all_desc_and_type[arg.name] = {
                    "desc": arg_segs[-1].replace('\n', ' ')
                                        .replace("  ", '').strip()}
                if hasattr(arg, "value") and arg.value is not None and\
                   arg.value is not False:
                    self.all_desc_and_type[arg.name]['default'] = arg.value
                if type(arg) is dcpt.Option and arg.argcount > 0:
                    for typ in [seg for seg in arg_segs[0]
                                .replace(',', ' ')
                                .replace('=', ' ')
                                .split() if seg[0] != "-"]:
                        self.all_desc_and_type[arg.name]["type"] = typ