0
|
1 #!/usr/bin/env python
|
|
2 # -*- coding: utf-8 -*-
|
|
3
|
|
4 """
|
|
5 validate yaml
|
|
6 """
|
|
7
|
|
8 # imports
|
|
9 import argparse
|
|
10 import sys
|
|
11 import yaml
|
|
12
|
|
13 class ValidateYAMLParser(argparse.ArgumentParser):
|
|
14 """CLI option parser"""
|
|
15 def __init__(self, **kwargs):
|
|
16 kwargs.setdefault('formatter_class', argparse.RawTextHelpFormatter)
|
|
17 kwargs.setdefault('description', __doc__)
|
|
18 argparse.ArgumentParser.__init__(self, **kwargs)
|
|
19 self.add_argument('yaml_file', type=argparse.filetype('r'))
|
|
20 self.options = None
|
|
21
|
|
22 def parse_args(self, *args, **kw):
|
|
23 options = argparse.ArgumentParser.parse_args(self, *args, **kw)
|
|
24 self.validate(options)
|
|
25 self.options = options
|
|
26 return options
|
|
27
|
|
28 def validate(self, options):
|
|
29 """validate options"""
|
|
30
|
|
31 def main(args=sys.argv[1:]):
|
|
32 """CLI"""
|
|
33
|
|
34 # parse command line options
|
|
35 parser = ValidateYAMLParser()
|
|
36 options = parser.parse_args(args)
|
|
37
|
|
38 yaml.load(options.yaml_file)
|
|
39
|
|
40 if __name__ == '__main__':
|
|
41 main()
|
|
42
|
|
43
|