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]