Skip to content

Commit

Permalink
feat: use return error codes for easier integration in other projects
Browse files Browse the repository at this point in the history
  • Loading branch information
BoboTiG committed Jul 12, 2023
1 parent d3575c6 commit 628fc68
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion medusa/_cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def main():
sys.tracebacklimit = 1000

try:
importlib.import_module(f"medusa._cli.{cmd}").main()
sys.exit(importlib.import_module(f"medusa._cli.{cmd}").main())
except Exception as e:
tb_item = sys.exc_info()[2]
traceback.print_tb(tb_item)
Expand Down
34 changes: 18 additions & 16 deletions medusa/_cli/analyse.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,28 @@
"""


def main():
def main() -> int:
args = docopt(__doc__)

if args["<contract>"]:
path = args["<contract>"]
print_output = args["--print-output"]
if not (path := args["<contract>"]):
return 1

# Get Vyper AST
vyper_ast = get_vyper_ast(path)
print_output = args["--print-output"]

# Perform analysis and format the result as a string
output_dict = analyse(vyper_ast)
formatted_analysis = format_analysis(output_dict)
# Get Vyper AST
vyper_ast = get_vyper_ast(path)

# Write to output file
if output_file := args["--output"]:
write_analysis(formatted_analysis, output_file)
# Perform analysis and format the result as a string
output_dict = analyse(vyper_ast)
formatted_analysis = format_analysis(output_dict)

# Print analysis to console
if print_output:
print(formatted_analysis)
# Write to output file
if output_file := args["--output"]:
write_analysis(formatted_analysis, output_file)

print(f"\nSuccessfully analysed {path}!")
# Print analysis to console
if print_output:
print(formatted_analysis)

print(f"\nSuccessfully analysed {path}!")
return int(bool(output_dict))
18 changes: 11 additions & 7 deletions medusa/_cli/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
"""


def main():
def main() -> int:
args = docopt(__doc__)

if args["<contract>"]:
path = args["<contract>"]
if not args["<contract>"]:
return 1

# Get Vyper AST
vyper_ast = get_vyper_ast(path)
ast_dict = vyper_ast.to_dict()
print(json.dumps(ast_dict, indent=4, sort_keys=True))
path = args["<contract>"]

# Get Vyper AST
vyper_ast = get_vyper_ast(path)
ast_dict = vyper_ast.to_dict()
print(json.dumps(ast_dict, indent=4, sort_keys=True))

return 0

0 comments on commit 628fc68

Please sign in to comment.