summaryrefslogtreecommitdiffstats
path: root/tosca2heat/tosca-parser/toscaparser/shell.py
diff options
context:
space:
mode:
Diffstat (limited to 'tosca2heat/tosca-parser/toscaparser/shell.py')
-rw-r--r--tosca2heat/tosca-parser/toscaparser/shell.py40
1 files changed, 27 insertions, 13 deletions
diff --git a/tosca2heat/tosca-parser/toscaparser/shell.py b/tosca2heat/tosca-parser/toscaparser/shell.py
index b41c024..1d98f1a 100644
--- a/tosca2heat/tosca-parser/toscaparser/shell.py
+++ b/tosca2heat/tosca-parser/toscaparser/shell.py
@@ -11,6 +11,7 @@
# under the License.
+import argparse
import os
import sys
@@ -40,19 +41,20 @@ e.g.
class ParserShell(object):
- def _validate(self, args):
- if len(args) < 1:
- msg = _('The program requires a template or a CSAR file as an '
- 'argument. Please refer to the usage documentation.')
- raise ValueError(msg)
- if "--template-file=" not in args[0]:
- msg = _('The program expects "--template-file" as the first '
- 'argument. Please refer to the usage documentation.')
- raise ValueError(msg)
-
- def main(self, args):
- self._validate(args)
- path = args[0].split('--template-file=')[1]
+ def get_parser(self, argv):
+ parser = argparse.ArgumentParser(prog="tosca-parser")
+
+ parser.add_argument('--template-file',
+ metavar='<filename>',
+ required=True,
+ help=_('YAML template or CSAR file to parse.'))
+
+ return parser
+
+ def main(self, argv):
+ parser = self.get_parser(argv)
+ (args, extra_args) = parser.parse_known_args(argv)
+ path = args.template_file
if os.path.isfile(path):
self.parse(path)
elif toscaparser.utils.urlutils.UrlUtils.validate_url(path):
@@ -88,6 +90,18 @@ class ParserShell(object):
for node in nodetemplates:
print("\t" + node.name)
+ # example of retrieving policy object
+ '''if hasattr(tosca, 'policies'):
+ policies = tosca.policies
+ if policies:
+ print("policies:")
+ for policy in policies:
+ print("\t" + policy.name)
+ if policy.triggers:
+ print("\ttriggers:")
+ for trigger in policy.triggers:
+ print("\ttrigger name:" + trigger.name)'''
+
if hasattr(tosca, 'outputs'):
outputs = tosca.outputs
if outputs: