diff validateyaml/main.py @ 0:c00f27542710

initial commit
author Jeff Hammel <k0scist@gmail.com>
date Tue, 01 Nov 2016 16:06:13 -0700
parents
children 99c252285817
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/validateyaml/main.py	Tue Nov 01 16:06:13 2016 -0700
@@ -0,0 +1,43 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+validate yaml
+"""
+
+# imports
+import argparse
+import sys
+import yaml
+
+class ValidateYAMLParser(argparse.ArgumentParser):
+    """CLI option parser"""
+    def __init__(self, **kwargs):
+        kwargs.setdefault('formatter_class', argparse.RawTextHelpFormatter)
+        kwargs.setdefault('description', __doc__)
+        argparse.ArgumentParser.__init__(self, **kwargs)
+        self.add_argument('yaml_file', type=argparse.filetype('r'))
+        self.options = None
+
+    def parse_args(self, *args, **kw):
+        options = argparse.ArgumentParser.parse_args(self, *args, **kw)
+        self.validate(options)
+        self.options = options
+        return options
+
+    def validate(self, options):
+        """validate options"""
+
+def main(args=sys.argv[1:]):
+    """CLI"""
+
+    # parse command line options
+    parser = ValidateYAMLParser()
+    options = parser.parse_args(args)
+
+    yaml.load(options.yaml_file)
+
+if __name__ == '__main__':
+    main()
+
+