Skip to content

Commit dff0bf4

Browse files
committed
Feature: Added watch option to exists commands
1 parent a1e8db8 commit dff0bf4

File tree

7 files changed

+46
-5
lines changed

7 files changed

+46
-5
lines changed

tm1cli/commands/cube.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
from rich import print # pylint: disable=redefined-builtin
55
from TM1py.Services import TM1Service
66

7-
from tm1cli.utils.cli_param import DATABASE_OPTION
7+
from tm1cli.utils.cli_param import DATABASE_OPTION, INTERVAL_OPTION, WATCH_OPTION
88
from tm1cli.utils.various import resolve_database
9+
from tm1cli.utils.watch import watch_option
910

1011
app = typer.Typer()
1112

@@ -34,10 +35,13 @@ def list_cube(
3435

3536

3637
@app.command()
38+
@watch_option
3739
def exists(
3840
ctx: typer.Context,
3941
cube_name: str,
4042
database: Annotated[str, DATABASE_OPTION] = None,
43+
watch: Annotated[bool, WATCH_OPTION] = False,
44+
interval: Annotated[int, INTERVAL_OPTION] = 5,
4145
):
4246
"""
4347
Check if cube exists

tm1cli/commands/dimension.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
from rich import print # pylint: disable=redefined-builtin
55
from TM1py.Services import TM1Service
66

7-
from tm1cli.utils.cli_param import DATABASE_OPTION
7+
from tm1cli.utils.cli_param import DATABASE_OPTION, INTERVAL_OPTION, WATCH_OPTION
88
from tm1cli.utils.various import resolve_database
9+
from tm1cli.utils.watch import watch_option
910

1011
app = typer.Typer()
1112

@@ -34,10 +35,13 @@ def list_dimension(
3435

3536

3637
@app.command()
38+
@watch_option
3739
def exists(
3840
ctx: typer.Context,
3941
dimension_name: str,
4042
database: Annotated[str, DATABASE_OPTION] = None,
43+
watch: Annotated[bool, WATCH_OPTION] = False,
44+
interval: Annotated[int, INTERVAL_OPTION] = 5,
4145
):
4246
"""
4347
Check if dimension exists

tm1cli/commands/process.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
from TM1py.Services import TM1Service
88
from typing_extensions import Annotated
99

10-
from tm1cli.utils.cli_param import DATABASE_OPTION
10+
from tm1cli.utils.cli_param import DATABASE_OPTION, INTERVAL_OPTION, WATCH_OPTION
1111
from tm1cli.utils.tm1yaml import dump_process, load_process
1212
from tm1cli.utils.various import print_error_and_exit, resolve_database
13+
from tm1cli.utils.watch import watch_option
1314

1415
app = typer.Typer()
1516

@@ -38,10 +39,13 @@ def list_process(
3839

3940

4041
@app.command()
42+
@watch_option
4143
def exists(
4244
ctx: typer.Context,
4345
name: str,
4446
database: Annotated[str, DATABASE_OPTION] = None,
47+
watch: Annotated[bool, WATCH_OPTION] = False,
48+
interval: Annotated[int, INTERVAL_OPTION] = 5,
4549
):
4650
"""
4751
Shows if process exists

tm1cli/commands/subset.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
from rich import print # pylint: disable=redefined-builtin
55
from TM1py.Services import TM1Service
66

7-
from tm1cli.utils.cli_param import DATABASE_OPTION
7+
from tm1cli.utils.cli_param import DATABASE_OPTION, INTERVAL_OPTION, WATCH_OPTION
88
from tm1cli.utils.various import resolve_database
9+
from tm1cli.utils.watch import watch_option
910

1011
app = typer.Typer()
1112

@@ -28,6 +29,7 @@ def list_subset(
2829

2930

3031
@app.command()
32+
@watch_option
3133
def exists(
3234
ctx: typer.Context,
3335
dimension_name: str,
@@ -36,6 +38,8 @@ def exists(
3638
bool, typer.Option("-p", "--private", help="Flag to specify if view is private")
3739
] = False,
3840
database: Annotated[str, DATABASE_OPTION] = None,
41+
watch: Annotated[bool, WATCH_OPTION] = False,
42+
interval: Annotated[int, INTERVAL_OPTION] = 5,
3943
):
4044
"""
4145
Check if subset exists

tm1cli/commands/view.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
from rich import print # pylint: disable=redefined-builtin
55
from TM1py.Services import TM1Service
66

7-
from tm1cli.utils.cli_param import DATABASE_OPTION
7+
from tm1cli.utils.cli_param import DATABASE_OPTION, INTERVAL_OPTION, WATCH_OPTION
88
from tm1cli.utils.various import resolve_database
9+
from tm1cli.utils.watch import watch_option
910

1011
app = typer.Typer()
1112

@@ -27,6 +28,7 @@ def list_view(
2728

2829

2930
@app.command()
31+
@watch_option
3032
def exists(
3133
ctx: typer.Context,
3234
cube_name: str,
@@ -35,6 +37,8 @@ def exists(
3537
bool, typer.Option("-p", "--private", help="Flag to specify if view is private")
3638
] = False,
3739
database: Annotated[str, DATABASE_OPTION] = None,
40+
watch: Annotated[bool, WATCH_OPTION] = False,
41+
interval: Annotated[int, INTERVAL_OPTION] = 5,
3842
):
3943
"""
4044
Check if view exists

tm1cli/utils/cli_param.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
import typer
22

33
DATABASE_OPTION = typer.Option("--database", "-d", help="Specify the database to use")
4+
WATCH_OPTION = typer.Option(
5+
"--watch", "-w", help="Watch the command output periodically."
6+
)
7+
INTERVAL_OPTION = (
8+
typer.Option("--interval", help="Interval in seconds for the watch option."),
9+
)

tm1cli/utils/watch.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import time
2+
from functools import wraps
3+
4+
5+
def watch_option(func):
6+
@wraps(func)
7+
def wrapper(*args, watch: bool = False, interval: int = 5, **kwargs):
8+
if watch:
9+
while True:
10+
func(*args, **kwargs)
11+
time.sleep(interval)
12+
else:
13+
func(*args, **kwargs)
14+
15+
return wrapper

0 commit comments

Comments
 (0)