Esempio n. 1
0
    def options():
        def get_delimiter(parser, action):
            if action.nargs == 0:
                return None
            fmt = parser._get_formatter()  # pylint: disable=protected-access
            usage = fmt._format_actions_usage([action], [])  # pylint: disable=protected-access
            option_string = action.option_strings[0]
            idx = usage.find(option_string)
            if idx == -1:
                return None
            return usage[idx + len(option_string)]

        parser = CLI.build_parser()
        result = []
        actions = parser._get_optional_actions(
        ) + parser._get_positional_actions()  # pylint: disable=protected-access
        for action in actions:
            if not action.option_strings:
                continue
            delimiter = get_delimiter(parser, action) or ''
            result.append(
                dict(options=[
                    o + delimiter.strip() for o in action.option_strings
                ],
                     choices=action.choices or []))
        return result
Esempio n. 2
0
 def generate(cls):
     result = cls.DESCRIPTION + ['']
     parser = CLI.build_parser()
     result.append('[general]')
     for action in parser._get_optional_actions():  # pylint: disable=protected-access
         if action.help is SUPPRESS:
             continue
         fmt = parser._get_formatter()  # pylint: disable=protected-access
         opts = action.option_strings
         if len(opts) > 1:
             opts.pop(0)
         name = opts[0].lstrip('-')
         if name in cls.BLACKLIST:
             continue
         value = getattr(action, 'actual_default', None)
         if isinstance(value, list):
             value = ','.join(value)
         args = fmt._format_args(action, action.dest.upper())  # pylint: disable=protected-access
         result.append('')
         result.append('# {}'.format(fmt._expand_help(action)))  # pylint: disable=protected-access
         if args:
             result.append('# synopsis: {} = {}'.format(name, args))
         result.append('{} = {}'.format(name,
                                        value if value is not None else ''))
     return '\n'.join(result)
Esempio n. 3
0
 def options():
     def get_delimiter(parser, action):
         if action.nargs == 0:
             return None
         fmt = parser._get_formatter()  # pylint: disable=protected-access
         usage = fmt._format_actions_usage([action], [])  # pylint: disable=protected-access
         option_string = action.option_strings[0]
         idx = usage.find(option_string)
         if idx == -1:
             return None
         return usage[idx + len(option_string)]
     parser = CLI.build_parser()
     result = []
     actions = parser._get_optional_actions() + parser._get_positional_actions()  # pylint: disable=protected-access
     for action in actions:
         if not action.option_strings:
             continue
         delimiter = get_delimiter(parser, action) or ''
         result.append(dict(
             options=[o + delimiter.strip() for o in action.option_strings],
             choices=action.choices or []))
     return result
 def generate(cls):
     result = cls.DESCRIPTION + ['']
     parser = CLI.build_parser()
     result.append('[general]')
     for action in parser._get_optional_actions():  # pylint: disable=protected-access
         if action.help is SUPPRESS:
             continue
         fmt = parser._get_formatter()  # pylint: disable=protected-access
         opts = action.option_strings
         if len(opts) > 1:
             opts.pop(0)
         name = opts[0].lstrip('-')
         if name in cls.BLACKLIST:
             continue
         value = getattr(action, 'actual_default', None)
         if isinstance(value, list):
             value = ','.join(value)
         args = fmt._format_args(action, action.dest.upper())  # pylint: disable=protected-access
         result.append('')
         result.append('# {}'.format(fmt._expand_help(action)))  # pylint: disable=protected-access
         if args:
             result.append('# synopsis: {} = {}'.format(name, args))
         result.append('{} = {}'.format(name, value if value is not None else ''))
     return '\n'.join(result)