diff --git a/.pylintrc b/.pylintrc index 9c4d544..57d2b19 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,3 +1,3 @@ [MAIN] -disable=missing-module-docstring, missing-class-docstring, missing-function-docstring +disable=missing-module-docstring, missing-class-docstring, missing-function-docstring, too-many-arguments, too-many-positional-arguments max-line-length=120 diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ee62e5..f0456c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v0.1.6 - 2025-16-01 + +### Features + +- New watch option for exists command, e.g: `cube exists --watch` + ## v0.1.5 - 2025-16-01 ### Features diff --git a/README.md b/README.md index 99345aa..2236f8a 100644 --- a/README.md +++ b/README.md @@ -52,10 +52,10 @@ tm1cli process dump --folder --format tm1cli process load --folder --format tm1cli cube list -tm1cli cube exists +tm1cli cube exists --watch tm1cli dimension list -tm1cli dimension exists +tm1cli dimension exists -w tm1cli view list tm1cli view exists diff --git a/pyproject.toml b/pyproject.toml index 4728bb6..03f4242 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "tm1cli" -version = "0.1.5" +version = "0.1.6" description = "A command-line interface (CLI) tool for interacting with TM1 servers using TM1py." authors = ["onefloid "] license = "MIT License" diff --git a/tm1cli/commands/cube.py b/tm1cli/commands/cube.py index ba9c2d5..ab88047 100644 --- a/tm1cli/commands/cube.py +++ b/tm1cli/commands/cube.py @@ -4,8 +4,9 @@ from rich import print # pylint: disable=redefined-builtin from TM1py.Services import TM1Service -from tm1cli.utils.cli_param import DATABASE_OPTION +from tm1cli.utils.cli_param import DATABASE_OPTION, INTERVAL_OPTION, WATCH_OPTION from tm1cli.utils.various import resolve_database +from tm1cli.utils.watch import watch_option app = typer.Typer() @@ -34,10 +35,13 @@ def list_cube( @app.command() +@watch_option def exists( ctx: typer.Context, cube_name: str, database: Annotated[str, DATABASE_OPTION] = None, + watch: Annotated[bool, WATCH_OPTION] = False, # pylint: disable=unused-argument + interval: Annotated[int, INTERVAL_OPTION] = 5, # pylint: disable=unused-argument ): """ Check if cube exists diff --git a/tm1cli/commands/dimension.py b/tm1cli/commands/dimension.py index 203c9ce..9926105 100644 --- a/tm1cli/commands/dimension.py +++ b/tm1cli/commands/dimension.py @@ -4,8 +4,9 @@ from rich import print # pylint: disable=redefined-builtin from TM1py.Services import TM1Service -from tm1cli.utils.cli_param import DATABASE_OPTION +from tm1cli.utils.cli_param import DATABASE_OPTION, INTERVAL_OPTION, WATCH_OPTION from tm1cli.utils.various import resolve_database +from tm1cli.utils.watch import watch_option app = typer.Typer() @@ -34,10 +35,13 @@ def list_dimension( @app.command() +@watch_option def exists( ctx: typer.Context, dimension_name: str, database: Annotated[str, DATABASE_OPTION] = None, + watch: Annotated[bool, WATCH_OPTION] = False, # pylint: disable=unused-argument + interval: Annotated[int, INTERVAL_OPTION] = 5, # pylint: disable=unused-argument ): """ Check if dimension exists diff --git a/tm1cli/commands/process.py b/tm1cli/commands/process.py index 7ee6684..7e1d46f 100644 --- a/tm1cli/commands/process.py +++ b/tm1cli/commands/process.py @@ -7,9 +7,10 @@ from TM1py.Services import TM1Service from typing_extensions import Annotated -from tm1cli.utils.cli_param import DATABASE_OPTION +from tm1cli.utils.cli_param import DATABASE_OPTION, INTERVAL_OPTION, WATCH_OPTION from tm1cli.utils.tm1yaml import dump_process, load_process from tm1cli.utils.various import print_error_and_exit, resolve_database +from tm1cli.utils.watch import watch_option app = typer.Typer() @@ -38,10 +39,13 @@ def list_process( @app.command() +@watch_option def exists( ctx: typer.Context, name: str, database: Annotated[str, DATABASE_OPTION] = None, + watch: Annotated[bool, WATCH_OPTION] = False, # pylint: disable=unused-argument + interval: Annotated[int, INTERVAL_OPTION] = 5, # pylint: disable=unused-argument ): """ Shows if process exists diff --git a/tm1cli/commands/subset.py b/tm1cli/commands/subset.py index 32360c3..021e720 100644 --- a/tm1cli/commands/subset.py +++ b/tm1cli/commands/subset.py @@ -4,8 +4,9 @@ from rich import print # pylint: disable=redefined-builtin from TM1py.Services import TM1Service -from tm1cli.utils.cli_param import DATABASE_OPTION +from tm1cli.utils.cli_param import DATABASE_OPTION, INTERVAL_OPTION, WATCH_OPTION from tm1cli.utils.various import resolve_database +from tm1cli.utils.watch import watch_option app = typer.Typer() @@ -28,6 +29,7 @@ def list_subset( @app.command() +@watch_option def exists( ctx: typer.Context, dimension_name: str, @@ -36,6 +38,8 @@ def exists( bool, typer.Option("-p", "--private", help="Flag to specify if view is private") ] = False, database: Annotated[str, DATABASE_OPTION] = None, + watch: Annotated[bool, WATCH_OPTION] = False, # pylint: disable=unused-argument + interval: Annotated[int, INTERVAL_OPTION] = 5, # pylint: disable=unused-argument ): """ Check if subset exists diff --git a/tm1cli/commands/view.py b/tm1cli/commands/view.py index dc72fbe..d71768d 100644 --- a/tm1cli/commands/view.py +++ b/tm1cli/commands/view.py @@ -4,8 +4,9 @@ from rich import print # pylint: disable=redefined-builtin from TM1py.Services import TM1Service -from tm1cli.utils.cli_param import DATABASE_OPTION +from tm1cli.utils.cli_param import DATABASE_OPTION, INTERVAL_OPTION, WATCH_OPTION from tm1cli.utils.various import resolve_database +from tm1cli.utils.watch import watch_option app = typer.Typer() @@ -27,6 +28,7 @@ def list_view( @app.command() +@watch_option def exists( ctx: typer.Context, cube_name: str, @@ -35,6 +37,8 @@ def exists( bool, typer.Option("-p", "--private", help="Flag to specify if view is private") ] = False, database: Annotated[str, DATABASE_OPTION] = None, + watch: Annotated[bool, WATCH_OPTION] = False, # pylint: disable=unused-argument + interval: Annotated[int, INTERVAL_OPTION] = 5, # pylint: disable=unused-argument ): """ Check if view exists diff --git a/tm1cli/utils/cli_param.py b/tm1cli/utils/cli_param.py index 74595cb..9792fed 100644 --- a/tm1cli/utils/cli_param.py +++ b/tm1cli/utils/cli_param.py @@ -1,3 +1,9 @@ import typer DATABASE_OPTION = typer.Option("--database", "-d", help="Specify the database to use") +WATCH_OPTION = typer.Option( + "--watch", "-w", help="Watch the command output periodically." +) +INTERVAL_OPTION = ( + typer.Option("--interval", help="Interval in seconds for the watch option."), +) diff --git a/tm1cli/utils/watch.py b/tm1cli/utils/watch.py new file mode 100644 index 0000000..1f5ffd4 --- /dev/null +++ b/tm1cli/utils/watch.py @@ -0,0 +1,15 @@ +import time +from functools import wraps + + +def watch_option(func): + @wraps(func) + def wrapper(*args, watch: bool = False, interval: int = 5, **kwargs): + if watch: + while True: + func(*args, **kwargs) + time.sleep(interval) + else: + func(*args, **kwargs) + + return wrapper