Skip to content

Commit

Permalink
Improve exit codes
Browse files Browse the repository at this point in the history
- Exit with a non-zero exit code when a page does not exist
- Exit with exit code 3 when the cache directory does not exit
- Exit with exit code 130 on a keyboard interrupt
  • Loading branch information
superatomic committed Jul 25, 2023
1 parent 280ab5b commit 5c839f4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/tldr_man/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ def wrapper(ctx: Context, _param, value):
# If `sys.exit()` was called, exit that context with the given status code.
exited_with_error = True # Don't call the `ctx.exit()` in the `finally` block
ctx.exit(err.code)
except KeyboardInterrupt:
exited_with_error = True
ctx.exit(130)
finally:
if not exited_with_error:
ctx.exit()
Expand Down
4 changes: 2 additions & 2 deletions src/tldr_man/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def pandoc_exists() -> bool:
def verify_tldr_cache_exists():
"""Display a specific message if the tldr manpage cache doesn't exist yet, and then exit."""
if not CACHE_DIR.exists():
exit_with(CACHE_DOES_NOT_EXIST_MESSAGE)
exit_with(CACHE_DOES_NOT_EXIST_MESSAGE, exitcode=3)


def display_page(page: Path) -> None:
Expand All @@ -294,7 +294,7 @@ def find_page(page_name: str, /, locales: Iterable[str], page_sections: Iterable
if page.exists():
return page
else:
eprint(PAGE_NOT_FOUND_MESSAGE.format(page_name=page_name))
exit_with(PAGE_NOT_FOUND_MESSAGE.format(page_name=page_name))


def get_dir_search_order(locales: Iterable[str], page_sections: Iterable[str]) -> Iterable[Path]:
Expand Down

0 comments on commit 5c839f4

Please sign in to comment.