data-ops-cli 0.4.4__py3-none-any.whl → 0.5.0__py3-none-any.whl

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: data-ops-cli
3
- Version: 0.4.4
3
+ Version: 0.5.0
4
4
  Summary: Command-line wrapper around dataops_sdk for the DataOps platform.
5
5
  Requires-Python: >=3.11
6
6
  Description-Content-Type: text/markdown
@@ -1,4 +1,4 @@
1
- dataops_cli/__init__.py,sha256=d2UbjTUlGOYW8qIAevDzt7p5UK-gHNuXe_HdIPXY0Ws,745
1
+ dataops_cli/__init__.py,sha256=WCSp3mG9jjdwMCbBy8nh1KcuzCtbCNuHLXFDIeYydT4,745
2
2
  dataops_cli/_compat.py,sha256=oq4s8oe7gNVJzpMEKSjB6Y6rCKthtPcDgiAkt1aWPB4,3166
3
3
  dataops_cli/exceptions.py,sha256=omc5rexgPapZvNfRjf0iM6FjbbLydjmJF4aia4W-5Pw,262
4
4
  dataops_cli/runner.py,sha256=V8QIHmFHE8EuUqN3YRU9Hf8bHGaGB2N7kyf4dxXlLK4,439
@@ -10,24 +10,24 @@ dataops_cli/cli/__init__.py,sha256=ybTH636cmgbHI6Uob8cWQl1ThoPZ9spBWWmzMjdqmmI,2
10
10
  dataops_cli/cli/alarm.py,sha256=_4wjm6y9bMNuxQEva4I9fro42gC2xfnSAkXU8fLovpo,25724
11
11
  dataops_cli/cli/api.py,sha256=NisNPMYn-dV-9mpYlq9HAlcNSp4XrqQWaQqJ8im0rUY,7334
12
12
  dataops_cli/cli/auth.py,sha256=ZXkvbpfMPJVVq2hxie8QfcIjM5m6ChZ8ovwrhzDahk0,7385
13
- dataops_cli/cli/data_table.py,sha256=XRMi1i5ZyWP55L_zLzWfWreXQcxG9W4cOEhVTth3IXs,12494
14
- dataops_cli/cli/dataset.py,sha256=7h5GKxggCBr7py51-Gcg3uADyX_3sbPN3kSPoej7Nuc,13016
13
+ dataops_cli/cli/data_table.py,sha256=PcZtAwLehFmi2UrB1Iicp4SYj4aBt_miOFcuqqai0T8,12510
14
+ dataops_cli/cli/dataset.py,sha256=-QXO21ZAgcnoqs6cwIx9MN7gJWzPIdXiP1SyaiJjIeA,9288
15
15
  dataops_cli/cli/datasource.py,sha256=pMXBBeec3TBq4YUXFoJbwXas_7B82S18Xs1JB-8R4eA,8096
16
- dataops_cli/cli/dict_.py,sha256=DAfXZxnl_o6r4-duCeSyKL0_qK0Zl7I9JYHKFTMeLIk,7240
17
- dataops_cli/cli/factory.py,sha256=2gqIRUzHt_uYwG-6RzCSFRV3XHdCNG6L9LProJwFF1I,2871
16
+ dataops_cli/cli/dict_.py,sha256=sGnwkbamfj9pzpF1NHF9TCadYooTXRBBNiXjnwZUI70,3661
17
+ dataops_cli/cli/factory.py,sha256=wZMKuevNw3szoDc7FS4WS6ahoEkmyCSAa_07TwcjrZ8,2948
18
18
  dataops_cli/cli/hazard.py,sha256=Jl6XX2iJNPJa-PClyWIct44PNCBk0p04tpS44gMad4c,13773
19
- dataops_cli/cli/kb.py,sha256=Abp7LWxe-fohL-vILxvNm4YMGP53725MLx1LvOQkn7E,7149
20
19
  dataops_cli/cli/metrics.py,sha256=FwMG4XANl-KQupp1KJtXve_gaw9RxrO6Ah1PmP-UgJ4,8876
21
- dataops_cli/cli/ref.py,sha256=ZjKW4WjjdIZgngwKp8y7vrHW4m0Z_APyCcI6mell7y4,4257
22
- dataops_cli/cli/report.py,sha256=BSYKblaDKzOl-OXl5ZWhABSSCwJr10T6DpG7hqVYNrk,4717
23
- dataops_cli/cli/skill.py,sha256=dg2-b_FJXOPCFNvAwaxgmlOhYbrcV5-d44M7nK1O7jo,12908
20
+ dataops_cli/cli/ontology.py,sha256=jIKDY0YJZkklg5ISsZ5-tpUqzH97To8NXsMHhA8W3aU,10116
21
+ dataops_cli/cli/ref.py,sha256=wW-gACSUQeL4LOcLiPpmnNvYlhKPBL18NjOskeIRIvY,4938
22
+ dataops_cli/cli/report.py,sha256=cq0l0X5n3ZS5WkgAjeHC1INgNjIa2RINuWKQjK2QWQE,4557
23
+ dataops_cli/cli/skill.py,sha256=QBFUCoT2NCdU6rskvu3Ftn5vyvXiiq3kc8zD4AXn7DQ,13783
24
24
  dataops_cli/cli/table.py,sha256=jFUk7PZ_ZOR0SFT1HyJ5G-gyfmPwPJP1viJ9NHZ24HQ,24716
25
25
  dataops_cli/cli/tag.py,sha256=Jj_IxhhUQ9oQ2bKz_zcVrGFxhTnaowlTrrjRvMMqyew,9867
26
26
  dataops_cli/cli/utils.py,sha256=jI9VT05lm2MX_3BXGgi2VHnR3JVF-bGZ5OfshbE94VU,8176
