data-ops-cli 0.4.1__tar.gz → 0.4.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/PKG-INFO +1 -1
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/data_ops_cli.egg-info/PKG-INFO +1 -1
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/__init__.py +1 -1
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/cli/auth.py +7 -4
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/cli/dataset.py +95 -3
- data_ops_cli-0.4.2/src/dataops_cli/cli/dict_.py +219 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/cli/ref.py +5 -20
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/cli/skill.py +4 -18
- data_ops_cli-0.4.1/src/dataops_cli/cli/dict_.py +0 -101
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/README.md +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/pyproject.toml +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/setup.cfg +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/data_ops_cli.egg-info/SOURCES.txt +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/data_ops_cli.egg-info/dependency_links.txt +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/data_ops_cli.egg-info/entry_points.txt +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/data_ops_cli.egg-info/requires.txt +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/data_ops_cli.egg-info/top_level.txt +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/_compat.py +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/cli/__init__.py +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/cli/alarm.py +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/cli/api.py +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/cli/data_table.py +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/cli/datasource.py +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/cli/factory.py +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/cli/hazard.py +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/cli/metrics.py +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/cli/report.py +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/cli/table.py +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/cli/utils.py +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/cli/widget.py +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/cli/workflow.py +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/exceptions.py +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/runner.py +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/schems.py +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/sdk.py +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/session.py +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/src/dataops_cli/utils.py +0 -0
- {data_ops_cli-0.4.1 → data_ops_cli-0.4.2}/tests/test_table_relation.py +0 -0
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
from typing import Annotated
|
|
10
10
|
|
|
11
11
|
import typer
|
|
12
|
+
from dataops_cli.cli.utils import print_list
|
|
12
13
|
from dataops_sdk.constants import APPLICATION_FILE, USER_INFO_FILE
|
|
13
14
|
from dataops_sdk.exceptions import AuthenticationError
|
|
14
15
|
from dataops_sdk.schemas import UserInfo
|
|
@@ -25,8 +26,6 @@ from dataops_sdk.utils import get_work_dir
|
|
|
25
26
|
from rich.console import Console
|
|
26
27
|
from rich.table import Table
|
|
27
28
|
|
|
28
|
-
from dataops_cli.cli.utils import print_list
|
|
29
|
-
|
|
30
29
|
auth_typer = typer.Typer(name="auth", help="认证相关命令", no_args_is_help=True)
|
|
31
30
|
application_typer = typer.Typer(name="application", help="应用相关命令", no_args_is_help=True)
|
|
32
31
|
auth_typer.add_typer(application_typer)
|
|
@@ -60,9 +59,13 @@ def auth_status() -> None:
|
|
|
60
59
|
print(f"{user_info.true_name}({user_info.user_name})登录过期,请重新登录")
|
|
61
60
|
else:
|
|
62
61
|
if application is None:
|
|
63
|
-
|
|
62
|
+
typer.echo(
|
|
63
|
+
f"{user_info.true_name}({user_info.user_name})已登录, 应用未设置\n请执行 data-ops-cli auth application set <应用code> 设置应用",
|
|
64
|
+
err=True,
|
|
65
|
+
)
|
|
66
|
+
raise typer.Exit(code=1)
|
|
64
67
|
else:
|
|
65
|
-
|
|
68
|
+
typer.echo(
|
|
66
69
|
f"{user_info.true_name}({user_info.user_name})已登录, 应用设置为{application.LABEL_CN}({application.CODE})"
|
|
67
70
|
)
|
|
68
71
|
|
|
@@ -1,29 +1,40 @@
|
|
|
1
1
|
"""数据集管理命令组.
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
提供数据集的列表查询、详情、数据量统计与实际数据获取。
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
|
+
from pathlib import Path
|
|
6
7
|
from typing import Annotated
|
|
7
8
|
|
|
8
9
|
import typer
|
|
10
|
+
from pydantic_core import to_json
|
|
11
|
+
|
|
9
12
|
from dataops_sdk.exceptions import DataOpsError
|
|
10
|
-
from dataops_sdk.schemas import PageParam, SqlFilter, SqlQueryParam
|
|
13
|
+
from dataops_sdk.schemas import MetaType, PageParam, SqlFilter, SqlQueryParam
|
|
11
14
|
from dataops_sdk.services import (
|
|
15
|
+
release_list_get_by_code,
|
|
12
16
|
release_list_update,
|
|
13
17
|
service_count_dataset_by_code,
|
|
14
18
|
service_get_dataset_data_by_code,
|
|
15
19
|
service_get_dataset_detail_by_code,
|
|
16
20
|
service_list_datasets,
|
|
17
21
|
)
|
|
18
|
-
from dataops_sdk.
|
|
22
|
+
from dataops_sdk.session import get_session
|
|
23
|
+
from dataops_sdk.utils import encrypt_body, filter_nodes_by_pattern
|
|
19
24
|
|
|
20
25
|
from dataops_cli.cli.utils import print_list, print_table_column_detail
|
|
21
26
|
|
|
27
|
+
# 数据集 rawData 中承载 SQL 定义的字段名(subType=sql 的数据集均有此字段)。
|
|
28
|
+
SQL_FIELD = "text"
|
|
29
|
+
|
|
30
|
+
|
|
22
31
|
dataset_typer = typer.Typer(name="dataset", help="Manage dataset.", no_args_is_help=True)
|
|
23
32
|
update_typer = typer.Typer(name="update", help="变更", no_args_is_help=True)
|
|
24
33
|
dataset_typer.add_typer(update_typer)
|
|
25
34
|
column_typer = typer.Typer(name="column", help="列变更", no_args_is_help=True)
|
|
26
35
|
update_typer.add_typer(column_typer)
|
|
36
|
+
sql_typer = typer.Typer(name="sql", help="SQL 编辑", no_args_is_help=True)
|
|
37
|
+
update_typer.add_typer(sql_typer)
|
|
27
38
|
|
|
28
39
|
|
|
29
40
|
@dataset_typer.command("list")
|
|
@@ -241,3 +252,84 @@ def update_dataset_column(
|
|
|
241
252
|
typer.echo(f"错误: {e.message}")
|
|
242
253
|
raise typer.Exit(code=1) from None
|
|
243
254
|
typer.echo(f"修改数据集 {code} 字段 {column_item.name} 完成")
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def _load_sql(code: str):
|
|
258
|
+
"""校验数据集存在 SQL 字段并返回 Meta;失败统一报错退出."""
|
|
259
|
+
try:
|
|
260
|
+
meta = release_list_get_by_code(MetaType.DATASET, code)
|
|
261
|
+
except DataOpsError as e:
|
|
262
|
+
typer.echo(f"错误: {e.message}", err=True)
|
|
263
|
+
raise typer.Exit(code=1) from None
|
|
264
|
+
data = meta.data
|
|
265
|
+
if not isinstance(data, dict) or not isinstance(data.get(SQL_FIELD), str):
|
|
266
|
+
typer.echo(f"数据集 {code} 未找到 SQL 字段({SQL_FIELD})", err=True)
|
|
267
|
+
raise typer.Exit(code=1)
|
|
268
|
+
return meta
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def _save_sql(meta, sql: str) -> None:
|
|
272
|
+
"""整段替换 SQL 并保存:先解析字段回填 columns(失败仅警告),保存失败统一报错."""
|
|
273
|
+
meta.data[SQL_FIELD] = sql
|
|
274
|
+
try:
|
|
275
|
+
meta_payload = meta.model_dump(mode="json", exclude={"data"})
|
|
276
|
+
meta_payload["rawData"] = to_json(meta.data).decode()
|
|
277
|
+
with get_session() as session:
|
|
278
|
+
resp = session.post(
|
|
279
|
+
"/data/dataset/analysis",
|
|
280
|
+
content=to_json(encrypt_body({"meta": meta_payload, "params": []})),
|
|
281
|
+
)
|
|
282
|
+
resp.raise_for_status()
|
|
283
|
+
meta.data["columns"] = resp.json()["data"]["columns"]
|
|
284
|
+
typer.echo(f"字段解析完成({len(meta.data['columns'])} 列)")
|
|
285
|
+
except Exception as e:
|
|
286
|
+
typer.echo(f"⚠️ 字段解析失败,仅保存 SQL: {e}", err=True)
|
|
287
|
+
try:
|
|
288
|
+
release_list_update(meta)
|
|
289
|
+
except DataOpsError as e:
|
|
290
|
+
typer.echo(f"错误: {e.message}", err=True)
|
|
291
|
+
raise typer.Exit(code=1) from None
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
@sql_typer.command("edit", no_args_is_help=True)
|
|
295
|
+
def edit_dataset_sql(
|
|
296
|
+
code: Annotated[str, typer.Argument(help="数据集编码")],
|
|
297
|
+
old_texts: Annotated[
|
|
298
|
+
list[str],
|
|
299
|
+
typer.Option("--old-text", help="待替换文本(可多次传入,与 --new-text 一一对应)"),
|
|
300
|
+
],
|
|
301
|
+
new_texts: Annotated[
|
|
302
|
+
list[str],
|
|
303
|
+
typer.Option("--new-text", help="替换后的文本(与 --old-text 一一对应)"),
|
|
304
|
+
],
|
|
305
|
+
) -> None:
|
|
306
|
+
"""按 --old-text/--new-text 成对精准替换 SQL 文本."""
|
|
307
|
+
if len(old_texts) != len(new_texts):
|
|
308
|
+
typer.echo("参数 --old-text 与 --new-text 数量不一致", err=True)
|
|
309
|
+
raise typer.Exit(code=1)
|
|
310
|
+
meta = _load_sql(code)
|
|
311
|
+
content = meta.data[SQL_FIELD]
|
|
312
|
+
for idx, (old, new) in enumerate(zip(old_texts, new_texts), start=1):
|
|
313
|
+
if old not in content:
|
|
314
|
+
typer.echo(f"[{idx}] 未找到匹配文本 {old}", err=True)
|
|
315
|
+
raise typer.Exit(code=1)
|
|
316
|
+
content = content.replace(old, new, count=1)
|
|
317
|
+
_save_sql(meta, content)
|
|
318
|
+
typer.echo(f"数据集 {code} SQL 更新成功")
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
@sql_typer.command("write", no_args_is_help=True)
|
|
322
|
+
def write_dataset_sql(
|
|
323
|
+
code: Annotated[str, typer.Argument(help="数据集编码")],
|
|
324
|
+
file: Annotated[Path | None, typer.Argument(help="输入文件路径")] = None,
|
|
325
|
+
content: Annotated[str | None, typer.Option("--content", help="SQL 内容")] = None,
|
|
326
|
+
) -> None:
|
|
327
|
+
"""整段写入 SQL,file 与 --content 至少指定一个."""
|
|
328
|
+
if file:
|
|
329
|
+
content = file.read_text(encoding="utf-8")
|
|
330
|
+
elif not content:
|
|
331
|
+
typer.echo("参数 file 或 --content 必须指定一个", err=True)
|
|
332
|
+
raise typer.Exit(code=1)
|
|
333
|
+
meta = _load_sql(code)
|
|
334
|
+
_save_sql(meta, content)
|
|
335
|
+
typer.echo(f"数据集 {code} SQL 写入成功")
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"""字典(dict)管理命令组.
|
|
2
|
+
|
|
3
|
+
提供数据源字典的列表查询、详情查看、字典树以及字段增删改能力。
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from typing import Annotated
|
|
9
|
+
|
|
10
|
+
import typer
|
|
11
|
+
from dataops_sdk.exceptions import DataOpsError
|
|
12
|
+
from dataops_sdk.schemas import MetaType
|
|
13
|
+
from dataops_sdk.services.dict_ import (
|
|
14
|
+
service_get_dict_detail_by_code,
|
|
15
|
+
service_get_dict_detail_by_name,
|
|
16
|
+
service_list_dicts,
|
|
17
|
+
servive_tree_dict,
|
|
18
|
+
)
|
|
19
|
+
from dataops_sdk.services.meta import release_list_get_by_code, release_list_update
|
|
20
|
+
from dataops_sdk.utils import filter_nodes_by_pattern
|
|
21
|
+
|
|
22
|
+
from dataops_cli.cli.utils import print_group_tree, print_list
|
|
23
|
+
|
|
24
|
+
dict_typer = typer.Typer(name="dict", help="Manage dict.", no_args_is_help=True)
|
|
25
|
+
field_typer = typer.Typer(name="field", help="字典字段变更", no_args_is_help=True)
|
|
26
|
+
dict_typer.add_typer(field_typer)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _find_option_index(options: list, value: str) -> int | None:
|
|
30
|
+
"""在 options 列表中按 value 查找下标,未找到返回 None."""
|
|
31
|
+
return next((i for i, o in enumerate(options) if str(o.get("value")) == value), None)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dict_typer.command("list")
|
|
35
|
+
def list_dict(
|
|
36
|
+
datasource: Annotated[str, typer.Argument(help="数据源")],
|
|
37
|
+
query: Annotated[str | None, typer.Option("-q", "--query", help="字典名称关键字")] = None,
|
|
38
|
+
) -> None:
|
|
39
|
+
"""列出数据源中的字典列表。
|
|
40
|
+
|
|
41
|
+
支持通过关键字过滤字典名称,并支持正则表达式匹配。
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
datasource: 数据源名称。
|
|
45
|
+
query: 可选字典名称关键字(支持正则)。
|
|
46
|
+
|
|
47
|
+
Examples:
|
|
48
|
+
# 列出指定数据源的所有字典
|
|
49
|
+
>>> data-ops-cli dict list <datasource>
|
|
50
|
+
|
|
51
|
+
# 列出数据源中名称包含 "user" 的字典
|
|
52
|
+
>>> data-ops-cli dict list <datasource> -q user
|
|
53
|
+
|
|
54
|
+
# 使用正则过滤字典名
|
|
55
|
+
>>> data-ops-cli dict list <datasource> -q "^user_.*"
|
|
56
|
+
"""
|
|
57
|
+
try:
|
|
58
|
+
group_nodes = service_list_dicts(datasource)
|
|
59
|
+
except DataOpsError as e:
|
|
60
|
+
typer.echo(f"错误: {e.message}")
|
|
61
|
+
raise typer.Exit(code=1) from None
|
|
62
|
+
|
|
63
|
+
if not group_nodes:
|
|
64
|
+
print("未查询到匹配字典")
|
|
65
|
+
return
|
|
66
|
+
|
|
67
|
+
if query:
|
|
68
|
+
group_nodes = filter_nodes_by_pattern(group_nodes, query)
|
|
69
|
+
|
|
70
|
+
print_list(
|
|
71
|
+
["code", "name", "alias"],
|
|
72
|
+
[[column.code, column.name, column.title] for column in group_nodes],
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@dict_typer.command("detail", no_args_is_help=True)
|
|
77
|
+
def get_dict_detail(
|
|
78
|
+
arg1: Annotated[str, typer.Argument(help="编码或数据源")],
|
|
79
|
+
name: Annotated[str | None, typer.Argument(help="字典名称")] = None,
|
|
80
|
+
) -> None:
|
|
81
|
+
"""获取字典详情信息。
|
|
82
|
+
|
|
83
|
+
支持两种查询方式:
|
|
84
|
+
|
|
85
|
+
1. 通过字典编码(CODE)直接查询
|
|
86
|
+
2. 通过数据源名称和字典名称组合查询
|
|
87
|
+
|
|
88
|
+
默认只显示字典选项的基本信息(label/value)
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
arg1: 字典编码;当同时提供 ``name`` 时为数据源名称。
|
|
92
|
+
name: 可选字典名称。
|
|
93
|
+
|
|
94
|
+
Examples:
|
|
95
|
+
# 通过字典编码查询字典结构
|
|
96
|
+
>>> data-ops-cli dict detail dict_code_123
|
|
97
|
+
|
|
98
|
+
# 通过数据源和字典名查询
|
|
99
|
+
>>> data-ops-cli dict detail <datasource> my_dict
|
|
100
|
+
"""
|
|
101
|
+
try:
|
|
102
|
+
meta = (
|
|
103
|
+
service_get_dict_detail_by_name(arg1, name)
|
|
104
|
+
if name
|
|
105
|
+
else service_get_dict_detail_by_code(arg1)
|
|
106
|
+
)
|
|
107
|
+
except DataOpsError as e:
|
|
108
|
+
typer.echo(f"错误: {e.message}")
|
|
109
|
+
raise typer.Exit(code=1) from None
|
|
110
|
+
print(f"{meta.name}({meta.title})")
|
|
111
|
+
print_list(["value", "label"], [[option.value, option.label] for option in meta.data.options])
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
@dict_typer.command("tree")
|
|
115
|
+
def tree_dict(
|
|
116
|
+
query: Annotated[str | None, typer.Option("-q", "--query", help="字典名称关键字")] = None,
|
|
117
|
+
) -> None:
|
|
118
|
+
"""展示字典树结构。
|
|
119
|
+
|
|
120
|
+
Args:
|
|
121
|
+
query: 字典名称关键字(支持正则)。
|
|
122
|
+
"""
|
|
123
|
+
try:
|
|
124
|
+
tree = servive_tree_dict()
|
|
125
|
+
except DataOpsError as e:
|
|
126
|
+
typer.echo(f"错误: {e.message}")
|
|
127
|
+
raise typer.Exit(code=1) from None
|
|
128
|
+
print_group_tree(tree, query)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
@field_typer.command("add", no_args_is_help=True)
|
|
132
|
+
def add_field(
|
|
133
|
+
code: Annotated[str, typer.Argument(help="字典编码")],
|
|
134
|
+
value: Annotated[str, typer.Argument(help="选项值")],
|
|
135
|
+
label: Annotated[str, typer.Argument(help="选项标签")],
|
|
136
|
+
) -> None:
|
|
137
|
+
"""新增字典字段。
|
|
138
|
+
|
|
139
|
+
Args:
|
|
140
|
+
code: 字典编码。
|
|
141
|
+
value: 选项值。
|
|
142
|
+
label: 选项标签。
|
|
143
|
+
|
|
144
|
+
Examples:
|
|
145
|
+
# 单条新增
|
|
146
|
+
>>> data-ops-cli dict field add dict_code_001 3 第三选项
|
|
147
|
+
"""
|
|
148
|
+
try:
|
|
149
|
+
meta = release_list_get_by_code(MetaType.DICT, code)
|
|
150
|
+
options = meta.data.setdefault("options", []) if meta.data else []
|
|
151
|
+
if any(str(o.get("value")) == value for o in options):
|
|
152
|
+
typer.echo(f"字典 {code} 中已存在 value={value}", err=True)
|
|
153
|
+
raise typer.Exit(code=1)
|
|
154
|
+
options.append({"value": value, "label": label, "id": ""})
|
|
155
|
+
release_list_update(meta, datasource=meta.subSystem)
|
|
156
|
+
except DataOpsError as e:
|
|
157
|
+
typer.echo(f"错误: {e.message}")
|
|
158
|
+
raise typer.Exit(code=1) from None
|
|
159
|
+
print(f"新增 {code} {value} 完成")
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
@field_typer.command("edit", no_args_is_help=True)
|
|
163
|
+
def edit_field(
|
|
164
|
+
code: Annotated[str, typer.Argument(help="字典编码")],
|
|
165
|
+
value: Annotated[str, typer.Argument(help="选项值")],
|
|
166
|
+
label: Annotated[str, typer.Argument(help="新标签")],
|
|
167
|
+
) -> None:
|
|
168
|
+
"""编辑字典字段标签。
|
|
169
|
+
|
|
170
|
+
Args:
|
|
171
|
+
code: 字典编码。
|
|
172
|
+
value: 要修改的选项值。
|
|
173
|
+
label: 新的标签名。
|
|
174
|
+
|
|
175
|
+
Examples:
|
|
176
|
+
>>> data-ops-cli dict field edit dict_code_001 0 禁用
|
|
177
|
+
"""
|
|
178
|
+
try:
|
|
179
|
+
meta = release_list_get_by_code(MetaType.DICT, code)
|
|
180
|
+
options = meta.data.get("options", []) if meta.data else []
|
|
181
|
+
idx = _find_option_index(options, value)
|
|
182
|
+
if idx is None:
|
|
183
|
+
typer.echo(f"字典中不存在选项: {value}", err=True)
|
|
184
|
+
raise typer.Exit(code=1)
|
|
185
|
+
options[idx]["label"] = label
|
|
186
|
+
release_list_update(meta, datasource=meta.subSystem)
|
|
187
|
+
except DataOpsError as e:
|
|
188
|
+
typer.echo(f"错误: {e.message}")
|
|
189
|
+
raise typer.Exit(code=1) from None
|
|
190
|
+
print(f"修改 {code} {value} 完成")
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
@field_typer.command("delete", no_args_is_help=True)
|
|
194
|
+
def delete_field(
|
|
195
|
+
code: Annotated[str, typer.Argument(help="字典编码")],
|
|
196
|
+
value: Annotated[str, typer.Argument(help="选项值")],
|
|
197
|
+
) -> None:
|
|
198
|
+
"""删除字典字段。
|
|
199
|
+
|
|
200
|
+
Args:
|
|
201
|
+
code: 字典编码。
|
|
202
|
+
value: 要删除的选项值。
|
|
203
|
+
|
|
204
|
+
Examples:
|
|
205
|
+
>>> data-ops-cli dict field delete dict_code_001 0
|
|
206
|
+
"""
|
|
207
|
+
try:
|
|
208
|
+
meta = release_list_get_by_code(MetaType.DICT, code)
|
|
209
|
+
options = meta.data.get("options", []) if meta.data else []
|
|
210
|
+
idx = _find_option_index(options, value)
|
|
211
|
+
if idx is None:
|
|
212
|
+
typer.echo(f"字典中不存在选项: {value}", err=True)
|
|
213
|
+
raise typer.Exit(code=1)
|
|
214
|
+
options.pop(idx)
|
|
215
|
+
release_list_update(meta, datasource=meta.subSystem)
|
|
216
|
+
except DataOpsError as e:
|
|
217
|
+
typer.echo(f"错误: {e.message}")
|
|
218
|
+
raise typer.Exit(code=1) from None
|
|
219
|
+
print(f"删除 {code} {value} 完成")
|
|
@@ -29,7 +29,6 @@ def ref_forward(
|
|
|
29
29
|
ref_types: Annotated[
|
|
30
30
|
str, typer.Option(help="允许的被引用类型,使用 , 分割(e.g. table,dict,dataset)")
|
|
31
31
|
] = "",
|
|
32
|
-
full: Annotated[bool, typer.Option(help="是否显示更多内容")] = False,
|
|
33
32
|
) -> None:
|
|
34
33
|
"""正向引用查询,查询指定资源引用了哪些其他资源。
|
|
35
34
|
|
|
@@ -58,11 +57,7 @@ def ref_forward(
|
|
|
58
57
|
typer.echo(f"错误: {e.message}")
|
|
59
58
|
raise typer.Exit(code=1) from None
|
|
60
59
|
|
|
61
|
-
headers = (
|
|
62
|
-
("ref-code", "ref-type", "ref-name", "ref-title")
|
|
63
|
-
if full
|
|
64
|
-
else ("ref-code", "ref-type", "ref-name")
|
|
65
|
-
)
|
|
60
|
+
headers = ("ref-code", "ref-type", "ref-name", "ref-title")
|
|
66
61
|
print("引用关系查询")
|
|
67
62
|
print_list(
|
|
68
63
|
headers,
|
|
@@ -73,12 +68,6 @@ def ref_forward(
|
|
|
73
68
|
result.refName if result.refName != result.refCode else "",
|
|
74
69
|
result.refTitle,
|
|
75
70
|
]
|
|
76
|
-
if full
|
|
77
|
-
else [
|
|
78
|
-
result.refCode,
|
|
79
|
-
result.refType,
|
|
80
|
-
result.refName if result.refName != result.refCode else "",
|
|
81
|
-
]
|
|
82
71
|
for result in results
|
|
83
72
|
],
|
|
84
73
|
)
|
|
@@ -89,9 +78,8 @@ def ref_backward(
|
|
|
89
78
|
type: Annotated[MetaType, typer.Argument(help="被引用类型")],
|
|
90
79
|
code: Annotated[str, typer.Argument(help="被引用编码")],
|
|
91
80
|
ref_types: Annotated[
|
|
92
|
-
MetaType, typer.Option(help="允许的引用类型,使用 , 分割(e.g. table,dict,dataset)")
|
|
93
|
-
]
|
|
94
|
-
full: Annotated[bool, typer.Option(help="是否显示更多内容")] = False,
|
|
81
|
+
list[MetaType], typer.Option(help="允许的引用类型,使用 , 分割(e.g. table,dict,dataset)")
|
|
82
|
+
],
|
|
95
83
|
) -> None:
|
|
96
84
|
"""反向引用查询,查询哪些资源引用了指定资源。
|
|
97
85
|
|
|
@@ -101,7 +89,6 @@ def ref_backward(
|
|
|
101
89
|
type: 被引用资源的类型,如 table、dict、dataset 等。
|
|
102
90
|
code: 被引用资源的编码,唯一标识。
|
|
103
91
|
ref_types: 可选,限定引用者的资源类型,多个用逗号分隔。
|
|
104
|
-
full: 可选,显示完整信息包括 title 字段。
|
|
105
92
|
|
|
106
93
|
Examples:
|
|
107
94
|
# 查询哪些资源引用了指定表
|
|
@@ -113,7 +100,7 @@ def ref_backward(
|
|
|
113
100
|
# 显示完整信息
|
|
114
101
|
>>> data-ops-cli ref backward table t_user --full
|
|
115
102
|
"""
|
|
116
|
-
filter_types = ref_types
|
|
103
|
+
filter_types = ref_types or None
|
|
117
104
|
try:
|
|
118
105
|
results = service_ref_backward(type, code, filter_types)
|
|
119
106
|
except DataOpsError as e:
|
|
@@ -121,7 +108,7 @@ def ref_backward(
|
|
|
121
108
|
raise typer.Exit(code=1) from None
|
|
122
109
|
|
|
123
110
|
print("被引用关系查询")
|
|
124
|
-
headers = ("code", "type", "name", "title")
|
|
111
|
+
headers = ("code", "type", "name", "title")
|
|
125
112
|
print_list(
|
|
126
113
|
headers,
|
|
127
114
|
[
|
|
@@ -131,8 +118,6 @@ def ref_backward(
|
|
|
131
118
|
result.name if result.name != result.code else "",
|
|
132
119
|
result.title,
|
|
133
120
|
]
|
|
134
|
-
if full
|
|
135
|
-
else [result.code, result.type, result.name if result.name != result.code else ""]
|
|
136
121
|
for result in results
|
|
137
122
|
],
|
|
138
123
|
)
|
|
@@ -14,7 +14,6 @@ import typer
|
|
|
14
14
|
from dataops_cli.cli.utils import paginate_with_line_numbers, print_list
|
|
15
15
|
from dataops_sdk.exceptions import DataOpsError
|
|
16
16
|
from dataops_sdk.schemas import MetaSkillFileSubType, MetaSkillSubType, MetaType
|
|
17
|
-
from dataops_sdk.schemas.enums import GroupNodeRefType
|
|
18
17
|
from dataops_sdk.services import (
|
|
19
18
|
SkillPackValidationError,
|
|
20
19
|
service_delete_skill,
|
|
@@ -123,41 +122,28 @@ def detail_cmd(
|
|
|
123
122
|
|
|
124
123
|
@skill_typer.command("upload", no_args_is_help=True)
|
|
125
124
|
def upload_cmd(
|
|
126
|
-
space_code: Annotated[
|
|
127
|
-
str, typer.Argument(help="空间编码 (通过 ``report sapce list`` 查看空间编码)")
|
|
128
|
-
],
|
|
129
125
|
file: Annotated[Path, typer.Argument(help="技能 ZIP 文件路径")],
|
|
130
126
|
dtype: Annotated[
|
|
131
127
|
MetaSkillSubType,
|
|
132
128
|
typer.Option("--type", help="技能子类型"),
|
|
133
129
|
],
|
|
134
|
-
ref_node_id: Annotated[
|
|
135
|
-
str | None, typer.Option("--ref-node-id", help="引用节点ID (通过 `report sapce tree` 查看)")
|
|
136
|
-
] = None,
|
|
137
|
-
ref_type: Annotated[
|
|
138
|
-
GroupNodeRefType,
|
|
139
|
-
typer.Option("--ref-type", help="引用节点类型 (放置在引用节点前、后还是内)"),
|
|
140
|
-
] = GroupNodeRefType.AFTER,
|
|
141
130
|
title: Annotated[str | None, typer.Option("--title", help="技能简体中文名称")] = None,
|
|
142
131
|
) -> None:
|
|
143
|
-
"""从 ZIP
|
|
132
|
+
"""从 ZIP 包上传技能。
|
|
144
133
|
|
|
145
134
|
Examples:
|
|
146
|
-
|
|
147
|
-
>>> data-ops-cli skill
|
|
135
|
+
>>> data-ops-cli skill upload my-skill.zip --type api
|
|
136
|
+
>>> data-ops-cli skill upload my-skill.zip --type llm --title "天气查询"
|
|
148
137
|
"""
|
|
149
138
|
if not file.exists():
|
|
150
139
|
typer.echo(f"错误: 文件不存在 {file}")
|
|
151
140
|
raise typer.Exit(code=2)
|
|
152
141
|
|
|
153
142
|
try:
|
|
154
|
-
|
|
143
|
+
service_skill_upload(
|
|
155
144
|
file_path=str(file),
|
|
156
145
|
sub_type=dtype,
|
|
157
146
|
title=title,
|
|
158
|
-
group_name=space_code,
|
|
159
|
-
ref_node_id=ref_node_id,
|
|
160
|
-
ref_type=ref_type,
|
|
161
147
|
)
|
|
162
148
|
except DataOpsError as e:
|
|
163
149
|
typer.echo(f"错误: {e.message}")
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"""字典(dict)管理命令组.
|
|
2
|
-
|
|
3
|
-
提供数据源字典的列表查询与详情查看能力。
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
from typing import Annotated
|
|
7
|
-
|
|
8
|
-
import typer
|
|
9
|
-
from dataops_sdk.exceptions import DataOpsError
|
|
10
|
-
from dataops_sdk.services.dict_ import (
|
|
11
|
-
service_get_dict_detail_by_code,
|
|
12
|
-
service_get_dict_detail_by_name,
|
|
13
|
-
service_list_dicts,
|
|
14
|
-
)
|
|
15
|
-
from dataops_sdk.utils import filter_nodes_by_pattern
|
|
16
|
-
|
|
17
|
-
from dataops_cli.cli.utils import print_list
|
|
18
|
-
|
|
19
|
-
dict_typer = typer.Typer(name="dict", help="Manage dict.", no_args_is_help=True)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
@dict_typer.command("list")
|
|
23
|
-
def list_dict(
|
|
24
|
-
datasource: Annotated[str, typer.Argument(help="数据源")],
|
|
25
|
-
query: Annotated[str | None, typer.Option("-q", "--query", help="字典名称关键字")] = None,
|
|
26
|
-
) -> None:
|
|
27
|
-
"""列出数据源中的字典列表。
|
|
28
|
-
|
|
29
|
-
支持通过关键字过滤字典名称,并支持正则表达式匹配。
|
|
30
|
-
|
|
31
|
-
Args:
|
|
32
|
-
datasource: 数据源名称。
|
|
33
|
-
query: 可选字典名称关键字(支持正则)。
|
|
34
|
-
|
|
35
|
-
Examples:
|
|
36
|
-
# 列出指定数据源的所有字典
|
|
37
|
-
>>> data-ops-cli dict list <datasource>
|
|
38
|
-
|
|
39
|
-
# 列出数据源中名称包含 "user" 的字典
|
|
40
|
-
>>> data-ops-cli dict list <datasource> -q user
|
|
41
|
-
|
|
42
|
-
# 使用正则过滤字典名
|
|
43
|
-
>>> data-ops-cli dict list <datasource> -q "^user_.*"
|
|
44
|
-
"""
|
|
45
|
-
try:
|
|
46
|
-
group_nodes = service_list_dicts(datasource)
|
|
47
|
-
except DataOpsError as e:
|
|
48
|
-
typer.echo(f"错误: {e.message}")
|
|
49
|
-
raise typer.Exit(code=1) from None
|
|
50
|
-
|
|
51
|
-
if not group_nodes:
|
|
52
|
-
print("未查询到匹配字典")
|
|
53
|
-
return
|
|
54
|
-
|
|
55
|
-
if query:
|
|
56
|
-
group_nodes = filter_nodes_by_pattern(group_nodes, query)
|
|
57
|
-
|
|
58
|
-
print_list(
|
|
59
|
-
["code", "name", "alias"],
|
|
60
|
-
[[column.code, column.name, column.title] for column in group_nodes],
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
@dict_typer.command("detail", no_args_is_help=True)
|
|
65
|
-
def get_dict_detail(
|
|
66
|
-
arg1: Annotated[str, typer.Argument(help="编码或数据源")],
|
|
67
|
-
name: Annotated[str | None, typer.Argument(help="字典名称")] = None,
|
|
68
|
-
# full: Annotated[bool, typer.Option("--full", help="是否显示完整信息")] = False,
|
|
69
|
-
) -> None:
|
|
70
|
-
"""获取字典详情信息。
|
|
71
|
-
|
|
72
|
-
支持两种查询方式:
|
|
73
|
-
|
|
74
|
-
1. 通过字典编码(CODE)直接查询
|
|
75
|
-
2. 通过数据源名称和字典名称组合查询
|
|
76
|
-
|
|
77
|
-
默认只显示字典选项的基本信息(label/value)
|
|
78
|
-
|
|
79
|
-
Args:
|
|
80
|
-
arg1: 字典编码;当同时提供 ``name`` 时为数据源名称。
|
|
81
|
-
name: 可选字典名称。
|
|
82
|
-
full: 是否显示完整信息。
|
|
83
|
-
|
|
84
|
-
Examples:
|
|
85
|
-
# 通过字典编码查询字典结构
|
|
86
|
-
>>> data-ops-cli dict detail dict_code_123
|
|
87
|
-
|
|
88
|
-
# 通过数据源和字典名查询
|
|
89
|
-
>>> data-ops-cli dict detail <datasource> my_dict
|
|
90
|
-
"""
|
|
91
|
-
try:
|
|
92
|
-
meta = (
|
|
93
|
-
service_get_dict_detail_by_name(arg1, name)
|
|
94
|
-
if name
|
|
95
|
-
else service_get_dict_detail_by_code(arg1)
|
|
96
|
-
)
|
|
97
|
-
except DataOpsError as e:
|
|
98
|
-
typer.echo(f"错误: {e.message}")
|
|
99
|
-
raise typer.Exit(code=1) from None
|
|
100
|
-
print(f"{meta.name}({meta.title})")
|
|
101
|
-
print_list(["value", "label"], [[option.value, option.label] for option in meta.data.options])
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|