• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

yhttp / yhttp / 21939354711

12 Feb 2026 08:37AM UTC coverage: 95.714% (-4.3%) from 100.0%
21939354711

push

github

pylover
v7.1.0

1 of 1 new or added line in 1 file covered. (100.0%)

33 existing lines in 2 files now uncovered.

737 of 770 relevant lines covered (95.71%)

2.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

31.91
/yhttp/core/cli.py
1
import os
3✔
2
import sys
3✔
3
from wsgiref.simple_server import make_server
3✔
4

5
from easycli import Root, Argument, SubCommand
3✔
6

7

8
DEFAULT_ADDRESS = '8080'
3✔
9

10

11
class Serve(SubCommand):
3✔
12
    __command__ = 'serve'
3✔
13
    __aliases__ = ['s']
3✔
14
    __arguments__ = [
3✔
15
        Argument(
16
            '-b', '--bind',
17
            default=DEFAULT_ADDRESS,
18
            metavar='{HOST:}PORT',
19
            help='Bind Address. default: %s' % DEFAULT_ADDRESS
20
        ),
21
    ]
22

23
    def __call__(self, args):  # pragma: no cover
24
        """the no cover pragma was set, because the coverae meassurement in
25
        subprocess is so complicated, but this function is covered by
26
        test_builtincli.py.
27
        """
28
        host, port = args.bind.split(':')\
29
            if ':' in args.bind else ('localhost', args.bind)
30

31
        args.application.ready()
32
        httpd = make_server(host, int(port), args.application)
33
        print(f'Demo server started http://{host}:{port}')
34
        try:
35
            httpd.serve_forever()
36
        except KeyboardInterrupt:
37
            print("CTRL+C pressed.")
38
            args.application.shutdown()
39

40

41
class Main(Root):
3✔
42
    __completion__ = True
3✔
43
    __arguments__ = [
3✔
44
        Argument(
45
            '-c', '--configuration-file',
46
            metavar="FILE",
47
            dest='configurationfile',
48
            help='Configuration file',
49
        ),
50
        Argument(
51
            '-C',
52
            '--directory',
53
            default='.',
54
            help='Change to this path before starting, default is: `.`'
55
        ),
56
        Argument(
57
            '-O',
58
            '--option',
59
            action='append',
60
            default=[],
61
            help='Set a configutation entry: -O foo.bar.baz=\'qux\'. this '
62
                 'argument can passed multiple times.'
63
        ),
64
        Serve,
65
    ]
66

67
    def __init__(self, application):
3✔
UNCOV
68
        if application.version:
×
UNCOV
69
            self.__arguments__.append(
×
70
                Argument('--version', action='store_true')
71
            )
72

UNCOV
73
        self.application = application
×
UNCOV
74
        self.__help__ = f'{sys.argv[0]} command line interface.'
×
UNCOV
75
        self.__arguments__.extend(self.application.cliarguments)
×
UNCOV
76
        super().__init__()
×
77

78
    def _execute_subcommand(self, args):
3✔
UNCOV
79
        args.application = self.application
×
80

UNCOV
81
        if args.directory != '.':
×
UNCOV
82
            os.chdir(args.directory)
×
83

UNCOV
84
        if args.configurationfile:
×
UNCOV
85
            self.application.settings.loadfile(args.configurationfile)
×
86

UNCOV
87
        for o in args.option:
×
UNCOV
88
            try:
×
UNCOV
89
                key, value = o.split('=')
×
UNCOV
90
            except ValueError:
×
UNCOV
91
                print(f'Invalid option: -O/--option {o}', file=sys.stderr)
×
UNCOV
92
                self._parser.print_help()
×
UNCOV
93
                return 1
×
94

UNCOV
95
            yml = ''
×
UNCOV
96
            indent = 0
×
UNCOV
97
            for k in key.split('.'):
×
UNCOV
98
                if indent:
×
UNCOV
99
                    yml += f'\n{indent * " "}{k}:'
×
100
                else:
UNCOV
101
                    yml += f'{k}:'
×
102

UNCOV
103
                indent += 2
×
104

UNCOV
105
            yml += f' {value}'
×
UNCOV
106
            self.application.settings.merge(yml)
×
107

UNCOV
108
        return super()._execute_subcommand(args)
×
109

110
    def __call__(self, args):
3✔
UNCOV
111
        if self.application.version and args.version:
×
UNCOV
112
            print(self.application.version)
×
UNCOV
113
            return
×
114

UNCOV
115
        self._parser.print_help()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc