From dff0bf40b3d30b9daaf78b3f3398441799125c08 Mon Sep 17 00:00:00 2001 From: onefloid <33193059+onefloid@users.noreply.github.com> Date: Thu, 16 Jan 2025 21:46:31 +0100 Subject: [PATCH 1/5] Feature: Added watch option to exists commands --- tm1cli/commands/cube.py | 6 +++++- tm1cli/commands/dimension.py | 6 +++++- tm1cli/commands/process.py | 6 +++++- tm1cli/commands/subset.py | 6 +++++- tm1cli/commands/view.py | 6 +++++- tm1cli/utils/cli_param.py | 6 ++++++ tm1cli/utils/watch.py | 15 +++++++++++++++ 7 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 tm1cli/utils/watch.py diff --git a/tm1cli/commands/cube.py b/tm1cli/commands/cube.py index ba9c2d5..eb28176 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, + interval: Annotated[int, INTERVAL_OPTION] = 5, ): """ Check if cube exists diff --git a/tm1cli/commands/dimension.py b/tm1cli/commands/dimension.py index 203c9ce..505d75d 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, + interval: Annotated[int, INTERVAL_OPTION] = 5, ): """ Check if dimension exists diff --git a/tm1cli/commands/process.py b/tm1cli/commands/process.py index 7ee6684..43212ae 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, + interval: Annotated[int, INTERVAL_OPTION] = 5, ): """ Shows if process exists diff --git a/tm1cli/commands/subset.py b/tm1cli/commands/subset.py index 32360c3..3c598a3 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, + interval: Annotated[int, INTERVAL_OPTION] = 5, ): """ Check if subset exists diff --git a/tm1cli/commands/view.py b/tm1cli/commands/view.py index dc72fbe..4495970 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, + interval: Annotated[int, INTERVAL_OPTION] = 5, ): """ 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 From a2723b888347e012ec33ca1a1e85042643f4950f Mon Sep 17 00:00:00 2001 From: onefloid <33193059+onefloid@users.noreply.github.com> Date: Thu, 16 Jan 2025 21:50:03 +0100 Subject: [PATCH 2/5] Chore: Prepare release 0.1.6 --- CHANGELOG.md | 6 ++++++ README.md | 4 ++-- pyproject.toml | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) 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" From 3178f83cf454b7949d80cd1396cc2e637665113a Mon Sep 17 00:00:00 2001 From: onefloid <33193059+onefloid@users.noreply.github.com> Date: Thu, 16 Jan 2025 21:55:45 +0100 Subject: [PATCH 3/5] Fix: Ignore watch option linter warnings These arguments are needed for the watch option decorator --- tm1cli/commands/cube.py | 4 ++-- tm1cli/commands/dimension.py | 4 ++-- tm1cli/commands/process.py | 2 +- tm1cli/commands/subset.py | 4 ++-- tm1cli/commands/view.py | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tm1cli/commands/cube.py b/tm1cli/commands/cube.py index eb28176..ab88047 100644 --- a/tm1cli/commands/cube.py +++ b/tm1cli/commands/cube.py @@ -40,8 +40,8 @@ def exists( ctx: typer.Context, cube_name: str, database: Annotated[str, DATABASE_OPTION] = None, - watch: Annotated[bool, WATCH_OPTION] = False, - interval: Annotated[int, INTERVAL_OPTION] = 5, + 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 505d75d..9926105 100644 --- a/tm1cli/commands/dimension.py +++ b/tm1cli/commands/dimension.py @@ -40,8 +40,8 @@ def exists( ctx: typer.Context, dimension_name: str, database: Annotated[str, DATABASE_OPTION] = None, - watch: Annotated[bool, WATCH_OPTION] = False, - interval: Annotated[int, INTERVAL_OPTION] = 5, + 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 43212ae..a87470c 100644 --- a/tm1cli/commands/process.py +++ b/tm1cli/commands/process.py @@ -44,7 +44,7 @@ def exists( ctx: typer.Context, name: str, database: Annotated[str, DATABASE_OPTION] = None, - watch: Annotated[bool, WATCH_OPTION] = False, + watch: Annotated[bool, WATCH_OPTION] = False, # pylint: disable=unused-argument interval: Annotated[int, INTERVAL_OPTION] = 5, ): """ diff --git a/tm1cli/commands/subset.py b/tm1cli/commands/subset.py index 3c598a3..021e720 100644 --- a/tm1cli/commands/subset.py +++ b/tm1cli/commands/subset.py @@ -38,8 +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, - interval: Annotated[int, INTERVAL_OPTION] = 5, + 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 4495970..d71768d 100644 --- a/tm1cli/commands/view.py +++ b/tm1cli/commands/view.py @@ -37,8 +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, - interval: Annotated[int, INTERVAL_OPTION] = 5, + watch: Annotated[bool, WATCH_OPTION] = False, # pylint: disable=unused-argument + interval: Annotated[int, INTERVAL_OPTION] = 5, # pylint: disable=unused-argument ): """ Check if view exists From 85524281e070f91c5f995193321cdc3feb512560 Mon Sep 17 00:00:00 2001 From: onefloid <33193059+onefloid@users.noreply.github.com> Date: Thu, 16 Jan 2025 21:59:08 +0100 Subject: [PATCH 4/5] Fix: Linter --- .pylintrc | 2 +- tm1cli/commands/process.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.pylintrc b/.pylintrc index 9c4d544..ed452aa 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 max-line-length=120 diff --git a/tm1cli/commands/process.py b/tm1cli/commands/process.py index a87470c..7e1d46f 100644 --- a/tm1cli/commands/process.py +++ b/tm1cli/commands/process.py @@ -45,7 +45,7 @@ def exists( name: str, database: Annotated[str, DATABASE_OPTION] = None, watch: Annotated[bool, WATCH_OPTION] = False, # pylint: disable=unused-argument - interval: Annotated[int, INTERVAL_OPTION] = 5, + interval: Annotated[int, INTERVAL_OPTION] = 5, # pylint: disable=unused-argument ): """ Shows if process exists From 6aaf5e999012d902bc04540fa5da33143d8a2d3c Mon Sep 17 00:00:00 2001 From: onefloid <33193059+onefloid@users.noreply.github.com> Date: Thu, 16 Jan 2025 22:00:39 +0100 Subject: [PATCH 5/5] Fix: Linter --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index ed452aa..57d2b19 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,3 +1,3 @@ [MAIN] -disable=missing-module-docstring, missing-class-docstring, missing-function-docstring, too-many-arguments +disable=missing-module-docstring, missing-class-docstring, missing-function-docstring, too-many-arguments, too-many-positional-arguments max-line-length=120