File: generator.py

package info (click to toggle)
crmsh 5.0.0~rc2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 7,792 kB
  • sloc: python: 50,329; sh: 1,207; makefile: 254; xml: 243; exp: 234; awk: 22
file content (51 lines) | stat: -rw-r--r-- 1,168 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from .parser import Parser

import typing
import re


class AsciiDocGenerator(Parser):
    USAGE_RE = re.compile('^usage:\\s*')

    def __init__(self, output: typing.Callable[[str], None]):
        self.output = output

    def on_usage(self, text: str):
        usage = text[self.USAGE_RE.match(text).end():]
        self.output('Usage:\n\n ')
        self.output(usage)
        self.output('\n\n')

    def on_paragraph(self, text: str):
        self.output(self.escape(text))
        self.output('\n\n')

    def enter_options(self):
        self.output('Options:\n\n')

    def exit_options(self):
        self.output('\n')

    def on_option(self, option: str, help: str):
        self.output('* `+++')
        self.output(option)
        self.output('+++`: ')
        self.output(self.escape(help))
        self.output('\n\n')

    def enter_option_group(self, name: str):
        self.output(name)
        self.output(':\n\n')

    def exit_option_group(self, name: str):
        self.output('\n')

    def enter_description(self):
        pass

    def exit_description(self):
        pass

    def escape(self, text: str):
        # TODO
        return text