Coverage for appr/commands/jsonnet.py: 37%

# Coverage for appr/commands/jsonnet.py : 37%

## 35 statements 13 run 22 missing 0 excluded

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

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 | import os import json import argparse from appr.commands.command_base import CommandBase, LoadVariables from appr.render_jsonnet import RenderJsonnet class JsonnetCmd(CommandBase): name = 'jsonnet' help_message = "Resolve a jsonnet file" def __init__(self, options): super(JsonnetCmd, self).__init__(options) self.namespace = options.namespace self.variables = options.variables self.filepath = options.filepath[0] self.extra_libs = options.lib_dir self.raw = options.raw self.result = None @classmethod def _add_arguments(cls, parser): parser.add_argument("--namespace", help="kubernetes namespace", default='default') parser.add_argument("-x", "--variables", help="variables", default={}, action=LoadVariables) parser.add_argument('filepath', nargs=1, help="Fetch package from the registry") parser.add_argument('--raw', action="store_true", default=False, help=argparse.SUPPRESS) parser.add_argument('-J', '--lib-dir', action='append', default=[], help="Specify an additional library search dir") def _call(self): r = RenderJsonnet(manifestpath=self.filepath, lib_dirs=self.extra_libs) if os.path.basename(self.filepath) == "manifest.jsonnet" and not self.raw: namespace = self.namespace self.variables['namespace'] = namespace tla_codes = {"params": json.dumps({"variables": self.variables})} else: tla_codes = self.variables p = open(self.filepath).read() self.result = r.render_jsonnet(p, tla_codes=tla_codes) def _render_dict(self): return self.result def _render_console(self): return json.dumps(self._render_dict(), indent=2, separators=(',', ': '))