27
27
  dataops_cli/cli/widget.py,sha256=4_daWMOoCp7InFhKRs3XS_auhfglV1NVxeavosYHTtU,26888
28
- dataops_cli/cli/workflow.py,sha256=sZg4EuChtKAQAZRdAHeS1Nj9PKPdAxvOLmvad8JVjUY,7912
29
- data_ops_cli-0.4.4.dist-info/METADATA,sha256=z4icDrxdxLCRmDiW2tjo0iQIgyPEVf7kKWLzICMguFU,1706
30
- data_ops_cli-0.4.4.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
31
- data_ops_cli-0.4.4.dist-info/entry_points.txt,sha256=vc_2b5byVdLofaQ2ppuPM484AcaZnGsaHdcMKmtcSkU,53
32
- data_ops_cli-0.4.4.dist-info/top_level.txt,sha256=KFHplpKxwE9_wWypzVLESa4eLkOBsk-iUD_Qbld2IcY,12
33
- data_ops_cli-0.4.4.dist-info/RECORD,,
28
+ dataops_cli/cli/workflow.py,sha256=JZIR1a3nxrPQ2zRZCCnvABLz-eJ5JL7bFXOvMFm2LQ0,8004
29
+ data_ops_cli-0.5.0.dist-info/METADATA,sha256=QUKwrfUEmNBmy9eKkq9J74iXcy01Ei_R5UiWX4MfYKk,1706
30
+ data_ops_cli-0.5.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
31
+ data_ops_cli-0.5.0.dist-info/entry_points.txt,sha256=vc_2b5byVdLofaQ2ppuPM484AcaZnGsaHdcMKmtcSkU,53
32
+ data_ops_cli-0.5.0.dist-info/top_level.txt,sha256=KFHplpKxwE9_wWypzVLESa4eLkOBsk-iUD_Qbld2IcY,12
33
+ data_ops_cli-0.5.0.dist-info/RECORD,,
dataops_cli/__init__.py CHANGED
@@ -14,4 +14,4 @@ groups command modules under :mod:`dataops_cli.cli` and re-exports the package
14
14
  removed in ``dataops_cli`` 1.0.
15
15
  """
16
16
 
17
- __version__ = "0.4.4"
17
+ __version__ = "0.5.0"
@@ -13,8 +13,8 @@ from dataops_sdk.schemas import MetaType, PageParam, SqlFilter, SqlQueryParam
13
13
  from dataops_sdk.services import (
14
14
  service_get_data_table_by_code,
15
15
  service_get_data_table_by_name,
16
- service_get_data_table_data_by_code,
17
- service_get_data_table_data_by_name,
16
+ service_get_data_table_data_ext_by_code,
17
+ service_get_data_table_data_ext_by_name,
18
18
  service_get_data_table_total,
19
19
  )
20
20
  from dataops_sdk.services.meta import release_list_list
@@ -285,9 +285,9 @@ def get_datatable_data(
285
285
 
286
286
  try:
287
287
  datas = (
288
- service_get_data_table_data_by_name(arg1, name, pp, qp)
288
+ service_get_data_table_data_ext_by_name(arg1, name, pp, qp)
289
289
  if name
290
- else service_get_data_table_data_by_code(arg1, pp, qp)
290
+ else service_get_data_table_data_ext_by_code(arg1, pp, qp)
291
291
  )
292
292
  except DataOpsError as e:
293
293
  typer.echo(f"错误: {e.message}", err=True)
@@ -1,40 +1,29 @@
1
1
  """数据集管理命令组.
2
2
 
3
- 提供数据集的列表查询、详情、数据量统计与实际数据获取。
3
+ 提供数据集的列表查询、详情、数据量统计与实际数据获取能力。
4
4
  """
5
5
 
6
- from pathlib import Path
7
6
  from typing import Annotated
8
7
 
9
8
  import typer
10
- from pydantic_core import to_json
11
-
12
9
  from dataops_sdk.exceptions import DataOpsError
13
- from dataops_sdk.schemas import MetaType, PageParam, SqlFilter, SqlQueryParam
10
+ from dataops_sdk.schemas import PageParam, SqlFilter, SqlQueryParam
14
11
  from dataops_sdk.services import (
15
- release_list_get_by_code,
16
12
  release_list_update,
17
13
  service_count_dataset_by_code,
18
14
  service_get_dataset_data_by_code,
19
15
  service_get_dataset_detail_by_code,
20
16
  service_list_datasets,
21
17
  )
22
- from dataops_sdk.session import get_session
23
- from dataops_sdk.utils import encrypt_body, filter_nodes_by_pattern
18
+ from dataops_sdk.utils import filter_nodes_by_pattern
24
19
 
25
20
  from dataops_cli.cli.utils import print_list, print_table_column_detail
26
21
 
27
- # 数据集 rawData 中承载 SQL 定义的字段名(subType=sql 的数据集均有此字段)。
28
- SQL_FIELD = "text"
29
-
30
-
31
22
  dataset_typer = typer.Typer(name="dataset", help="Manage dataset.", no_args_is_help=True)
32
23
  update_typer = typer.Typer(name="update", help="变更", no_args_is_help=True)
33
24
  dataset_typer.add_typer(update_typer)
34
25
  column_typer = typer.Typer(name="column", help="列变更", no_args_is_help=True)
35
26
  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)
38
27
 
39
28
 
40
29
  @dataset_typer.command("list")
@@ -252,84 +241,3 @@ def update_dataset_column(
252
241
  typer.echo(f"错误: {e.message}")
253
242
  raise typer.Exit(code=1) from None
254
243
  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 写入成功")
dataops_cli/cli/dict_.py CHANGED
@@ -1,34 +1,23 @@
1
1
  """字典(dict)管理命令组.
2
2
 
3
- 提供数据源字典的列表查询、详情查看、字典树以及字段增删改能力。
3
+ 提供数据源字典的列表查询与详情查看能力。
4
4
  """
5
5
 
6
- from __future__ import annotations
7
-
8
6
  from typing import Annotated
9
7
 
10
8
  import typer
11
9
  from dataops_sdk.exceptions import DataOpsError
12
- from dataops_sdk.schemas import MetaType
13
10
  from dataops_sdk.services.dict_ import (
14
11
  service_get_dict_detail_by_code,
15
12
  service_get_dict_detail_by_name,
16
13
  service_list_dicts,
17
14
  servive_tree_dict,
18
15
  )
19
- from dataops_sdk.services.meta import release_list_get_by_code, release_list_update
20
16
  from dataops_sdk.utils import filter_nodes_by_pattern
21
17
 
22
18
  from dataops_cli.cli.utils import print_group_tree, print_list
23
19
 
24
20
  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
21
 
33
22
 
34
23
  @dict_typer.command("list")
@@ -77,6 +66,7 @@ def list_dict(
77
66
  def get_dict_detail(
78
67
  arg1: Annotated[str, typer.Argument(help="编码或数据源")],
79
68
  name: Annotated[str | None, typer.Argument(help="字典名称")] = None,
69
+ # full: Annotated[bool, typer.Option("--full", help="是否显示完整信息")] = False,
80
70
  ) -> None:
81
71
  """获取字典详情信息。
82
72
 
