From cd52d0be38efa6ecc155a316d38ca1a7c2ec613d Mon Sep 17 00:00:00 2001 From: whut Date: Thu, 23 Jun 2022 16:32:22 -0500 Subject: [PATCH] oh yeah let's not crash on basic mistakes --- noble.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/noble.py b/noble.py index 3acec2b..ff7a00c 100755 --- a/noble.py +++ b/noble.py @@ -1,13 +1,20 @@ #!/usr/bin/env python3 import pystache, sys, yaml +def DieIf(cond, *message, **kwargs): + if cond: + print(sys.argv[0] + ":", *message, **kwargs) + sys.exit(1) + inData = yaml.safe_load(sys.stdin.read()) +DieIf(len(sys.argv)==1, "no template specified") template = open(sys.argv[1], 'r').read() data = {'scheme-name': inData.get('scheme', 'Untitled'), 'scheme-author': inData.get('author', 'Anonymous'), 'scheme-slug': ''} for i in ["base%02X" % x for x in range(16)]: + DieIf(i not in inData, "missing color %s" % i) colorHex = [inData[i][x*2:x*2+2] for x in range(3)] color = [int(x, 16) for x in colorHex] data[i + "-hex"] = inData[i]