compshare-cli 0.1.1__tar.gz → 0.1.3__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.
Files changed (35) hide show
  1. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/PKG-INFO +1 -1
  2. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/pyproject.toml +1 -1
  3. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli/__init__.py +1 -1
  4. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli/cli.py +20 -2
  5. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli/i18n.py +3 -2
  6. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli.egg-info/PKG-INFO +1 -1
  7. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/tests/test_cli.py +19 -5
  8. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/README.md +0 -0
  9. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/setup.cfg +0 -0
  10. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli/__main__.py +0 -0
  11. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli/actions.py +0 -0
  12. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli/api.py +0 -0
  13. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli/commands/__init__.py +0 -0
  14. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli/commands/common.py +0 -0
  15. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli/commands/image.py +0 -0
  16. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli/commands/instance.py +0 -0
  17. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli/commands/storage.py +0 -0
  18. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli/config.py +0 -0
  19. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli/errors.py +0 -0
  20. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli/location.py +0 -0
  21. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli/output.py +0 -0
  22. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli/parsing.py +0 -0
  23. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli/runtime.py +0 -0
  24. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli/sdk.py +0 -0
  25. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli.egg-info/SOURCES.txt +0 -0
  26. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli.egg-info/dependency_links.txt +0 -0
  27. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli.egg-info/entry_points.txt +0 -0
  28. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli.egg-info/requires.txt +0 -0
  29. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/src/compshare_cli.egg-info/top_level.txt +0 -0
  30. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/tests/test_actions.py +0 -0
  31. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/tests/test_config.py +0 -0
  32. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/tests/test_location.py +0 -0
  33. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/tests/test_output.py +0 -0
  34. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/tests/test_parsing.py +0 -0
  35. {compshare_cli-0.1.1 → compshare_cli-0.1.3}/tests/test_sdk.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: compshare-cli
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: Command-line client for CompShare GPU compute
5
5
  Author: CompShare
6
6
  License: Apache-2.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "compshare-cli"
7
- version = "0.1.1"
7
+ version = "0.1.3"
8
8
  description = "Command-line client for CompShare GPU compute"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -1,3 +1,3 @@
1
1
  """CompShare command-line client."""
2
2
 
3
- __version__ = "0.1.1"
3
+ __version__ = "0.1.3"
@@ -5,6 +5,7 @@ from typing import List, Optional
5
5
 
6
6
  import click
7
7
  import typer
8
+ from typer import core as typer_core
8
9
  from typer.main import get_command
9
10
 
10
11
  from compshare_cli import __version__
@@ -15,9 +16,24 @@ from compshare_cli.i18n import configured_language, localize_command, normalize_
15
16
  from compshare_cli.output import Renderer
16
17
  from compshare_cli.runtime import Runtime
17
18
 