@@ -90,6 +80,7 @@ def get_dict_detail(
90
80
  Args:
91
81
  arg1: 字典编码;当同时提供 ``name`` 时为数据源名称。
92
82
  name: 可选字典名称。
83
+ full: 是否显示完整信息。
93
84
 
94
85
  Examples:
95
86
  # 通过字典编码查询字典结构
@@ -126,94 +117,3 @@ def tree_dict(
126
117
  typer.echo(f"错误: {e.message}")
127
118
  raise typer.Exit(code=1) from None
128
119
  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} 完成")
@@ -53,8 +53,8 @@ def create_app():
53
53
  from dataops_cli.cli.datasource import datasource_typer
54
54
  from dataops_cli.cli.dict_ import dict_typer
55
55
  from dataops_cli.cli.hazard import hazard_typer
56
- from dataops_cli.cli.kb import kb_typer
57
56
  from dataops_cli.cli.metrics import metrics_typer
57
+ from dataops_cli.cli.ontology import ontology_typer
58
58
  from dataops_cli.cli.ref import ref_typer
59
59
  from dataops_cli.cli.report import report_typer
60
60
  from dataops_cli.cli.skill import skill_typer
@@ -79,11 +79,12 @@ def create_app():
79
79
  app.add_typer(report_typer)
80
80
  app.add_typer(skill_typer)
81
81
  app.add_typer(metrics_typer)
82
+ app.add_typer(ontology_typer)
82
83
  app.add_typer(data_table_typer)
83
84
  app.add_typer(widget_typer)
84
85
  app.add_typer(dict_typer)
85
86
  app.add_typer(hazard_typer)
86
- app.add_typer(kb_typer)
87
+ # app.add_typer(kb_typer) # TODO: kb CLI 尚未实现
87
88
  app.add_typer(tag_typer)
88
89
 
89
90
  app.registered_callback = TyperInfo(callback=main)
@@ -0,0 +1,291 @@
1
+ """本体(Ontology)管理命令组.
2
+
3
+ 提供本体的目录树、列表、配置详情与分段更新。
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import json
9
+ from pathlib import Path
10
+ from typing import Annotated, Any
11
+
12
+ import typer
13
+ from dataops_sdk.exceptions import DataOpsError
14
+ from dataops_sdk.services.ontology import (
15
+ service_get_ontology_by_code,
16
+ service_get_ontology_by_name,
17
+ service_list_ontologies,
18
+ service_tree_ontology,
19
+ service_update_ontology_basic,
20
+ service_update_ontology_constraints,
21
+ service_update_ontology_notes,
22
+ service_update_ontology_relations,
23
+ )
24
+
25
+ from dataops_cli.cli.utils import print_group_tree, print_list
26
+
27
+ ontology_typer = typer.Typer(name="ontology", help="本体管理", no_args_is_help=True)
28
+ update_typer = typer.Typer(name="update", help="更新本体配置", no_args_is_help=True)
29
+ ontology_typer.add_typer(update_typer)
30
+
31
+
32
+ def _read_json_payload(
33
+ file: Path | None,
34
+ content: str | None,
35
+ ) -> Any:
36
+ """从 ``--file`` 或 ``--content`` 读取 JSON(二选一)."""
37
+ if not file and content is None:
38
+ typer.echo("参数 --file 或 --content 必须指定一个", err=True)
39
+ raise typer.Exit(code=1)
40
+ if file and content is not None:
41
+ typer.echo("参数 --file 与 --content 不能同时指定", err=True)
42
+ raise typer.Exit(code=1)
43
+ if file:
44
+ try:
45
+ text = file.read_text(encoding="utf-8")
46
+ except OSError as e:
47
+ typer.echo(f"错误: 无法读取文件 {file}: {e}", err=True)
48
+ raise typer.Exit(code=1) from None
49
+ else:
50
+ text = content or ""
51
+ try:
52
+ return json.loads(text)
53
+ except json.JSONDecodeError as e:
54
+ typer.echo(f"错误: JSON 解析失败: {e}", err=True)
55
+ raise typer.Exit(code=1) from None
56
+
57
+
58
+ def _read_text_payload(
59
+ file: Path | None,
60
+ content: str | None,
61
+ ) -> str:
62
+ """从 ``--file`` 或 ``--content`` 读取文本(二选一)."""
63
+ if not file and content is None:
64
+ typer.echo("参数 --file 或 --content 必须指定一个", err=True)
65
+ raise typer.Exit(code=1)
66
+ if file and content is not None:
67
+ typer.echo("参数 --file 与 --content 不能同时指定", err=True)
68
+ raise typer.Exit(code=1)
69
+ if file:
70
+ try:
71
+ return file.read_text(encoding="utf-8")
72
+ except OSError as e:
73
+ typer.echo(f"错误: 无法读取文件 {file}: {e}", err=True)
74
+ raise typer.Exit(code=1) from None
75
+ return content or ""
76
+
77
+
78
+ @ontology_typer.command("list")
79
+ def list_ontologies(
80
+ query: Annotated[str | None, typer.Option("-q", "--query", help="正则关键词")] = None,
81
+ ) -> None:
82
+ """列出所有本体。
83
+
84
+ Examples:
85
+ >>> data-ops-cli ontology list
86
+ >>> data-ops-cli ontology list -q "^dev_.*"
87
+ """
88
+ try:
89
+ items = service_list_ontologies(query=query)
90
+ except DataOpsError as e:
91
+ typer.echo(f"错误: {e.message}")
92
+ raise typer.Exit(code=1) from None
93
+
94
+ if not items:
95
+ print("未查询到匹配的本体")
96
+ return
97
+
98
+ print_list(
99
+ ["code", "name", "title", "remark"],
100
+ [[item.code, item.name, item.title, item.remark or ""] for item in items],
101
+ )
102
+
103
+
104
+ @ontology_typer.command("detail", no_args_is_help=True)
105
+ def detail_ontology(
106
+ name: Annotated[str, typer.Argument(help="本体编码或业务名")],
107
+ raw: Annotated[bool, typer.Option("--raw", help="仅输出 rawData JSON")] = False,
108
+ ) -> None:
109
+ """查看本体配置详情。
110
+
111
+ 默认输出摘要;加 ``--raw`` 时输出完整 ``meta.data`` JSON。
112
+
113
+ Examples:
114
+ >>> data-ops-cli ontology detail dev_ne
115
+ >>> data-ops-cli ontology detail dev_ne --raw
116
+ """
117
+ try:
118
+ meta = service_get_ontology_by_name(name)
119
+ except DataOpsError:
120
+ try:
121
+ meta = service_get_ontology_by_code(name)
122
+ except DataOpsError as e:
123
+ typer.echo(f"错误: {e.message}")
124
+ raise typer.Exit(code=1) from None
125
+
126
+ if meta.data is None:
127
+ typer.echo(f"错误: 本体({name})不存在")
128
+ raise typer.Exit(code=1) from None
129
+
130
+ if raw:
131
+ print(meta.data.model_dump_json(mode="json"))
132
+ return
133
+
134
+ data = meta.data
135
+ print(f"本体: {meta.name} ({meta.title})")
136
+ print(f"备注: {meta.remark or '-'}")
137
+ print(f"多维表格: {data.data_table or '-'}")
138
+ print(f"场景数: {len(data.scenarios)}")
139
+ print(f"约束数: {len(data.constraints)}")
140
+ print(f"关系数: {len(data.relations)}")
141
+ if data.notes:
142
+ print(f"\n说明:\n{data.notes}")
143
+
144
+
145
+ @ontology_typer.command("tree")
146
+ def tree_ontology(
147
+ query: Annotated[str | None, typer.Option("-q", "--query", help="节点关键字")] = None,
148
+ types: Annotated[
149
+ list[str] | None,
150
+ typer.Option("--type", "-t", help="节点类型过滤 (group/ontology)"),
151
+ ] = None,
152
+ ) -> None:
153
+ """展示本体目录树。
154
+
155
+ Examples:
156
+ >>> data-ops-cli ontology tree
157
+ >>> data-ops-cli ontology tree -q dev
158
+ """
159
+ try:
160
+ tree = service_tree_ontology()
161
+ except DataOpsError as e:
162
+ typer.echo(f"错误: {e.message}")
163
+ raise typer.Exit(code=1) from None
164
+ print_group_tree(tree, query, types=types)
165
+
166
+
167
+ @update_typer.command("basic", no_args_is_help=True)
168
+ def update_basic(
169
+ name: Annotated[str, typer.Argument(help="本体编码或业务名")],
170
+ new_name: Annotated[
171
+ str | None,
172
+ typer.Option("--name", help="新业务名(英文字母开头,仅字母数字下划线)"),
173
+ ] = None,
174
+ title: Annotated[str | None, typer.Option("--title", help="中文标题")] = None,
175
+ remark: Annotated[str | None, typer.Option("--remark", help="备注/描述")] = None,
176
+ data_table: Annotated[
177
+ str | None,
178
+ typer.Option("--data-table", help="绑定的多维表格编码"),
179
+ ] = None,
180
+ ) -> None:
181
+ """更新本体基础配置(title / remark / name / data_table)。
182
+
183
+ 仅覆盖显式传入的字段;至少一个选项必填。
184
+
185
+ Examples:
186
+ >>> data-ops-cli ontology update basic dev_ne --title "网元" --data-table dt_ne
187
+ >>> data-ops-cli ontology update basic dev_ne --name dev_ne_v2 --remark "传输网元"
188
+ """
189
+ if new_name is None and title is None and remark is None and data_table is None:
190
+ typer.echo("请至少指定一个要更新的字段(--name/--title/--remark/--data-table)", err=True)
191
+ raise typer.Exit(code=1)
192
+ try:
193
+ result = service_update_ontology_basic(
194
+ name,
195
+ title=title,
196
+ remark=remark,
197
+ name=new_name,
198
+ data_table=data_table,
199
+ )
200
+ except DataOpsError as e:
201
+ typer.echo(f"错误: {e.message}", err=True)
202
+ raise typer.Exit(code=1) from None
203
+ typer.echo(f"本体 {result.name} 基础配置更新成功")
204
+
205
+
206
+ @update_typer.command("constraints", no_args_is_help=True)
207
+ def update_constraints(
208
+ name: Annotated[str, typer.Argument(help="本体编码或业务名")],
209
+ file: Annotated[
210
+ Path | None,
211
+ typer.Option("--file", "-f", help="约束 JSON 文件路径(数组)"),
212
+ ] = None,
213
+ content: Annotated[
214
+ str | None,
215
+ typer.Option("--content", "-c", help="约束 JSON 内容(数组)"),
216
+ ] = None,
217
+ ) -> None:
218
+ """全量替换本体约束列表。
219
+
220
+ Examples:
221
+ >>> data-ops-cli ontology update constraints dev_ne --file constraints.json
222
+ >>> data-ops-cli ontology update constraints dev_ne --content '[{"type":"唯一","rule":"code唯一"}]'
223
+ """
224
+ payload = _read_json_payload(file, content)
225
+ if not isinstance(payload, list):
226
+ typer.echo("错误: 约束内容必须是 JSON 数组", err=True)
227
+ raise typer.Exit(code=1)
228
+ try:
229
+ result = service_update_ontology_constraints(name, payload)
230
+ except DataOpsError as e:
231
+ typer.echo(f"错误: {e.message}", err=True)
232
+ raise typer.Exit(code=1) from None
233
+ assert result.data is not None
234
+ typer.echo(f"本体 {result.name} 约束已更新(共 {len(result.data.constraints)} 条)")
235
+
236
+
237
+ @update_typer.command("notes", no_args_is_help=True)
238
+ def update_notes(
239
+ name: Annotated[str, typer.Argument(help="本体编码或业务名")],
240
+ file: Annotated[
241
+ Path | None,
242
+ typer.Option("--file", "-f", help="说明文本文件路径"),
243
+ ] = None,
244
+ content: Annotated[
245
+ str | None,
246
+ typer.Option("--content", "-c", help="说明文本内容"),
247
+ ] = None,
248
+ ) -> None:
249
+ """全量替换本体其他说明。
250
+
251
+ Examples:
252
+ >>> data-ops-cli ontology update notes dev_ne --content "说明文本"
253
+ >>> data-ops-cli ontology update notes dev_ne --file notes.md
254
+ """
255
+ text = _read_text_payload(file, content)
256
+ try:
257
+ result = service_update_ontology_notes(name, text)
258
+ except DataOpsError as e:
259
+ typer.echo(f"错误: {e.message}", err=True)
260
+ raise typer.Exit(code=1) from None
261
+ typer.echo(f"本体 {result.name} 其他说明已更新")
262
+
263
+
264
+ @update_typer.command("relations", no_args_is_help=True)
265
+ def update_relations(
266
+ name: Annotated[str, typer.Argument(help="本体编码或业务名")],
267
+ file: Annotated[
268
+ Path | None,
269
+ typer.Option("--file", "-f", help="关系 JSON 文件路径(数组)"),
270
+ ] = None,
271
+ content: Annotated[
272
+ str | None,
273
+ typer.Option("--content", "-c", help="关系 JSON 内容(数组)"),
274
+ ] = None,
275
+ ) -> None:
276
+ """全量替换本体关联关系列表。
277
+
278
+ Examples:
279
+ >>> data-ops-cli ontology update relations dev_ne --file relations.json
280
+ """
281
+ payload = _read_json_payload(file, content)
282
+ if not isinstance(payload, list):
283
+ typer.echo("错误: 关系内容必须是 JSON 数组", err=True)
284
+ raise typer.Exit(code=1)
285
+ try:
286
+ result = service_update_ontology_relations(name, payload)
287
+ except DataOpsError as e:
288
+ typer.echo(f"错误: {e.message}", err=True)
289
+ raise typer.Exit(code=1) from None
290
+ assert result.data is not None
291
+ typer.echo(f"本体 {result.name} 关联关系已更新(共 {len(result.data.relations)} 条)")
dataops_cli/cli/ref.py CHANGED
@@ -29,6 +29,7 @@ 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,
32
33
  ) -> None:
33
34
  """正向引用查询,查询指定资源引用了哪些其他资源。
34
35
 
@@ -57,7 +58,11 @@ def ref_forward(
57
58
  typer.echo(f"错误: {e.message}")
58
59
  raise typer.Exit(code=1) from None
59
60
 
60
- headers = ("ref-code", "ref-type", "ref-name", "ref-title")
61
+ headers = (
62
+ ("ref-code", "ref-type", "ref-name", "ref-title")
63
+ if full
64
+ else ("ref-code", "ref-type", "ref-name")
65
+ )
61
66
  print("引用关系查询")
62
67
  print_list(
63
68
  headers,
@@ -68,6 +73,12 @@ def ref_forward(
68
73
  result.refName if result.refName != result.refCode else "",
69
74
  result.refTitle,
70
75
  ]
76
+ if full
77
+ else [
78
+ result.refCode,
79
+ result.refType,
80
+ result.refName if result.refName != result.refCode else "",
81
+ ]
71
82
  for result in results
72
83
  ],
73
84
  )
@@ -78,8 +89,9 @@ def ref_backward(
78
89
  type: Annotated[MetaType, typer.Argument(help="被引用类型")],
79
90
  code: Annotated[str, typer.Argument(help="被引用编码")],
80
91
  ref_types: Annotated[
81
- list[MetaType], typer.Option(help="允许的引用类型,使用 , 分割(e.g. table,dict,dataset)")
82
- ],
92
+ MetaType, typer.Option(help="允许的引用类型,使用 , 分割(e.g. table,dict,dataset)")
93
+ ] = "",
94
+ full: Annotated[bool, typer.Option(help="是否显示更多内容")] = False,
83
95
  ) -> None:
