Skip to content

Commit

Permalink
feat: use exit code in cli tools
Browse files Browse the repository at this point in the history
  • Loading branch information
star0202 committed May 11, 2024
1 parent c4fb482 commit 848d3bf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
21 changes: 14 additions & 7 deletions tools/validator/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,11 @@ def _validate_cpp(self, input: str, output: str) -> Result:
return Result(ResultEnum.TLE, -1, -1, "")


def cli() -> None:
def main() -> int | None:
if len(argv) < 2:
print('Usage: python validate.py <file or "clean">')
return 1

if argv[1] == "clean":
for file in glob("_problems/*.json"):
print(f"Removing {file}")
Expand All @@ -320,13 +324,16 @@ def cli() -> None:
for i, r in enumerate(res):
print(f"Sample {i + 1}: {r.result.value}")

if all(res):
print(HR)
if not all(res):
return 1

print(HR)

print("All samples passed!")
system(f"/mnt/c/Windows/System32/clip.exe < {argv[1]}")
print("Copied to clipboard!")

print("All samples passed!")
system(f"/mnt/c/Windows/System32/clip.exe < {argv[1]}")
print("Copied to clipboard!")


if __name__ == "__main__":
cli()
exit(main())
4 changes: 2 additions & 2 deletions update.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def language(ext: str) -> str:
return LANGUAGE_MAPPING[ext]


def main():
def main() -> int | None:
json: dict[str, SnippetSchema] = {}

if path.exists(SNIPPET_FILE):
Expand Down Expand Up @@ -66,4 +66,4 @@ def main():


if __name__ == "__main__":
main()
exit(main())

0 comments on commit 848d3bf

Please sign in to comment.