-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract CLI into separate package (#23)
### Summary of Changes Move the CLI out of the `server` package.
- Loading branch information
1 parent
613589b
commit 20e9aac
Showing
7 changed files
with
68 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"""The command line interface of the application.""" | ||
|
||
from ._cli import cli | ||
|
||
__all__ = ["cli"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import argparse | ||
import logging | ||
from importlib.metadata import version | ||
|
||
from safeds_runner.server.main import start_server | ||
|
||
|
||
class Commands: | ||
START = "start" | ||
|
||
|
||
def cli() -> None: # pragma: no cover | ||
"""Run the application via the command line.""" | ||
args = _get_args() | ||
|
||
# Set logging level | ||
if args.verbose: | ||
logging.basicConfig(level=logging.DEBUG) | ||
else: | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
# Run command | ||
match args.command: | ||
case Commands.START: | ||
start_server(args.port) | ||
|
||
|
||
def _get_args() -> argparse.Namespace: # pragma: no cover | ||
parser = argparse.ArgumentParser(description="Execute Safe-DS programs that were compiled to Python.") | ||
parser.add_argument( | ||
"-V", | ||
"--version", | ||
action="version", | ||
version=f"%(prog)s {version('safe-ds-runner')}", | ||
) | ||
parser.add_argument("-v", "--verbose", help="increase logging verbosity", action="store_true") | ||
|
||
# Commands | ||
subparsers = parser.add_subparsers(dest="command") | ||
_add_start_subparser(subparsers) | ||
|
||
return parser.parse_args() | ||
|
||
|
||
def _add_start_subparser(subparsers: argparse._SubParsersAction) -> None: # pragma: no cover | ||
parser = subparsers.add_parser(Commands.START, help="start the Safe-DS Runner server") | ||
parser.add_argument("-p", "--port", type=int, default=5000, help="the port to use") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"""The main entry point of the application.""" | ||
|
||
from safeds_runner.cli import cli | ||
|
||
|
||
def main() -> None: # pragma: no cover | ||
"""Run the application.""" | ||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters