diff options
author | Ekaitz Zarraga <ekaitz@elenq.tech> | 2020-08-09 14:38:34 +0200 |
---|---|---|
committer | Ekaitz Zarraga <ekaitz@elenq.tech> | 2020-08-09 14:38:34 +0200 |
commit | aacf3313390ab07f36c817bcfb48c11813be4580 (patch) | |
tree | e932ea1807fcd6131e9da4abaed5451ab8021ddc | |
parent | 54e01779769bea931047c391070a985224107236 (diff) |
Multiple template type handling:
- Move json to an independent command
-rw-r--r-- | fracture/__main__.py | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/fracture/__main__.py b/fracture/__main__.py index 44f2518..e7c3381 100644 --- a/fracture/__main__.py +++ b/fracture/__main__.py @@ -135,17 +135,24 @@ def summarize(xlsx=False, year=None, quarter=None): @command def render(id, type=None, format=None): + + # TODO AUTOMATE TEMPLATE SEARCH AND THAT, THIS IS THIS FOR DEV + if format is None: + raise ValueError("No format specified") + invoice = Invoice.load(id, type) - if format == "json": - print(invoice.to_json()) + if invoice is None: + raise ValueError("No invoice found") - if format == "xelatex": - # TODO AUTOMATE TEMPLATE SEARCH AND THAT, THIS IS THIS FOR DEV - with open("templates/template.tex", "r") as f: - template_text = f.read() - template = Template(template_text) - if invoice is not None: - print(template.render(invoice=invoice.to_dict())) + with open("templates/template." + format, "r") as f: + template_text = f.read() + template = Template(template_text) + print(template.render(invoice=invoice.to_dict())) + +@command +def to_json(id, type=None): + invoice = Invoice.load(id, type) + print(invoice.to_json()) if __name__ == "__main__": load_config() @@ -185,10 +192,19 @@ if __name__ == "__main__": summary_parser.add_argument("--type", type=str, help="Invoice type", default="sent") summary_parser.add_argument("--format", type=str, - choices={"json", "xelatex"}, help="Invoice type", default="json") + help="Invoice type", default="tex") summary_parser.set_defaults(func=render) + # json + json_parser = subparsers.add_parser("json", aliases=["j"], + help="Dump chosen invoice in json format") + json_parser.add_argument("id", nargs="?", type=str, + help="Invoice identification string") + json_parser.add_argument("--type", type=str, + help="Invoice type", default="sent") + json_parser.set_defaults(func=to_json) + # parse args = parser.parse_args() args.func(args) |