diff --git a/frontends/src/jp/base.py b/frontends/src/jp/base.py index 673db5fb..0a248085 100644 --- a/frontends/src/jp/base.py +++ b/frontends/src/jp/base.py @@ -318,6 +318,24 @@ class Jp(object): 'description': description } + def parse_output_options(self): + options = self.command.args.output_opts + options_dict = {} + for option in options: + try: + key, value = option.split(u'=', 1) + except ValueError: + key, value = option, None + options_dict[key.strip()] = value.strip() if value is not None else None + return options_dict + + def check_output_options(self, accepted_set, options): + if not accepted_set.issuperset(options): + self.disp(u"The following output options are invalid: {invalid_options}".format( + invalid_options = u', '.join(set(options).difference(accepted_set))), + error=True) + self.quit(C.EXIT_BAD_ARG) + def import_plugins(self): """Automaticaly import commands and outputs in jp diff --git a/frontends/src/jp/output_template.py b/frontends/src/jp/output_template.py index 3f9c2225..6081c7fd 100644 --- a/frontends/src/jp/output_template.py +++ b/frontends/src/jp/output_template.py @@ -39,16 +39,6 @@ class Template(object): jp.register_output(C.OUTPUT_COMPLEX, TEMPLATE, self.render) self.renderer = template.Renderer(jp) - def parse_options(self, options): - options_dict = {} - for option in options: - try: - key, value = option.split(u'=', 1) - except ValueError: - key, value = option, None - options_dict[key.strip()] = value.strip() if value is not None else None - return options_dict - def render(self, data): """render output data using requested template @@ -60,12 +50,8 @@ class Template(object): data to a dict usable by the template. """ cmd = self.host.command - options = self.parse_options(cmd.args.output_opts) - if not OPTIONS.issuperset(options): - self.host.disp(u"The following output options are invalid: {invalid_options}".format( - invalid_options = u', '.join(set(options).difference(OPTIONS))), - error=True) - self.host.quit(C.EXIT_BAD_ARG) + options = self.host.parse_output_options() + self.host.check_output_options(OPTIONS, options) try: template_path = cmd.TEMPLATE except AttributeError: