Files
wurangyu 1e39b6da88 feat: sap-cli skill v2.1.0 — self-contained distributable package
- assets/: sap-cli source (v2.1.0, 26 commands, 16 object types)
- references/: tool constraints + error handling (self-contained)
- scripts/setup.py: one-click install/config/verify
- SKILL.md: full command reference + dual-platform install guide
- VERSION: 2.1.0

Built from D:/Codespace/sap-cli via scripts/pack_skill.py
2026-06-13 20:52:24 +08:00

108 lines
3.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""包管理命令:package (create / info / list)。"""
from __future__ import annotations
import argparse
import logging
from sapcli.client import ADTClient
logger = logging.getLogger("sapcli.commands.package_cmd")
def cmd_package(args: argparse.Namespace, client: ADTClient) -> None:
"""ABAP 包操作。"""
action = getattr(args, "package_action", None)
if action == "create":
_package_create(args, client)
elif action == "info":
_package_info(args, client)
elif action == "list":
_package_list(args, client)
else:
print(" 用法: sap-cli package [create|info|list]")
print(" create — 创建 ABAP 包")
print(" info — 查看包详情")
print(" list — 列出对象(通过 list 命令按包过滤)")
def _package_create(args: argparse.Namespace, client: ADTClient) -> None:
"""创建 ABAP 包。"""
name: str = args.name
description: str = getattr(args, "description", None) or name
superpackage: str | None = getattr(args, "superpackage", None)
print("=" * 60)
print(" SAP 创建 ABAP 包")
print("=" * 60)
print(f" 包名: {name}")
print(f" 描述: {description}")
if superpackage:
print(f" 上级包: {superpackage}")
print(f"\n → 正在创建包...")
try:
success = client.create_package(name, description, superpackage)
except Exception as e:
print(f" ✗ 创建失败: {e}")
return
if success:
print(f" ✓ 包 {name} 创建成功!")
else:
print(f" ✗ 包创建失败")
def _package_info(args: argparse.Namespace, client: ADTClient) -> None:
"""查看包详情。"""
name: str = args.name
print("=" * 60)
print(" SAP 包信息")
print("=" * 60)
print(f" 包名: {name}")
print(f"\n → 正在查询...")
try:
info = client.get_package_info(name)
except Exception as e:
print(f" ✗ 查询失败: {e}")
return
print(f"\n {'─' * 50}")
print(f" 名称: {info.get('name', '')}")
print(f" 描述: {info.get('description', '')}")
print(f" 所有者: {info.get('owner', '')}")
print(f" 上级包: {info.get('superpackage', '(无)')}")
print(f" {'─' * 50}")
def _package_list(args: argparse.Namespace, client: ADTClient) -> None:
"""列出包中的对象。"""
name: str = args.name
print("=" * 60)
print(" SAP 包对象列表")
print("=" * 60)
print(f" 包名: {name}")
print(f"\n → 正在查询...")
try:
results = client.list_objects(package=name)
except Exception as e:
print(f" ✗ 查询失败: {e}")
return
if not results:
print(" 包中没有找到对象")
return
print(f" ✓ 找到 {len(results)} 个对象\n")
print(f" {'名称':<30s} {'类型':<12s} {'描述':<30s}")
print(f" {'─' * 30} {'─' * 12} {'─' * 30}")
for obj in results:
obj_name = obj.get("name", "")[:30]
obj_type = obj.get("type", "")[:12]
desc = obj.get("description", "")[:30]
print(f" {obj_name:<30s} {obj_type:<12s} {desc:<30s}")