Add the ability to set output file

Set an output file, handy for scripting.

partially implements bp openstack-client-heat-translator

Change-Id: I5ddbab7c9266b18f4a0aad0958ccbe7db318e73f
This commit is contained in:
Steve Martinelli 2015-06-15 15:09:40 -04:00
parent eb913cd991
commit 2590405792

View File

@ -41,6 +41,10 @@ class TranslateTemplate(command.Command):
required=True,
choices=['tosca'],
help='Format of the template file.')
parser.add_argument(
'--output-file',
metavar='<output-file>',
help='Path to place the translated content.')
return parser
def take_action(self, parsed_args):
@ -56,4 +60,9 @@ class TranslateTemplate(command.Command):
tosca = ToscaTemplate(parsed_args.template_file)
translator = TOSCATranslator(tosca, parsed_params)
output = translator.translate()
print(output)
if parsed_args.output_file:
with open(parsed_args.output_file, 'w+') as f:
f.write(output)
else:
print(output)