84
96
  """反向引用查询,查询哪些资源引用了指定资源。
85
97
 
@@ -89,6 +101,7 @@ def ref_backward(
89
101
  type: 被引用资源的类型,如 table、dict、dataset 等。
90
102
  code: 被引用资源的编码,唯一标识。
91
103
  ref_types: 可选,限定引用者的资源类型,多个用逗号分隔。
104
+ full: 可选,显示完整信息包括 title 字段。
92
105
 
93
106
  Examples:
94
107
  # 查询哪些资源引用了指定表
@@ -100,7 +113,7 @@ def ref_backward(
100
113
  # 显示完整信息
101
114
  >>> data-ops-cli ref backward table t_user --full
102
115
  """
103
- filter_types = ref_types or None
116
+ filter_types = ref_types.split(",") if ref_types else None
104
117
  try:
105
118
  results = service_ref_backward(type, code, filter_types)
106
119
  except DataOpsError as e:
@@ -108,7 +121,7 @@ def ref_backward(
108
121
  raise typer.Exit(code=1) from None
109
122
 
110
123
  print("被引用关系查询")
111
- headers = ("code", "type", "name", "title")
124
+ headers = ("code", "type", "name", "title") if full else ("code", "type", "name")
112
125
  print_list(
113
126
  headers,
114
127
  [
@@ -118,6 +131,8 @@ def ref_backward(
118
131
  result.name if result.name != result.code else "",
119
132
  result.title,
120
133
  ]
134
+ if full
135
+ else [result.code, result.type, result.name if result.name != result.code else ""]
121
136
  for result in results
122
137
  ],
123
138
  )
dataops_cli/cli/report.py CHANGED
@@ -96,9 +96,8 @@ def read_report(code: Annotated[str, typer.Argument(help="报告编码")]) -> No
96
96
  print(f"文档({meta.name})\n\n{content}")
97
97
 
98
98
 
99
- @space_typer.command("tree", no_args_is_help=True)
99
+ @report_typer.command("tree")
100
100
  def tree_report(
101
- space_code: Annotated[str, typer.Argument(help="文档中心空间编码")],
102
101
  query: Annotated[str | None, typer.Option("-q", "--query", help="表名关键字")] = None,
103
102
  types: Annotated[
104
103
  list[str] | None,
@@ -108,12 +107,11 @@ def tree_report(
108
107
  """展示文档中心树结构。
109
108
 
110
109
  Args:
111
- space_code: 文档中心空间编码。
112
110
  query: 表名关键字。
113
111
  types: 文档、多维表格、技能、工作流子类型列表。
114
112
  """
115
113
  try:
116
- tree = servive_tree_report(space_code)
114
+ tree = servive_tree_report()
117
115
  except DataOpsError as e:
118
116
  typer.echo(f"错误: {e.message}")
119
117
  raise typer.Exit(code=1) from None
dataops_cli/cli/skill.py CHANGED
@@ -14,6 +14,7 @@ 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
17
18
  from dataops_sdk.services import (
18
19
  SkillPackValidationError,
19
20
  service_delete_skill,
@@ -124,28 +125,46 @@ def detail_cmd(
124
125
 
125
126
  @skill_typer.command("upload", no_args_is_help=True)
126
127
  def upload_cmd(
128
+ space_code: Annotated[str, typer.Argument(help="空间编码 (通过 ``report space list`` 查看)")],
127
129
  file: Annotated[Path, typer.Argument(help="技能 ZIP 文件路径")],
128
130
  dtype: Annotated[
129
131
  MetaSkillSubType,
130
132
  typer.Option("--type", help="技能子类型"),
131
133
  ],
134
+ ref_node_id: Annotated[
135
+ str | None,
136
+ typer.Option(
137
+ "--ref-node-id",
138
+ help="文档中心分组节点 ID(可选;通过 ``report tree`` 查看,需挂到树上时填写)",
139
+ ),
140
+ ] = None,
141
+ ref_type: Annotated[
142
+ GroupNodeRefType,
143
+ typer.Option("--ref-type", help="引用节点类型 (放置在引用节点前、后还是内)"),
144
+ ] = GroupNodeRefType.AFTER,
132
145
  title: Annotated[str | None, typer.Option("--title", help="技能简体中文名称")] = None,
133
146
  ) -> None:
134
- """从 ZIP 包上传技能。
147
+ """从 ZIP 包导入技能到指定文档空间(可选挂到文档中心树节点)。
135
148
 
136
149
  Examples:
137
- >>> data-ops-cli skill upload my-skill.zip --type api
138
- >>> data-ops-cli skill upload my-skill.zip --type llm --title "天气查询"
150
+ 仅导入到空间(不挂文档树节点)
151
+ >>> data-ops-cli skill upload default my-skill.zip --type llm
152
+
153
+ 挂到文档中心某分组节点内
154
+ >>> data-ops-cli skill upload default my-skill.zip --type api --ref-node-id {node-id} --ref-type inner
139
155
  """
140
156
  if not file.exists():
141
157
  typer.echo(f"错误: 文件不存在 {file}")
142
158
  raise typer.Exit(code=2)
143
159
 
144
160
  try:
145
- service_skill_upload(
161
+ result = service_skill_upload(
146
162
  file_path=str(file),
147
163
  sub_type=dtype,
148
164
  title=title,
165
+ group_name=space_code,
166
+ ref_node_id=ref_node_id,
167
+ ref_type=ref_type,
149
168
  )
150
169
  except DataOpsError as e:
151
170
  typer.echo(f"错误: {e.message}")
@@ -204,9 +223,7 @@ def download_cmd(
204
223
  output_path: str | None = None
205
224
  if output is not None:
206
225
  # Typer Path 会吞掉末尾分隔符;无 .zip 后缀时视为目录
207
- output_path = (
208
- str(output) if output.suffix.lower() == ".zip" else f"{output}/"
209
- )
226
+ output_path = str(output) if output.suffix.lower() == ".zip" else f"{output}/"
210
227
 
211
228
  try:
212
229
  zip_path = service_skill_download(name=name, output_path=output_path)
@@ -160,7 +160,7 @@ def get_workflow_template(
160
160
  @workflow_typer.command("run", no_args_is_help=True)
161
161
  def run_workflow(
162
162
  code: Annotated[str, typer.Argument(help="工作流编码")],
163
- start_node_id: Annotated[str, typer.Argument(help="启动节点ID")],
163
+ start_node_id: Annotated[str, typer.Argument(help="启动节点 ID")],
164
164
  params: Annotated[
165
165
  str | None,
166
166
  typer.Option(help='启动参数 JSON 字符串,例如 \'{"key":"value"}\''),
@@ -173,7 +173,7 @@ def run_workflow(
173
173
 
174
174
  Args:
175
175
  code: 工作流编码。
176
- start_node_id: 启动节点ID。
176
+ start_node_id: 启动节点 ID(手动触发一般为 manually-trigger)。
177
177
  params: 可选启动参数 JSON 字符串。
178
178
 
179
179
  Examples:
@@ -201,7 +201,7 @@ def run_workflow(
201
201
  @workflow_typer.command("run-async", no_args_is_help=True)
202
202
  def run_workflow_async(
203
203
  code: Annotated[str, typer.Argument(help="工作流编码")],
204
- start_node_id: Annotated[str, typer.Argument(help="启动节点ID")],
204
+ start_node_id: Annotated[str, typer.Argument(help="启动节点 ID")],
205
205
  params: Annotated[
206
206
  str | None,
207
207
  typer.Option(help='启动参数 JSON 字符串,例如 \'{"key":"value"}\''),
@@ -214,7 +214,7 @@ def run_workflow_async(
214
214
 
215
215
  Args:
216
216
  code: 工作流编码。
217
- start_node_id: 启动节点ID。
217
+ start_node_id: 启动节点 ID(手动触发一般为 manually-trigger)。
218
218
  params: 可选启动参数 JSON 字符串。
219
219
 
220
220
  Examples:
dataops_cli/cli/kb.py DELETED
@@ -1,234 +0,0 @@
1
- """Knowledge Base(知识库)管理命令组.
2
-
3
- - 服务层函数 (service_*):纯 Python 接口,返回原始数据
4
- - CLI 命令:基于服务层的薄包装,负责格式化输出
5
- """
6
-
7
- from __future__ import annotations
8
-
9
- from pathlib import Path
10
- from typing import Annotated
11
-
12
- import typer
13
- from dataops_cli.cli.utils import print_list
14
- from dataops_sdk.exceptions import DataOpsError
15
- from dataops_sdk.schemas.wiki import KbType
16
- from dataops_sdk.services.wiki import (
17
- service_get_knowledge_base,
18
- service_list_knowledge_bases,
19
- service_list_knowledge_documents,
20
- service_search_knowledge,
21
- service_search_wiki_pages,
22
- service_upload_knowledge_file,
23
- )
24
-
25
- kb_typer = typer.Typer(
26
- name="kb",
27
- help="知识库管理",
28
- no_args_is_help=True,
29
- )
30
- doc_typer = typer.Typer(name="doc", help="知识库文档", no_args_is_help=True)
31
- page_typer = typer.Typer(name="page", help="Wiki 页面", no_args_is_help=True)
32
- kb_typer.add_typer(doc_typer)
33
- kb_typer.add_typer(page_typer)
34
-
35
-
36
- @kb_typer.command("list")
37
- def kb_list_cmd(
38
- kb_type: Annotated[
39
- KbType | None,
40
- typer.Option("--type", "-t", help="知识库类型:document / faq / wiki"),
41
- ] = None,
42
- page: Annotated[int, typer.Option("--page", help="页码", min=1)] = 1,
43
- page_size: Annotated[int, typer.Option("--page-size", help="每页条数", min=1)] = 20,
44
- ) -> None:
45
- """列出知识库。
46
-
47
- Examples:
48
- >>> data-ops-cli kb list
49
- >>> data-ops-cli kb list --type wiki
50
- """
51
- try:
52
- result = service_list_knowledge_bases(page=page, page_size=page_size, kb_type=kb_type)
53
- except DataOpsError as e:
54
- typer.echo(f"错误: {e.message}")
55
- raise typer.Exit(code=1) from None
56
-
57
- if not result.items:
58
- print("未查询到知识库")
59
- return
60
-
61
- print_list(
62
- ("id", "name", "type", "knowledge_count"),
63
- [
64
- [it.id, it.name, it.type or "", it.knowledge_count if it.knowledge_count is not None else ""]
65
- for it in result.items
66
- ],
67
- )
68
- print(f"total={result.total} page={result.page} page_size={result.page_size}")
69
-
70
-
71
- @kb_typer.command("detail", no_args_is_help=True)
72
- def kb_detail_cmd(
73
- kb_id: Annotated[str, typer.Argument(help="知识库 ID")],
74
- ) -> None:
75
- """查看知识库详情。
76
-
77
- Examples:
78
- >>> data-ops-cli kb detail <kb_id>
79
- """
80
- try:
81
- kb = service_get_knowledge_base(kb_id)
82
- except DataOpsError as e:
83
- typer.echo(f"错误: {e.message}")
84
- raise typer.Exit(code=1) from None
85
-
86
- print_list(
87
- ("field", "value"),
88
- [
89
- ["id", kb.id],
90
- ["name", kb.name],
91
- ["type", kb.type or ""],
92
- ["description", kb.description or ""],
93
- ["knowledge_count", kb.knowledge_count if kb.knowledge_count is not None else ""],
94
- ["chunk_count", kb.chunk_count if kb.chunk_count is not None else ""],
95
- ],
96
- )
97
-
98
-
99
- @doc_typer.command("list", no_args_is_help=True)
100
- def doc_list_cmd(
101
- kb_id: Annotated[str, typer.Argument(help="知识库 ID")],
102
- keyword: Annotated[
103
- str | None,
104
- typer.Option("--keyword", "-k", help="关键词"),
105
- ] = None,
106
- page: Annotated[int, typer.Option("--page", help="页码", min=1)] = 1,
107
- page_size: Annotated[int, typer.Option("--page-size", help="每页条数", min=1)] = 20,
108
- ) -> None:
109
- """列出知识库文档。
110
-
111
- Examples:
112
- >>> data-ops-cli kb doc list <kb_id>
113
- >>> data-ops-cli kb doc list <kb_id> --keyword "故障处理"
114
- """
115
- try:
116
- result = service_list_knowledge_documents(
117
- kb_id, page=page, page_size=page_size, keyword=keyword
118
- )
119
- except DataOpsError as e:
120
- typer.echo(f"错误: {e.message}")
121
- raise typer.Exit(code=1) from None
122
-
123
- if not result.items:
124
- print("未查询到文档")
125
- return
126
-
127
- print_list(
128
- ("id", "title", "file_name", "parse_status"),
129
- [
130
- [
131
- it.id,
132
- it.title or "",
133
- it.file_name or "",
134
- it.parse_status or "",
135
- ]
136
- for it in result.items
137
- ],
138
- )
139
- print(f"total={result.total} page={result.page} page_size={result.page_size}")
140
-
141
-
142
- @doc_typer.command("upload", no_args_is_help=True)
143
- def doc_upload_cmd(
144
- kb_id: Annotated[str, typer.Argument(help="知识库 ID")],
145
- file: Annotated[Path, typer.Argument(help="本地文件路径", exists=True, readable=True)],
146
- name: Annotated[
147
- str | None,
148
- typer.Option("--name", help="覆盖上传文件名"),
149
- ] = None,
150
- ) -> None:
151
- """上传文件到知识库。
152
-
153
- Examples:
154
- >>> data-ops-cli kb doc upload <kb_id> ./manual.pdf
155
- """
156
- try:
157
- doc = service_upload_knowledge_file(kb_id, file, file_name=name)
158
- except (DataOpsError, FileNotFoundError) as e:
159
- msg = getattr(e, "message", None) or str(e)
160
- typer.echo(f"错误: {msg}")
161
- raise typer.Exit(code=1) from None
162
-
163
- print(f"上传成功: id={doc.id} title={doc.title or ''} file_name={doc.file_name or ''}")
164
-
165
-
166
- @kb_typer.command("search", no_args_is_help=True)
167
- def search_cmd(
168
- keyword: Annotated[str, typer.Argument(help="检索关键词")],
169
- limit: Annotated[int, typer.Option("--limit", help="返回条数", min=1)] = 20,
170
- offset: Annotated[int, typer.Option("--offset", help="偏移量", min=0)] = 0,
171
- ) -> None:
172
- """全局关键词检索知识内容。
173
-
174
- Examples:
175
- >>> data-ops-cli kb search "网络割接"
176
- """
177
- try:
178
- result = service_search_knowledge(keyword, limit=limit, offset=offset)
179
- except DataOpsError as e:
180
- typer.echo(f"错误: {e.message}")
181
- raise typer.Exit(code=1) from None
182
-
183
- if not result.items:
184
- print("未检索到内容")
185
- return
186
-
187
- print_list(
188
- ("title", "kb_name", "score", "content"),
189
- [
190
- [
191
- it.title or it.knowledge_title or "",
192
- it.kb_name or "",
193
- f"{it.score:.4f}" if it.score is not None else "",
194
- (it.content or "")[:80],
195
- ]
196
- for it in result.items
197
- ],
198
- )
199
- print(f"total={result.total}")
200
-
201
-
202
- @page_typer.command("search", no_args_is_help=True)
203
- def page_search_cmd(
204
- kb_id: Annotated[str, typer.Argument(help="知识库 ID")],
205
- query: Annotated[str, typer.Argument(help="检索词")],
206
- limit: Annotated[int, typer.Option("--limit", help="返回条数", min=1)] = 20,
207
- ) -> None:
208
- """检索知识库 Wiki 页面。
209
-
210
- Examples:
211
- >>> data-ops-cli kb page search <kb_id> "运维手册"
212
- """
213
- try:
214
- pages = service_search_wiki_pages(kb_id, query, limit=limit)
215
- except DataOpsError as e:
216
- typer.echo(f"错误: {e.message}")
217
- raise typer.Exit(code=1) from None
218
-
219
- if not pages:
220
- print("未检索到 Wiki 页面")
221
- return
222
-
223
- print_list(
224
- ("slug", "title", "page_type", "summary"),
225
- [
226
- [
227
- it.slug,
228
- it.title or "",
229
- it.page_type or "",
230
- (it.summary or "")[:60],
231
- ]
232
- for it in pages
233
- ],
234
- )