diff --git a/cli.py b/cli.py index 0376bb2..b61d84c 100644 --- a/cli.py +++ b/cli.py @@ -3,6 +3,8 @@ import dataclasses as dc import sys from typing import cast +from dopt_basics import cli + from dopt_sensor_anomalies import _interface @@ -34,11 +36,18 @@ def main() -> int: ) args = cast(CliArgs, parser.parse_args()) - status = _interface.sensor_anomalies_detection( - args.img_path, - args.calib_value_x, - args.calib_value_y, - ) + with cli.LoadingAnimation( + "Perform anomaly detection...", + "Pipeline ended successfully!", + ) as loader: + status = _interface.sensor_anomalies_detection( + args.img_path, + args.calib_value_x, + args.calib_value_y, + ) + if status != 0: + loader.stop(interrupt=True) + sys.exit(status) diff --git a/cli_mocked.py b/cli_mocked.py new file mode 100644 index 0000000..df1a317 --- /dev/null +++ b/cli_mocked.py @@ -0,0 +1,58 @@ +import argparse +import dataclasses as dc +import sys +from typing import cast +from unittest.mock import patch + +from dopt_basics import cli + +from dopt_sensor_anomalies import _interface + + +@dc.dataclass() +class CliArgs: + img_path: str + calib_value_x: float + calib_value_y: float + + +@patch("dopt_sensor_anomalies._find_paths.STOP_FOLDER_NAME", "src") +@patch("dopt_sensor_anomalies._find_paths.MODEL_FOLDER_NAME", "tests/_models") +def main() -> int: + parser = argparse.ArgumentParser( + description=("simple CLI tool to analyse single sensor images for anomalies") + ) + parser.add_argument( + "img_path", + help="file path to the image which is to be analysed", + type=str, + ) + parser.add_argument( + "calib_value_x", + help="calibration value in pixels per mcm for x axis, type: float", + type=float, + ) + parser.add_argument( + "calib_value_y", + help="calibration value in pixels per mcm for y axis, type: float", + type=float, + ) + args = cast(CliArgs, parser.parse_args()) + + with cli.LoadingAnimation( + "Perform anomaly detection...", + "Pipeline ended successfully!", + ) as loader: + status = _interface.sensor_anomalies_detection( + args.img_path, + args.calib_value_x, + args.calib_value_y, + ) + if status != 0: + loader.stop(interrupt=True) + + sys.exit(status) + + +if __name__ == "__main__": + main() diff --git a/src/dopt_sensor_anomalies/_interface.py b/src/dopt_sensor_anomalies/_interface.py index 748e6b7..1195f17 100644 --- a/src/dopt_sensor_anomalies/_interface.py +++ b/src/dopt_sensor_anomalies/_interface.py @@ -23,7 +23,7 @@ def _print_error_state( f"\nType: {state.ExceptionType.__name__}\nDescription: {state.description}\n" f"Message: {state.message}" ) - print(msg, flush=True, file=out_stream) + print(f"\r{msg}", flush=True, file=out_stream) def sensor_anomalies_detection(