Skip to content

Commit

Permalink
Add -o flag to output directly to file (vyperlang#2452)
Browse files Browse the repository at this point in the history
Co-authored-by: Charles Cooper <cooper.charles.m@gmail.com>
  • Loading branch information
2 people authored and skellet0r committed Oct 2, 2021
1 parent 42c2ff5 commit 39164e4
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions vyper/cli/vyper_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@
def _parse_cli_args():
return _parse_args(sys.argv[1:])

def _cli_helper(f, output_formats, compiled):
if output_formats == ("combined_json",):
print(json.dumps(compiled), file=f)
return

for contract_data in compiled.values():
for data in contract_data.values():
if isinstance(data, (list, dict)):
print(json.dumps(data), file=f)
else:
print(data, file=f)

def _parse_args(argv):
warnings.simplefilter("always")
Expand Down Expand Up @@ -109,6 +120,9 @@ def _parse_args(argv):
parser.add_argument(
"-p", help="Set the root path for contract imports", default=".", dest="root_folder"
)
parser.add_argument(
"-o", help="Set the output path", dest="output_path"
)

args = parser.parse_args(argv)

Expand All @@ -135,16 +149,13 @@ def _parse_args(argv):
args.ovm,
)

if output_formats == ("combined_json",):
print(json.dumps(compiled))
return

for contract_data in compiled.values():
for data in contract_data.values():
if isinstance(data, (list, dict)):
print(json.dumps(data))
else:
print(data)
if args.output_path:
with open(args.output_path,"w") as f:
_cli_helper(f, output_formats, compiled)
else:
f = sys.stdout
_cli_helper(f, output_formats, compiled)


def uniq(seq: Iterable[T]) -> Iterator[T]:
Expand Down

0 comments on commit 39164e4

Please sign in to comment.