Generate YAML: Specify scalar number as argument
from uuid import uuid4
from random import choice, randint, random
+from sys import argv, stderr
-def generate_yaml(chance_key=0.7, number_scalars=10000):
+def usage(name=argv[0]):
+ print("Usage: {} [count]".format(name), file=stderr)
+
+
+def generate_yaml(number_scalars=100000, chance_key=0.7):
indentation = 0
last_was_value = True # We have to start with a key
print('generated:')
@@ -30,4 +35,20 @@ def generate_yaml(chance_key=0.7, number_scalars=10000):
if __name__ == '__main__':
- generate_yaml()
+ if len(argv) > 2:
+ usage()
+ exit(1)
+
+ if len(argv) == 2:
+ try:
+ count = int(argv[1])
+ if count < 0:
+ raise ValueError
+ except ValueError:
+ usage()
+ exit(1)
+ else:
+ count = 10
+
+ if count > 0:
+ generate_yaml(count)
