58
58
help = "Enables verbose logging" ,
59
59
action = "store_true" ,
60
60
)
61
+ parser .add_argument (
62
+ "--stdout" ,
63
+ help = "Write transformed template to stdout instead of a file" ,
64
+ action = "store_true" ,
65
+ )
61
66
cli_options = parser .parse_args ()
62
67
63
68
if cli_options .verbose :
@@ -100,14 +105,18 @@ def package(input_file_path: Path) -> Path:
100
105
return package_output_template_file
101
106
102
107
103
- def transform_template (input_file_path : Path , output_file_path : Path ): # type: ignore[no-untyped-def]
108
+ def transform_template (input_file_path : Path , output_file_path : Path , stdout : bool ): # type: ignore[no-untyped-def]
104
109
with input_file_path .open () as f :
105
110
sam_template = yaml_parse (f ) # type: ignore[no-untyped-call]
106
111
107
112
try :
108
113
cloud_formation_template = transform (sam_template , {}, ManagedPolicyLoader (iam_client ))
109
114
cloud_formation_template_prettified = json .dumps (cloud_formation_template , indent = 1 )
110
115
116
+ if stdout :
117
+ print (cloud_formation_template_prettified )
118
+ return
119
+
111
120
output_file_path .write_text (cloud_formation_template_prettified , encoding = "utf-8" )
112
121
113
122
print ("Wrote transformed CloudFormation template to: " , output_file_path )
@@ -132,10 +141,10 @@ def deploy(template_file: Path) -> None:
132
141
133
142
if cli_options .command == "package" :
134
143
package_output_template_file = package (input_file_path )
135
- transform_template (package_output_template_file , output_file_path )
144
+ transform_template (package_output_template_file , output_file_path , cli_options . stdout )
136
145
elif cli_options .command == "deploy" :
137
146
package_output_template_file = package (input_file_path )
138
- transform_template (package_output_template_file , output_file_path )
147
+ transform_template (package_output_template_file , output_file_path , cli_options . stdout )
139
148
deploy (output_file_path )
140
149
else :
141
- transform_template (input_file_path , output_file_path )
150
+ transform_template (input_file_path , output_file_path , cli_options . stdout )
0 commit comments