Skip to content
This repository was archived by the owner on Jun 2, 2026. It is now read-only.

Commit 9a3a3cb

Browse files
committed
x
1 parent 58fcada commit 9a3a3cb

2 files changed

Lines changed: 29 additions & 10 deletions

File tree

defectdojo_api_generated/cli/commands/apis.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,23 @@ class ApiGroup(CLI.SubGroup, classyclick.Group):
3939
name=group_name,
4040
help=f'`{api_class.__name__}`.',
4141
)
42-
client: DefectDojo = classyclick.ContextMeta('client')
4342

4443
methods = sorted(name for name, member in inspect.getmembers(api_class, callable) if not name.startswith('_'))
4544
method_set = set(methods)
45+
46+
def _build_api_command(command_name: str, target_method: str):
47+
class ApiCommand(ApiGroup.Command, classyclick.Command):
48+
__config__ = classyclick.Command.Config(
49+
name=command_name,
50+
help=f'`{target_method}`.',
51+
)
52+
client: DefectDojo = classyclick.ContextMeta('client')
53+
54+
def __call__(self):
55+
print(getattr(api_class(self.client.api_client), target_method)())
56+
57+
return ApiCommand
58+
4659
for method in methods:
4760
if method.endswith('_with_http_info') or method.endswith('_without_preload_content'):
4861
continue
@@ -51,15 +64,7 @@ class ApiGroup(CLI.SubGroup, classyclick.Group):
5164
method_name = method
5265
if method.endswith('_iterator') and method[:-9] in method_set:
5366
method_name = method[:-9]
54-
55-
class ApiCommand(ApiGroup.Command, classyclick.Command):
56-
__config__ = classyclick.Command.Config(
57-
name=method_name,
58-
help=f'`{method}`.',
59-
)
60-
61-
def __call__(self):
62-
pass
67+
_build_api_command(method_name, method)
6368

6469
return ApiGroup
6570

tests/unit/test_cli.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,17 @@ def test_findings_list_command_runs(self):
2323
expected_exit_code = 2 if click_version >= (8, 2) else 0
2424
self.assertEqual(result.exit_code, expected_exit_code)
2525
self.assertRegex(result.output, r'findings\s+`FindingsApi`\.')
26+
27+
def test_api_commands_capture_their_own_method(self):
28+
runner = CliRunner()
29+
with runner.isolated_filesystem():
30+
config_path = Path('config.toml')
31+
config_path.write_text("host = 'https://example.com'\ntoken = 'token'\n")
32+
33+
list_result = runner.invoke(CLI.click, ['--config', str(config_path), 'findings', 'list'])
34+
create_result = runner.invoke(CLI.click, ['--config', str(config_path), 'findings', 'create'])
35+
36+
self.assertEqual(list_result.exit_code, 0)
37+
self.assertEqual(create_result.exit_code, 0)
38+
self.assertIn('FindingsApi.list_iterator', list_result.output)
39+
self.assertIn('FindingsApi.create', create_result.output)

0 commit comments

Comments
 (0)