@josephyan/qingflow-cli 0.2.0-beta.69 → 0.2.0-beta.70

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.
@@ -35,12 +35,33 @@ def _format_generic(result: dict[str, Any]) -> str:
35
35
 
36
36
  def _format_whoami(result: dict[str, Any]) -> str:
37
37
  lines = [
38
- f"Profile: {result.get('profile')}",
39
38
  f"User: {result.get('nick_name') or '-'} ({result.get('email') or '-'})",
40
39
  f"UID: {result.get('uid')}",
41
40
  f"Workspace: {result.get('selected_ws_name') or '-'} ({result.get('selected_ws_id') or '-'})",
42
- f"Base URL: {result.get('base_url')}",
41
+ f"QF Version: {result.get('qf_version') or '-'}",
43
42
  ]
43
+ lines.append(f"Permission Level: {result.get('permission_level') or '-'}")
44
+ departments = result.get("departments") if isinstance(result.get("departments"), list) else []
45
+ roles = result.get("roles") if isinstance(result.get("roles"), list) else []
46
+ if departments:
47
+ lines.append(
48
+ "Departments: "
49
+ + ", ".join(
50
+ str(item.get("dept_name") or item.get("dept_id"))
51
+ for item in departments
52
+ if isinstance(item, dict)
53
+ )
54
+ )
55
+ if roles:
56
+ lines.append(
57
+ "Roles: "
58
+ + ", ".join(
59
+ str(item.get("role_name") or item.get("role_id"))
60
+ for item in roles
61
+ if isinstance(item, dict)
62
+ )
63
+ )
64
+ _append_warnings(lines, result.get("warnings"))
44
65
  return "\n".join(lines) + "\n"
45
66
 
46
67
 
@@ -93,6 +114,15 @@ def _format_app_get(result: dict[str, Any]) -> str:
93
114
  f"{import_capability.get('auth_source') or 'unknown'} / "
94
115
  f"can_import={import_capability.get('can_import')}"
95
116
  )
117
+ editability = data.get("editability") if isinstance(data.get("editability"), dict) else {}
118
+ if editability:
119
+ lines.append(
120
+ "Editability: "
121
+ f"form={editability.get('can_edit_form')} / "
122
+ f"flow={editability.get('can_edit_flow')} / "
123
+ f"views={editability.get('can_edit_views')} / "
124
+ f"charts={editability.get('can_edit_charts')}"
125
+ )
96
126
  views = data.get("accessible_views") if isinstance(data.get("accessible_views"), list) else []
97
127
  lines.append(f"Accessible Views: {len(views)}")
98
128
  for item in views[:10]:
@@ -102,6 +132,25 @@ def _format_app_get(result: dict[str, Any]) -> str:
102
132
  return "\n".join(lines) + "\n"
103
133
 
104
134
 
135
+ def _format_workspace_select(result: dict[str, Any]) -> str:
136
+ lines = [
137
+ f"Workspace: {result.get('selected_ws_name') or '-'} ({result.get('selected_ws_id') or '-'})",
138
+ f"QF Version: {result.get('qf_version') or '-'}",
139
+ ]
140
+ workspace_version = result.get("workspace_version") if isinstance(result.get("workspace_version"), dict) else {}
141
+ if workspace_version:
142
+ lines.append(
143
+ "Workspace Version: "
144
+ f"{workspace_version.get('display_name') or '-'} "
145
+ f"({workspace_version.get('level_name') or workspace_version.get('level_code') or '-'})"
146
+ )
147
+ if workspace_version.get("being_trial") is not None:
148
+ lines.append(f"Trial: {workspace_version.get('being_trial')}")
149
+ if workspace_version.get("expire_date") is not None:
150
+ lines.append(f"Expire Date: {workspace_version.get('expire_date')}")
151
+ return "\n".join(lines) + "\n"
152
+
153
+
105
154
  def _format_record_list(result: dict[str, Any]) -> str:
106
155
  data = result.get("data") if isinstance(result.get("data"), dict) else {}
107
156
  items = data.get("items") if isinstance(data.get("items"), list) else []
@@ -293,6 +342,7 @@ def _first_present(payload: dict[str, Any], *keys: str) -> Any:
293
342
  _FORMATTERS = {
294
343
  "auth_whoami": _format_whoami,
295
344
  "workspace_list": _format_workspace_list,
345
+ "workspace_select": _format_workspace_select,
296
346
  "app_list": _format_app_items,
297
347
  "app_search": _format_app_items,
298
348
  "app_get": _format_app_get,
@@ -6,6 +6,7 @@ import sys
6
6
  from typing import Any, Callable, TextIO
7
7
 
8
8
  from ..errors import QingflowApiError
9
+ from ..response_trim import resolve_cli_tool_name, trim_error_response, trim_public_response
9
10
  from .context import CliContext, build_cli_context
10
11
  from .formatters import emit_json_result, emit_text_result
11
12
  from .commands import register_all_commands
@@ -17,7 +18,7 @@ Handler = Callable[[argparse.Namespace, CliContext], dict[str, Any]]
17
18
  def build_parser() -> argparse.ArgumentParser:
18
19
  parser = argparse.ArgumentParser(prog="qingflow", description="Qingflow CLI")
19
20
  parser.add_argument("--profile", default="default", help="会话 profile,默认 default")
20
- parser.add_argument("--json", action="store_true", help="输出原始 JSON")
21
+ parser.add_argument("--json", action="store_true", help="输出 JSON")
21
22
  subparsers = parser.add_subparsers(dest="command", required=True)
22
23
  register_all_commands(subparsers)
23
24
  return parser
@@ -50,20 +51,21 @@ def run(
50
51
  try:
51
52
  result = handler(args, context)
52
53
  except RuntimeError as exc:
53
- payload = _parse_error_payload(exc)
54
+ payload = trim_error_response(_parse_error_payload(exc))
54
55
  return _emit_error(payload, json_mode=bool(args.json), stdout=out, stderr=err)
55
56
  except QingflowApiError as exc:
56
- payload = exc.to_dict()
57
+ payload = trim_error_response(exc.to_dict())
57
58
  return _emit_error(payload, json_mode=bool(args.json), stdout=out, stderr=err)
58
59
  finally:
59
60
  context.close()
60
61
 
61
62
  exit_code = _result_exit_code(result)
63
+ trimmed_result = trim_public_response(resolve_cli_tool_name(args), result) if isinstance(result, dict) else result
62
64
  stream = out if bool(args.json) or exit_code == 0 else err
63
65
  if bool(args.json):
64
- emit_json_result(result, stream=stream)
66
+ emit_json_result(trimmed_result, stream=stream)
65
67
  else:
66
- emit_text_result(result, hint=getattr(args, "format_hint", ""), stream=stream)
68
+ emit_text_result(trimmed_result, hint=getattr(args, "format_hint", ""), stream=stream)
67
69
  return exit_code
68
70
 
69
71