Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
622 changes: 316 additions & 306 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/test_cmd_cubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_cube_list(mocker, command):


def test_cube_exists(mocker):
mocker.patch("tm1cli.commands.cube.TM1Service", MockedTM1Service)
mocker.patch("tm1cli.utils.generic.TM1Service", MockedTM1Service)
result = runner.invoke(app, ["cube", "exists", "Cube1"])
assert result.exit_code == 0
assert isinstance(result.stdout, str)
Expand Down
15 changes: 11 additions & 4 deletions tests/test_cmd_dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@ def test_dimension_list(mocker, command):
assert result.stdout == "Dimension1\nDimension2\nDimension3\n"


def test_dimension_exists(mocker):
mocker.patch("tm1cli.commands.dimension.TM1Service", MockedTM1Service)
result = runner.invoke(app, ["dimension", "exists", "Dimension1"])
@pytest.mark.parametrize(
"raw_option,expected_output",
[(None, "✅ Dimension exists!\n"), ("--output-raw", "True\n")],
)
def test_dimension_exists(mocker, raw_option, expected_output):
mocker.patch("tm1cli.utils.generic.TM1Service", MockedTM1Service)
if raw_option:
result = runner.invoke(app, [raw_option, "dimension", "exists", "Dimension1"])
else:
result = runner.invoke(app, ["dimension", "exists", "Dimension1"])
assert result.exit_code == 0
assert isinstance(result.stdout, str)
assert result.stdout == "True\n"
assert result.stdout == expected_output
2 changes: 1 addition & 1 deletion tests/test_cmd_subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_subset_list(mocker, command):


def test_subset_exists(mocker):
mocker.patch("tm1cli.commands.subset.TM1Service", MockedTM1Service)
mocker.patch("tm1cli.utils.generic.TM1Service", MockedTM1Service)
result = runner.invoke(app, ["subset", "exists", "Dimension1", "Subset1"])
assert result.exit_code == 0
assert isinstance(result.stdout, str)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cmd_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[("not", "", "False"), ("example", "-p", "True"), ("not", "--private", "False")],
)
def test_view_exists(mocker, options):
mocker.patch("tm1cli.commands.view.TM1Service", MockedTM1Service)
mocker.patch("tm1cli.utils.generic.TM1Service", MockedTM1Service)
if options[1]:
result = runner.invoke(app, ["view", "exists", "example_cube", options[0]])
else:
Expand Down
9 changes: 7 additions & 2 deletions tm1cli/commands/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from TM1py.Services import TM1Service

from tm1cli.utils.cli_param import DATABASE_OPTION, INTERVAL_OPTION, WATCH_OPTION
from tm1cli.utils.generic import execute_exists
from tm1cli.utils.various import resolve_database
from tm1cli.utils.watch import watch_option

Expand Down Expand Up @@ -46,5 +47,9 @@ def exists(
"""
Check if cube exists
"""
with TM1Service(**resolve_database(ctx, database)) as tm1:
print(tm1.cubes.exists(cube_name))
execute_exists(
"cubes",
ctx,
database,
cube_name=cube_name,
)
9 changes: 7 additions & 2 deletions tm1cli/commands/dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from TM1py.Services import TM1Service

from tm1cli.utils.cli_param import DATABASE_OPTION, INTERVAL_OPTION, WATCH_OPTION
from tm1cli.utils.generic import execute_exists
from tm1cli.utils.various import resolve_database
from tm1cli.utils.watch import watch_option

Expand Down Expand Up @@ -46,5 +47,9 @@ def exists(
"""
Check if dimension exists
"""
with TM1Service(**resolve_database(ctx, database)) as tm1:
print(tm1.dimensions.exists(dimension_name))
execute_exists(
"dimensions",
ctx,
database,
dimension_name=dimension_name,
)
9 changes: 7 additions & 2 deletions tm1cli/commands/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing_extensions import Annotated

from tm1cli.utils.cli_param import DATABASE_OPTION, INTERVAL_OPTION, WATCH_OPTION
from tm1cli.utils.generic import execute_exists
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
Expand Down Expand Up @@ -51,8 +52,12 @@ def exists(
Shows if process exists
"""

with TM1Service(**resolve_database(ctx, database)) as tm1:
print(tm1.processes.exists(name))
execute_exists(
"processes",
ctx,
database,
name=name,
)


@app.command()
Expand Down
11 changes: 9 additions & 2 deletions tm1cli/commands/subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from TM1py.Services import TM1Service

from tm1cli.utils.cli_param import DATABASE_OPTION, INTERVAL_OPTION, WATCH_OPTION
from tm1cli.utils.generic import execute_exists
from tm1cli.utils.various import resolve_database
from tm1cli.utils.watch import watch_option

Expand Down Expand Up @@ -45,5 +46,11 @@ def exists(
Check if subset exists
"""

with TM1Service(**resolve_database(ctx, database)) as tm1:
print(tm1.views.exists(dimension_name, subset_name, is_private))
execute_exists(
"subsets",
ctx,
database,
dimension_name=dimension_name,
subset_name=subset_name,
private=is_private,
)
11 changes: 9 additions & 2 deletions tm1cli/commands/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from TM1py.Services import TM1Service

from tm1cli.utils.cli_param import DATABASE_OPTION, INTERVAL_OPTION, WATCH_OPTION
from tm1cli.utils.generic import execute_exists
from tm1cli.utils.various import resolve_database
from tm1cli.utils.watch import watch_option

Expand Down Expand Up @@ -44,5 +45,11 @@ def exists(
Check if view exists
"""

with TM1Service(**resolve_database(ctx, database)) as tm1:
print(tm1.views.exists(cube_name, view_name, is_private))
execute_exists(
"views",
ctx,
database,
cube_name=cube_name,
view_name=view_name,
private=is_private,
)
15 changes: 11 additions & 4 deletions tm1cli/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import importlib.metadata
import json
import os

import importlib.metadata
import typer
import yaml
from rich import print
Expand All @@ -14,7 +14,6 @@
from tm1cli.utils.cli_param import DATABASE_OPTION
from tm1cli.utils.various import resolve_database


console = Console()
app = typer.Typer()

Expand All @@ -30,7 +29,13 @@


@app.callback()
def main(ctx: typer.Context):
def main(
ctx: typer.Context,
raw: Annotated[
bool,
typer.Option("--output-raw", help="Raw output without formatting"),
] = False,
):
"""
CLI tool to interact with TM1 using TM1py.
"""
Expand All @@ -52,6 +57,8 @@ def main(ctx: typer.Context):
}
ctx.obj = {"configs": {}, "default_db_config": default_db_config}

ctx.obj["raw"] = raw


@app.command()
def version():
Expand Down
31 changes: 31 additions & 0 deletions tm1cli/utils/generic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import typer
from rich import print
from TM1py import TM1Service

from tm1cli.utils.various import resolve_database


def execute_exists(attribute_name, ctx, database, **args):
"""
Util function to execute an exists function
"""

try:
with TM1Service(**resolve_database(ctx, database)) as tm1:

attribute = getattr(tm1, attribute_name)
method = getattr(attribute, "exists")
output = method(**args)
if ctx.obj["raw"]:
print(output)
return

output_name = f"{attribute_name[:-1].capitalize()}"
if output:
print(f":white_check_mark: {output_name} exists!")
else:
print(f":x: {output_name} does not exist!")

except Exception as e:
print(f"[bold red]{type(e).__name__}:[/bold red] {e}")
raise typer.Exit(code=1)
Loading