19
+ _TYPER_CLICK = getattr(typer_core, "_click", click)
20
+ _TYPER_CLICK_EXCEPTIONS = getattr(_TYPER_CLICK, "exceptions", _TYPER_CLICK)
21
+ _CLICK_EXCEPTIONS = (click.ClickException, _TYPER_CLICK_EXCEPTIONS.ClickException)
22
+ _ABORT_EXCEPTIONS = (click.Abort, _TYPER_CLICK_EXCEPTIONS.Abort)
23
+
24
+
25
+ class RootGroup(typer_core.TyperGroup):
26
+ def list_commands(self, ctx):
27
+ names = super().list_commands(ctx)
28
+ if "config" not in names:
29
+ return names
30
+ return ["config", *(name for name in names if name != "config")]
31
+
32
+
18
33
  app = typer.Typer(
19
34
  name="compshare",
20
35
  help="Manage CompShare GPU compute from the terminal.",
36
+ cls=RootGroup,
21
37
  no_args_is_help=True,
22
38
  add_completion=False,
23
39
  context_settings={"help_option_names": ["-h", "--help"]},
@@ -198,6 +214,8 @@ def lang(
198
214
 
199
215
  def main(args: Optional[List[str]] = None) -> None:
200
216
  argv = list(sys.argv[1:] if args is None else args)
217
+ if not argv:
218
+ argv = ["-h"]
201
219
  try:
202
220
  language = configured_language()
203
221
  command = localize_command(get_command(app), language)
@@ -205,10 +223,10 @@ def main(args: Optional[List[str]] = None) -> None:
205
223
  except CLIError as error:
206
224
  Renderer("--json" in argv).error(str(error))
207
225
  raise SystemExit(2) from error
208
- except click.ClickException as error:
226
+ except _CLICK_EXCEPTIONS as error:
209
227
  Renderer("--json" in argv).error(error.format_message())
210
228
  raise SystemExit(error.exit_code) from error
211
- except click.Abort as error:
229
+ except _ABORT_EXCEPTIONS as error:
212
230
  Renderer("--json" in argv).error(tr("Aborted"))
213
231
  raise SystemExit(1) from error
214
232
  if isinstance(result, int) and result:
@@ -500,7 +500,8 @@ def localize_command(command: click.Command, language: str) -> click.Command:
500
500
  return option
501
501
 
502
502
  command.get_help_option = localized_help_option # type: ignore[method-assign]
503
- if isinstance(command, click.Group):
504
- for child in command.commands.values():
503
+ children = getattr(command, "commands", None)
504
+ if children is not None:
505
+ for child in children.values():
505
506
  localize_command(child, language)
506
507
  return command
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: compshare-cli
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: Command-line client for CompShare GPU compute
5
5
  Author: CompShare
6
6
  License: Apache-2.0
@@ -1,6 +1,5 @@
1
1
  import json
2
2
 
3
- import click
4
3
  import pytest
5
4
  from typer.main import get_command
6
5
  from typer.testing import CliRunner
@@ -30,12 +29,25 @@ def test_help_tree(args) -> None:
30
29
 
31
30
  def test_global_json_is_accepted_before_command(capsys) -> None:
32
31
  cli.main(["--json", "version"])
33
- assert json.loads(capsys.readouterr().out) == {"version": "0.1.1"}
32
+ assert json.loads(capsys.readouterr().out) == {"version": "0.1.3"}
34
33
 
35
34
 
36
35
  def test_global_profile_is_accepted_before_command(capsys) -> None:
37
36
  cli.main(["--profile", "testing", "--json", "version"])
38
- assert json.loads(capsys.readouterr().out) == {"version": "0.1.1"}
37
+ assert json.loads(capsys.readouterr().out) == {"version": "0.1.3"}
38
+
39
+
40
+ def test_no_args_shows_help_without_error(capsys) -> None:
41
+ cli.main([])
42
+ captured = capsys.readouterr()
43
+ assert "Usage:" in captured.out
44
+ assert "Traceback" not in captured.err
45
+
46
+
47
+ def test_root_help_lists_config_first(capsys) -> None:
48
+ cli.main(["-h"])
49
+ help_text = capsys.readouterr().out
50
+ assert help_text.index("config") < help_text.index("version")
39
51
 
40
52
 
41
53
  def test_global_options_after_command_are_rejected(capsys) -> None:
@@ -107,6 +119,7 @@ def test_lang_command_persists_help_language(monkeypatch, tmp_path, capsys) -> N
107
119
  cli.main(["--help"])
108
120
  chinese = capsys.readouterr().out
109
121
  assert "在终端管理优云智算 GPU 计算资源" in chinese
122
+ assert "管理 GPU 实例" in chinese
110
123
  assert "显示帮助并退出" in chinese
111
124
  assert "--install-completion" not in chinese
112
125
  assert "--lang" not in chinese
@@ -157,8 +170,9 @@ def test_every_command_has_chinese_and_english_description() -> None:
157
170
 
158
171
  def descriptions(command, prefix=()):
159
172
  result = []
160
- if isinstance(command, click.Group):
161
- for name, child in command.commands.items():
173
+ children = getattr(command, "commands", None)
174
+ if children is not None:
175
+ for name, child in children.items():
162
176
  path = (*prefix, name)
163
177
  result.append((path, child.help or child.short_help))
164
178
  result.extend(descriptions(child, path))
File without changes
File without changes