-
Notifications
You must be signed in to change notification settings - Fork 22
/
dump_config_schema.py
40 lines (31 loc) · 1.66 KB
/
dump_config_schema.py
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
import argparse
import json
import logging
from lightbus.commands.utilities import BusImportMixin, LogLevelMixin
from lightbus.config.config import config_as_json_schema
from lightbus.schema.encoder import json_encode
logger = logging.getLogger(__name__)
class Command(LogLevelMixin, BusImportMixin, object):
def setup(self, parser, subparsers):
parser_shell = subparsers.add_parser('dumpconfigschema',
help="Dumps the lightbus configuration json schema. Can be useful "
"in validating your config. This is not the same as your"
"bus' API schema, for that see the more commonly used 'dumpschema' "
"command",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser_shell.add_argument('--schema', '-m',
help='File to write config schema to. '
'If omitted schema will be written to standard out.',
metavar='FILE',
)
self.setup_import_parameter(parser_shell)
parser_shell.set_defaults(func=self.handle)
def handle(self, args, config):
self.setup_logging(args.log_level or 'warning', config)
self.import_bus(args)
schema = json_encode(config_as_json_schema(), indent=2, sort_keys=True)
if args.schema:
with open(args.schema, 'w', encoding='utf8') as f:
f.write(schema)
else:
print(schema)