Skip to content

Commit

Permalink
refactor pyglossary/ui/main.py and add mainNoExit function
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Dec 27, 2024
1 parent fbbb6da commit c19ba56
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions pyglossary/ui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from pyglossary.ui.argparse_main import configFromArgs, defineFlags, validateFlags
from pyglossary.ui.base import UIBase

__all__ = ["main"]
__all__ = ["main", "mainNoExit"]

# TODO: move to docs:
# examples for read and write options:
Expand Down Expand Up @@ -266,21 +266,22 @@ def mainPrepare() -> tuple[bool, MainPrepareResult | None]:
)


def main() -> None: # noqa: PLR0912
def mainNoExit() -> bool: # noqa: PLR0912
ok, res = mainPrepare()
if res is None:
sys.exit(0 if ok else 1)
# import pprint;pprint.pprint(res)
if not ok:
return False
if res is None: # --version or --help
return True

from pyglossary.ui.runner import getRunner

assert log
run = getRunner(res.args, res.uiType, log)
if run is None:
sys.exit(1)
return False

try:
ok = run(
return run(
inputFilename=res.inputFilename,
outputFilename=res.outputFilename,
inputFormat=res.inputFormat,
Expand All @@ -294,5 +295,8 @@ def main() -> None: # noqa: PLR0912
)
except KeyboardInterrupt:
log.error("Cancelled")
ok = False
sys.exit(0 if ok else 1)
return False


def main() -> None:
sys.exit(int(not mainNoExit()))

0 comments on commit c19ba56

Please sign in to comment.