qodalis-cli-server-abstractions 1.0.0b1__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.
- qodalis_cli_server_abstractions-1.0.0b1/.gitignore +43 -0
- qodalis_cli_server_abstractions-1.0.0b1/LICENSE +21 -0
- qodalis_cli_server_abstractions-1.0.0b1/PKG-INFO +114 -0
- qodalis_cli_server_abstractions-1.0.0b1/README.md +92 -0
- qodalis_cli_server_abstractions-1.0.0b1/pyproject.toml +33 -0
- qodalis_cli_server_abstractions-1.0.0b1/src/qodalis_cli_server_abstractions/__init__.py +21 -0
- qodalis_cli_server_abstractions-1.0.0b1/src/qodalis_cli_server_abstractions/cli_command_author.py +18 -0
- qodalis_cli_server_abstractions-1.0.0b1/src/qodalis_cli_server_abstractions/cli_command_parameter_descriptor.py +31 -0
- qodalis_cli_server_abstractions-1.0.0b1/src/qodalis_cli_server_abstractions/cli_command_processor.py +58 -0
- qodalis_cli_server_abstractions-1.0.0b1/src/qodalis_cli_server_abstractions/cli_module.py +45 -0
- qodalis_cli_server_abstractions-1.0.0b1/src/qodalis_cli_server_abstractions/cli_process_command.py +14 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Byte-compiled / optimized
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# Distribution / packaging
|
|
7
|
+
*.egg-info/
|
|
8
|
+
dist/
|
|
9
|
+
build/
|
|
10
|
+
.eggs/
|
|
11
|
+
*.egg
|
|
12
|
+
|
|
13
|
+
# Virtual environments
|
|
14
|
+
.venv/
|
|
15
|
+
venv/
|
|
16
|
+
env/
|
|
17
|
+
|
|
18
|
+
# Environment variables
|
|
19
|
+
.env
|
|
20
|
+
|
|
21
|
+
# Testing
|
|
22
|
+
.pytest_cache/
|
|
23
|
+
.coverage
|
|
24
|
+
htmlcov/
|
|
25
|
+
TestResults/
|
|
26
|
+
|
|
27
|
+
# Type checking / linting
|
|
28
|
+
.mypy_cache/
|
|
29
|
+
.ruff_cache/
|
|
30
|
+
|
|
31
|
+
# C extensions
|
|
32
|
+
*.so
|
|
33
|
+
|
|
34
|
+
# IDEs and editors
|
|
35
|
+
.idea/
|
|
36
|
+
.vscode/*
|
|
37
|
+
!.vscode/settings.json
|
|
38
|
+
!.vscode/launch.json
|
|
39
|
+
!.vscode/extensions.json
|
|
40
|
+
|
|
41
|
+
# System files
|
|
42
|
+
.DS_Store
|
|
43
|
+
Thumbs.db
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Qodalis Solutions
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: qodalis-cli-server-abstractions
|
|
3
|
+
Version: 1.0.0b1
|
|
4
|
+
Summary: Shared interfaces and base classes for Qodalis CLI command processors — zero framework dependencies
|
|
5
|
+
Project-URL: Homepage, https://github.com/qodalis-solutions/cli-server-python
|
|
6
|
+
Project-URL: Repository, https://github.com/qodalis-solutions/cli-server-python
|
|
7
|
+
Project-URL: Issues, https://github.com/qodalis-solutions/cli-server-python/issues
|
|
8
|
+
Author-email: Nicolae Lupei <nicolae.lupei@qodalis.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: abstractions,cli,command-processor,commands,qodalis,terminal
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# qodalis-cli-server-abstractions
|
|
24
|
+
|
|
25
|
+
Shared interfaces and base classes for building [Qodalis CLI](https://qodalis.com/) command processors in Python. **Zero framework dependencies** — install this package when writing plugins, without pulling in FastAPI, uvicorn, or websockets.
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install qodalis-cli-server-abstractions
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
Create a custom command processor by subclassing `CliCommandProcessor`:
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from qodalis_cli_server_abstractions import (
|
|
39
|
+
CliCommandProcessor,
|
|
40
|
+
CliProcessCommand,
|
|
41
|
+
CliCommandParameterDescriptor,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class GreetCommandProcessor(CliCommandProcessor):
|
|
46
|
+
@property
|
|
47
|
+
def command(self) -> str:
|
|
48
|
+
return "greet"
|
|
49
|
+
|
|
50
|
+
@property
|
|
51
|
+
def description(self) -> str:
|
|
52
|
+
return "Greets a user by name"
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def parameters(self):
|
|
56
|
+
return [
|
|
57
|
+
CliCommandParameterDescriptor("--name", "Name to greet", required=True),
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
async def handle_async(self, command: CliProcessCommand) -> str:
|
|
61
|
+
name = command.args.get("name", "World")
|
|
62
|
+
return f"Hello, {name}!"
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Then register the processor with the server package. See [`qodalis-cli-server`](https://pypi.org/project/qodalis-cli-server/) for server setup.
|
|
66
|
+
|
|
67
|
+
## API Reference
|
|
68
|
+
|
|
69
|
+
### Abstract Base Classes
|
|
70
|
+
|
|
71
|
+
| Class | Description |
|
|
72
|
+
|-------|-------------|
|
|
73
|
+
| `ICliCommandProcessor` | Abstract base defining the processor contract: command, description, author, parameters, sub-processors, and `handle_async()` |
|
|
74
|
+
| `CliCommandProcessor` | Convenience subclass of `ICliCommandProcessor` with sensible defaults |
|
|
75
|
+
|
|
76
|
+
### Protocols
|
|
77
|
+
|
|
78
|
+
| Protocol | Description |
|
|
79
|
+
|----------|-------------|
|
|
80
|
+
| `ICliCommandAuthor` | Author metadata: `name` and `email` (runtime-checkable) |
|
|
81
|
+
| `ICliCommandParameterDescriptor` | Parameter declaration: name, type, required, aliases, default value (runtime-checkable) |
|
|
82
|
+
|
|
83
|
+
### Data Classes
|
|
84
|
+
|
|
85
|
+
| Class | Description |
|
|
86
|
+
|-------|-------------|
|
|
87
|
+
| `CliProcessCommand` | Parsed command input: `command`, `value`, `args`, `chain_commands`, `raw_command`, `data` |
|
|
88
|
+
| `CliCommandAuthor` | Simple implementation of `ICliCommandAuthor` |
|
|
89
|
+
| `CliCommandParameterDescriptor` | Simple implementation of `ICliCommandParameterDescriptor` |
|
|
90
|
+
|
|
91
|
+
### Constants
|
|
92
|
+
|
|
93
|
+
| Constant | Description |
|
|
94
|
+
|----------|-------------|
|
|
95
|
+
| `DEFAULT_LIBRARY_AUTHOR` | Default `CliCommandAuthor` instance used when no author is specified |
|
|
96
|
+
|
|
97
|
+
### `ICliCommandProcessor` Properties
|
|
98
|
+
|
|
99
|
+
| Property | Type | Default | Description |
|
|
100
|
+
|----------|------|---------|-------------|
|
|
101
|
+
| `command` | `str` | *(abstract)* | The command name users type to invoke this processor |
|
|
102
|
+
| `description` | `str` | *(abstract)* | Human-readable description shown in help |
|
|
103
|
+
| `author` | `ICliCommandAuthor` | `DEFAULT_LIBRARY_AUTHOR` | Author metadata |
|
|
104
|
+
| `version` | `str` | `"1.0.0"` | Processor version |
|
|
105
|
+
| `api_version` | `int` | `1` | Minimum API version this processor targets |
|
|
106
|
+
| `allow_unlisted_commands` | `bool \| None` | `None` | Accept sub-commands not in `processors` list |
|
|
107
|
+
| `value_required` | `bool \| None` | `None` | Whether a positional value argument is required |
|
|
108
|
+
| `processors` | `list \| None` | `None` | Nested sub-command processors |
|
|
109
|
+
| `parameters` | `list \| None` | `None` | Declared parameters for autocompletion and validation |
|
|
110
|
+
| `handle_async(command)` | method | *(abstract)* | Execute the command, return result string |
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
MIT
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# qodalis-cli-server-abstractions
|
|
2
|
+
|
|
3
|
+
Shared interfaces and base classes for building [Qodalis CLI](https://qodalis.com/) command processors in Python. **Zero framework dependencies** — install this package when writing plugins, without pulling in FastAPI, uvicorn, or websockets.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install qodalis-cli-server-abstractions
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
Create a custom command processor by subclassing `CliCommandProcessor`:
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from qodalis_cli_server_abstractions import (
|
|
17
|
+
CliCommandProcessor,
|
|
18
|
+
CliProcessCommand,
|
|
19
|
+
CliCommandParameterDescriptor,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class GreetCommandProcessor(CliCommandProcessor):
|
|
24
|
+
@property
|
|
25
|
+
def command(self) -> str:
|
|
26
|
+
return "greet"
|
|
27
|
+
|
|
28
|
+
@property
|
|
29
|
+
def description(self) -> str:
|
|
30
|
+
return "Greets a user by name"
|
|
31
|
+
|
|
32
|
+
@property
|
|
33
|
+
def parameters(self):
|
|
34
|
+
return [
|
|
35
|
+
CliCommandParameterDescriptor("--name", "Name to greet", required=True),
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
async def handle_async(self, command: CliProcessCommand) -> str:
|
|
39
|
+
name = command.args.get("name", "World")
|
|
40
|
+
return f"Hello, {name}!"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Then register the processor with the server package. See [`qodalis-cli-server`](https://pypi.org/project/qodalis-cli-server/) for server setup.
|
|
44
|
+
|
|
45
|
+
## API Reference
|
|
46
|
+
|
|
47
|
+
### Abstract Base Classes
|
|
48
|
+
|
|
49
|
+
| Class | Description |
|
|
50
|
+
|-------|-------------|
|
|
51
|
+
| `ICliCommandProcessor` | Abstract base defining the processor contract: command, description, author, parameters, sub-processors, and `handle_async()` |
|
|
52
|
+
| `CliCommandProcessor` | Convenience subclass of `ICliCommandProcessor` with sensible defaults |
|
|
53
|
+
|
|
54
|
+
### Protocols
|
|
55
|
+
|
|
56
|
+
| Protocol | Description |
|
|
57
|
+
|----------|-------------|
|
|
58
|
+
| `ICliCommandAuthor` | Author metadata: `name` and `email` (runtime-checkable) |
|
|
59
|
+
| `ICliCommandParameterDescriptor` | Parameter declaration: name, type, required, aliases, default value (runtime-checkable) |
|
|
60
|
+
|
|
61
|
+
### Data Classes
|
|
62
|
+
|
|
63
|
+
| Class | Description |
|
|
64
|
+
|-------|-------------|
|
|
65
|
+
| `CliProcessCommand` | Parsed command input: `command`, `value`, `args`, `chain_commands`, `raw_command`, `data` |
|
|
66
|
+
| `CliCommandAuthor` | Simple implementation of `ICliCommandAuthor` |
|
|
67
|
+
| `CliCommandParameterDescriptor` | Simple implementation of `ICliCommandParameterDescriptor` |
|
|
68
|
+
|
|
69
|
+
### Constants
|
|
70
|
+
|
|
71
|
+
| Constant | Description |
|
|
72
|
+
|----------|-------------|
|
|
73
|
+
| `DEFAULT_LIBRARY_AUTHOR` | Default `CliCommandAuthor` instance used when no author is specified |
|
|
74
|
+
|
|
75
|
+
### `ICliCommandProcessor` Properties
|
|
76
|
+
|
|
77
|
+
| Property | Type | Default | Description |
|
|
78
|
+
|----------|------|---------|-------------|
|
|
79
|
+
| `command` | `str` | *(abstract)* | The command name users type to invoke this processor |
|
|
80
|
+
| `description` | `str` | *(abstract)* | Human-readable description shown in help |
|
|
81
|
+
| `author` | `ICliCommandAuthor` | `DEFAULT_LIBRARY_AUTHOR` | Author metadata |
|
|
82
|
+
| `version` | `str` | `"1.0.0"` | Processor version |
|
|
83
|
+
| `api_version` | `int` | `1` | Minimum API version this processor targets |
|
|
84
|
+
| `allow_unlisted_commands` | `bool \| None` | `None` | Accept sub-commands not in `processors` list |
|
|
85
|
+
| `value_required` | `bool \| None` | `None` | Whether a positional value argument is required |
|
|
86
|
+
| `processors` | `list \| None` | `None` | Nested sub-command processors |
|
|
87
|
+
| `parameters` | `list \| None` | `None` | Declared parameters for autocompletion and validation |
|
|
88
|
+
| `handle_async(command)` | method | *(abstract)* | Execute the command, return result string |
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
MIT
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "qodalis-cli-server-abstractions"
|
|
7
|
+
version = "1.0.0b1"
|
|
8
|
+
description = "Shared interfaces and base classes for Qodalis CLI command processors — zero framework dependencies"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Nicolae Lupei", email = "nicolae.lupei@qodalis.com" },
|
|
14
|
+
]
|
|
15
|
+
keywords = ["cli", "qodalis", "terminal", "commands", "command-processor", "abstractions"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Homepage = "https://github.com/qodalis-solutions/cli-server-python"
|
|
29
|
+
Repository = "https://github.com/qodalis-solutions/cli-server-python"
|
|
30
|
+
Issues = "https://github.com/qodalis-solutions/cli-server-python/issues"
|
|
31
|
+
|
|
32
|
+
[tool.hatch.build.targets.wheel]
|
|
33
|
+
packages = ["src/qodalis_cli_server_abstractions"]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from .cli_command_author import ICliCommandAuthor, CliCommandAuthor, DEFAULT_LIBRARY_AUTHOR
|
|
2
|
+
from .cli_process_command import CliProcessCommand
|
|
3
|
+
from .cli_command_parameter_descriptor import (
|
|
4
|
+
ICliCommandParameterDescriptor,
|
|
5
|
+
CliCommandParameterDescriptor,
|
|
6
|
+
)
|
|
7
|
+
from .cli_command_processor import ICliCommandProcessor, CliCommandProcessor
|
|
8
|
+
from .cli_module import ICliModule, CliModule
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"ICliCommandAuthor",
|
|
12
|
+
"CliCommandAuthor",
|
|
13
|
+
"DEFAULT_LIBRARY_AUTHOR",
|
|
14
|
+
"CliProcessCommand",
|
|
15
|
+
"ICliCommandParameterDescriptor",
|
|
16
|
+
"CliCommandParameterDescriptor",
|
|
17
|
+
"ICliCommandProcessor",
|
|
18
|
+
"CliCommandProcessor",
|
|
19
|
+
"ICliModule",
|
|
20
|
+
"CliModule",
|
|
21
|
+
]
|
qodalis_cli_server_abstractions-1.0.0b1/src/qodalis_cli_server_abstractions/cli_command_author.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Protocol, runtime_checkable
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@runtime_checkable
|
|
7
|
+
class ICliCommandAuthor(Protocol):
|
|
8
|
+
name: str
|
|
9
|
+
email: str
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class CliCommandAuthor:
|
|
13
|
+
def __init__(self, name: str, email: str) -> None:
|
|
14
|
+
self.name = name
|
|
15
|
+
self.email = email
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
DEFAULT_LIBRARY_AUTHOR = CliCommandAuthor("Nicolae Lupei", "nicolae.lupei@qodalis.com")
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any, Protocol, runtime_checkable
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@runtime_checkable
|
|
7
|
+
class ICliCommandParameterDescriptor(Protocol):
|
|
8
|
+
name: str
|
|
9
|
+
description: str
|
|
10
|
+
required: bool
|
|
11
|
+
type: str
|
|
12
|
+
aliases: list[str] | None
|
|
13
|
+
default_value: Any
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class CliCommandParameterDescriptor:
|
|
17
|
+
def __init__(
|
|
18
|
+
self,
|
|
19
|
+
name: str,
|
|
20
|
+
description: str,
|
|
21
|
+
required: bool = False,
|
|
22
|
+
type: str = "string",
|
|
23
|
+
aliases: list[str] | None = None,
|
|
24
|
+
default_value: Any = None,
|
|
25
|
+
) -> None:
|
|
26
|
+
self.name = name
|
|
27
|
+
self.description = description
|
|
28
|
+
self.required = required
|
|
29
|
+
self.type = type
|
|
30
|
+
self.aliases = aliases
|
|
31
|
+
self.default_value = default_value
|
qodalis_cli_server_abstractions-1.0.0b1/src/qodalis_cli_server_abstractions/cli_command_processor.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import abc
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
|
+
|
|
6
|
+
from .cli_command_author import DEFAULT_LIBRARY_AUTHOR, ICliCommandAuthor
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from .cli_command_parameter_descriptor import ICliCommandParameterDescriptor
|
|
10
|
+
from .cli_process_command import CliProcessCommand
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ICliCommandProcessor(abc.ABC):
|
|
14
|
+
@property
|
|
15
|
+
@abc.abstractmethod
|
|
16
|
+
def command(self) -> str: ...
|
|
17
|
+
|
|
18
|
+
@property
|
|
19
|
+
@abc.abstractmethod
|
|
20
|
+
def description(self) -> str: ...
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def author(self) -> ICliCommandAuthor:
|
|
24
|
+
return DEFAULT_LIBRARY_AUTHOR
|
|
25
|
+
|
|
26
|
+
@property
|
|
27
|
+
def version(self) -> str:
|
|
28
|
+
return "1.0.0"
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def allow_unlisted_commands(self) -> bool | None:
|
|
32
|
+
return None
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
def value_required(self) -> bool | None:
|
|
36
|
+
return None
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def api_version(self) -> int:
|
|
40
|
+
"""API version this processor targets. Default 1 for backward compat."""
|
|
41
|
+
return 1
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def processors(self) -> list[ICliCommandProcessor] | None:
|
|
45
|
+
return None
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def parameters(self) -> list[ICliCommandParameterDescriptor] | None:
|
|
49
|
+
return None
|
|
50
|
+
|
|
51
|
+
@abc.abstractmethod
|
|
52
|
+
async def handle_async(self, command: CliProcessCommand) -> str: ...
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class CliCommandProcessor(ICliCommandProcessor):
|
|
56
|
+
"""Convenience base class with sensible defaults."""
|
|
57
|
+
|
|
58
|
+
pass
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import abc
|
|
4
|
+
from typing import Sequence
|
|
5
|
+
|
|
6
|
+
from .cli_command_processor import ICliCommandProcessor
|
|
7
|
+
from .cli_command_author import ICliCommandAuthor, DEFAULT_LIBRARY_AUTHOR
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ICliModule(abc.ABC):
|
|
11
|
+
"""Represents a module that bundles one or more command processors."""
|
|
12
|
+
|
|
13
|
+
@property
|
|
14
|
+
@abc.abstractmethod
|
|
15
|
+
def name(self) -> str:
|
|
16
|
+
"""Unique name of the module."""
|
|
17
|
+
...
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
@abc.abstractmethod
|
|
21
|
+
def version(self) -> str:
|
|
22
|
+
"""Module version."""
|
|
23
|
+
...
|
|
24
|
+
|
|
25
|
+
@property
|
|
26
|
+
@abc.abstractmethod
|
|
27
|
+
def description(self) -> str:
|
|
28
|
+
"""Short description of the module."""
|
|
29
|
+
...
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def author(self) -> ICliCommandAuthor:
|
|
33
|
+
"""Author of the module."""
|
|
34
|
+
return DEFAULT_LIBRARY_AUTHOR
|
|
35
|
+
|
|
36
|
+
@property
|
|
37
|
+
@abc.abstractmethod
|
|
38
|
+
def processors(self) -> Sequence[ICliCommandProcessor]:
|
|
39
|
+
"""Command processors provided by this module."""
|
|
40
|
+
...
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class CliModule(ICliModule):
|
|
44
|
+
"""Base class for CLI modules providing sensible defaults."""
|
|
45
|
+
pass
|
qodalis_cli_server_abstractions-1.0.0b1/src/qodalis_cli_server_abstractions/cli_process_command.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass
|
|
8
|
+
class CliProcessCommand:
|
|
9
|
+
command: str = ""
|
|
10
|
+
raw_command: str = ""
|
|
11
|
+
value: str | None = None
|
|
12
|
+
args: dict[str, Any] = field(default_factory=dict)
|
|
13
|
+
chain_commands: list[str] = field(default_factory=list)
|
|
14
|
+
data: Any = None
|