cells-cli 0.2.1__py3-none-any.whl
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.
- cells/cli/__init__.py +65 -0
- cells/cli/app.py +336 -0
- cells/cli/banner.py +117 -0
- cells/cli/command.py +147 -0
- cells/cli/converters.py +73 -0
- cells/cli/env.py +100 -0
- cells/cli/errors.py +30 -0
- cells/cli/menu.py +110 -0
- cells/cli/parser.py +129 -0
- cells/cli/prompt.py +98 -0
- cells/cli/render.py +135 -0
- cells/cli/resolver.py +167 -0
- cells/cli/session.py +185 -0
- cells/cli/style.py +46 -0
- cells/cli/text.py +136 -0
- cells/cli/version.py +3 -0
- cells_cli-0.2.1.dist-info/METADATA +205 -0
- cells_cli-0.2.1.dist-info/RECORD +21 -0
- cells_cli-0.2.1.dist-info/WHEEL +5 -0
- cells_cli-0.2.1.dist-info/licenses/LICENSE +21 -0
- cells_cli-0.2.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cells-cli
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: Declarative CLI toolkit for typed commands, interactive terminal interfaces, and native asyncio support
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Requires-Python: >=3.13
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: regex>=2026.11.30
|
|
10
|
+
Provides-Extra: test
|
|
11
|
+
Requires-Dist: pytest>=8; extra == "test"
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# cells-cli
|
|
15
|
+
|
|
16
|
+
**cells-cli** is a lightweight Python toolkit for declarative command-line applications and line-based terminal interfaces. A single command declaration defines argument parsing, help, interactive prompts and command dispatch, with native asyncio support.
|
|
17
|
+
|
|
18
|
+
- Python 3.13+; runtime dependency: `regex`.
|
|
19
|
+
- Typed arguments with environment, dotenv and TOML configuration.
|
|
20
|
+
- Synchronous and asynchronous commands, interactive menus and noninteractive execution.
|
|
21
|
+
- Standalone terminal presentation: banners, prompts, tables and Unicode-aware text layout.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
python -m pip install cells-cli
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Versioned wheels are available on [GitHub Releases](https://github.com/pylab-me/cells-cli/releases). The `rolling` prerelease tracks successful builds of `main`.
|
|
30
|
+
|
|
31
|
+
## Quick start
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
import asyncio
|
|
35
|
+
from typing import Annotated
|
|
36
|
+
|
|
37
|
+
from cells.cli import Argument, Banner, Session, parse_human_int
|
|
38
|
+
from cells.cli.app import App
|
|
39
|
+
|
|
40
|
+
app = App("server", banner=Banner("SERVER"))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@app.command()
|
|
44
|
+
def start(
|
|
45
|
+
session: Session,
|
|
46
|
+
buffer: Annotated[
|
|
47
|
+
int, Argument(short="-b", env="SERVER_BUFFER", parse=parse_human_int)
|
|
48
|
+
] = 65536,
|
|
49
|
+
) -> None:
|
|
50
|
+
"""Display the configured buffer capacity."""
|
|
51
|
+
session.print_message(f"Buffer: {buffer}")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@app.command()
|
|
55
|
+
async def refresh(session: Session) -> None:
|
|
56
|
+
"""Run an asynchronous command."""
|
|
57
|
+
await asyncio.sleep(0)
|
|
58
|
+
session.print_message("Refresh completed.")
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
if __name__ == "__main__":
|
|
62
|
+
raise SystemExit(app.run())
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
python main.py start --buffer 64Ki
|
|
67
|
+
python main.py refresh
|
|
68
|
+
python main.py start --help
|
|
69
|
+
python main.py
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The same handlers serve direct invocation and interactive menus. Without arguments, an interactive terminal opens the menu; noninteractive execution displays help.
|
|
73
|
+
|
|
74
|
+
## Configuration
|
|
75
|
+
|
|
76
|
+
Default precedence, from highest to lowest: **CLI > environment > dotenv > TOML > declared default**.
|
|
77
|
+
|
|
78
|
+
```toml
|
|
79
|
+
# config.toml
|
|
80
|
+
[server]
|
|
81
|
+
buffer = "64Ki"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
app = App(
|
|
86
|
+
"server",
|
|
87
|
+
config="config.toml",
|
|
88
|
+
source_order=("cli", "env", "config", "default"),
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@app.command()
|
|
93
|
+
def start(
|
|
94
|
+
session: Session,
|
|
95
|
+
buffer: Annotated[
|
|
96
|
+
int,
|
|
97
|
+
Argument(env="SERVER_BUFFER", config="server.buffer", parse=parse_human_int),
|
|
98
|
+
] = 65536,
|
|
99
|
+
) -> None:
|
|
100
|
+
"""Display the resolved buffer capacity."""
|
|
101
|
+
session.print_message(f"Buffer: {buffer}")
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`App` defines source precedence. Explicit CLI arguments always take priority and declared defaults remain last. Intermediate sources may be reordered or omitted; omitted sources are not loaded. Invalid values from the highest-priority source fail validation rather than falling back. Empty strings, `False` and zero are present values.
|
|
105
|
+
|
|
106
|
+
Supply dotenv paths with `env_files=(".env", ".env.local")`; later files take precedence within the dotenv source. Dotenv accepts `KEY=VALUE`, optional `export` and surrounding quotes, without shell evaluation or interpolation. `App` reads the environment without modifying it. Standalone dotenv loading helpers may update the process environment unless `update_process_env=False`.
|
|
107
|
+
|
|
108
|
+
## Execution
|
|
109
|
+
|
|
110
|
+
| API | Purpose |
|
|
111
|
+
| --- | --- |
|
|
112
|
+
| `App.command()` | Register synchronous or asynchronous handlers. |
|
|
113
|
+
| `App.run()` | Execute commands or interactive menus at a CLI entry point. |
|
|
114
|
+
| `await App.run_async(argv)` | Execute noninteractively in an existing asyncio event loop. |
|
|
115
|
+
| `Argument(...)` | Declare argument names, sources, conversion, validation and prompt policy. |
|
|
116
|
+
|
|
117
|
+
`App.run()` creates an asyncio Runner only when needed and reuses it throughout the CLI session. Synchronous handlers execute on the calling thread. `run_async()` uses the caller's loop and disables interactive input; synchronous handlers and configuration reads remain blocking. The caller is responsible for awaiting its tasks.
|
|
118
|
+
|
|
119
|
+
Handlers return `None` (success) or an integer exit code. Input errors return `2`; direct prompt cancellation returns `130`. Handler exceptions and asyncio cancellation propagate. Help and version requests do not load configuration.
|
|
120
|
+
|
|
121
|
+
Interactive menus allow editing resolved values; Enter preserves the typed value. Direct commands prompt for missing values on an interactive terminal unless `prompt=False`. `q`, `back` and `cancel` return to the menu; `qq`, `quit`, `exit` and EOF end the session. Machine mode disables Session prompts, banners and library color. Do not expose secrets through displayed defaults or prompts.
|
|
122
|
+
|
|
123
|
+
## Presentation
|
|
124
|
+
|
|
125
|
+
The presentation API can be used independently of `App`, without loading argparse.
|
|
126
|
+
|
|
127
|
+
| API | Purpose |
|
|
128
|
+
| --- | --- |
|
|
129
|
+
| `Session` | Shared streams, prompts and formatted output. |
|
|
130
|
+
| `Banner` | Application identity and startup presentation. |
|
|
131
|
+
| `MenuSpec`, `MenuItem` | Declarative menu structure. |
|
|
132
|
+
| `Session.run_menu()`, `Session.run_menu_loop()` | Select or dispatch menu actions. |
|
|
133
|
+
| `Table`, `KvRow`, `kv()` | Tables and aligned key/value output. |
|
|
134
|
+
| `run_action()` | Normalize standalone callback exit status. |
|
|
135
|
+
| `display_width()`, `wrap_text()`, `truncate_middle()` | Unicode-aware terminal text layout. |
|
|
136
|
+
|
|
137
|
+
### Banner styles
|
|
138
|
+
|
|
139
|
+
Choose one of three built-in layouts, or supply your own multiline artwork. All four styles are available through `BannerStyle`. `COMPACT` is the default.
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from cells.cli import Banner, BannerStyle, Tone
|
|
143
|
+
|
|
144
|
+
for style in BannerStyle:
|
|
145
|
+
banner = Banner(
|
|
146
|
+
"SERVER",
|
|
147
|
+
subtitle="Service console",
|
|
148
|
+
version="1.0.0",
|
|
149
|
+
style=style,
|
|
150
|
+
tone=Tone.ACCENT,
|
|
151
|
+
artwork="==> SERVER <==\n [ CLI ]" if style is BannerStyle.CUSTOM else None,
|
|
152
|
+
)
|
|
153
|
+
print(banner.render(width=40, color=False))
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
**`BannerStyle.PLAIN`** — Plain text.
|
|
157
|
+
|
|
158
|
+
```text
|
|
159
|
+
SERVER v1.0.0
|
|
160
|
+
Service console
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**`BannerStyle.COMPACT` (default)** — Left-hand accent.
|
|
164
|
+
|
|
165
|
+
```text
|
|
166
|
+
│ SERVER v1.0.0
|
|
167
|
+
│ Service console
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**`BannerStyle.BLOCK`** — Boxed identity.
|
|
171
|
+
|
|
172
|
+
```text
|
|
173
|
+
┌─────────────────┐
|
|
174
|
+
│ SERVER v1.0.0 │
|
|
175
|
+
│ Service console │
|
|
176
|
+
└─────────────────┘
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**`BannerStyle.CUSTOM`** — User-defined artwork followed by identity.
|
|
180
|
+
|
|
181
|
+
```text
|
|
182
|
+
==> SERVER <==
|
|
183
|
+
[ CLI ]
|
|
184
|
+
SERVER v1.0.0
|
|
185
|
+
Service console
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Customize the title, subtitle, version, author, description and metadata independently of layout. `tone` selects a semantic ANSI color when enabled (plain output is unstyled); custom artwork is supplied as a string, not a new layout engine. ANSI escapes in artwork are stripped. Artwork wider than the requested terminal width falls back to `COMPACT`; widths below eight cells use plain text.
|
|
189
|
+
|
|
190
|
+
Pass a `Banner` to `App` or `Session`, or call `render()` directly for standalone output.
|
|
191
|
+
|
|
192
|
+
Automatic color respects `NO_COLOR`, `CLICOLOR_FORCE`, TTY and `TERM`. Text layout preserves Unicode grapheme clusters and estimates terminal cell widths. Sanitize untrusted control characters before rendering. The toolkit targets line-based interfaces and scalar arguments; full-screen interfaces, shell completion, password masking and repeated/collection arguments are outside its supported feature set.
|
|
193
|
+
|
|
194
|
+
See [examples](examples/) for command applications and standalone presentation.
|
|
195
|
+
|
|
196
|
+
## Development
|
|
197
|
+
|
|
198
|
+
```sh
|
|
199
|
+
python -m pip install -e '.[test]' -r requirements.txt
|
|
200
|
+
ruff check .
|
|
201
|
+
ruff format --check .
|
|
202
|
+
python -m pytest -q
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Inspired by [cli-kit](https://github.com/pylab-me/cli-kit). Licensed under [MIT](LICENSE).
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
cells/cli/__init__.py,sha256=upvEVy09Y6P_NcKHf7XopZBv8B0vBV2f18gqG0ho1Yg,1721
|
|
2
|
+
cells/cli/app.py,sha256=WpkL689xBYKBbVOhKbcwrQCYtI-NgPS0JbRptpyeKBo,13669
|
|
3
|
+
cells/cli/banner.py,sha256=zK4_Jp4tIsWXjzyXfQ3dkLXAPVQOciA9ZJudNRjHPe4,4333
|
|
4
|
+
cells/cli/command.py,sha256=P_jb6BpTCWlr3g0Gl69xneBse6AmTkg2NhC8KmJLJDU,5879
|
|
5
|
+
cells/cli/converters.py,sha256=nJ3DGUcNNXyDHKTrYIdUcbCc19b523_wtZVLwJjnxJc,2924
|
|
6
|
+
cells/cli/env.py,sha256=0Z9QXRf0wbQ_U1y81PlYqbHDjkl4WkNTgYUCwBOXHiI,3484
|
|
7
|
+
cells/cli/errors.py,sha256=lgO1-qzwY3QfFHK-qTy2RLjmV7k4lm3vFhgHsBx6RPA,760
|
|
8
|
+
cells/cli/menu.py,sha256=4hbqaqL2W-nDhe01K0jqBGgYwlPAH1OUZZD7vZszDaY,4320
|
|
9
|
+
cells/cli/parser.py,sha256=O9AdxpOOGJsuvdbV77vWva7SnUDyWTTXykFSyuBWE1k,5219
|
|
10
|
+
cells/cli/prompt.py,sha256=ETfit64Ef3MhTSPW0VluyNAy8KKmKGUfOsPwJp1EOEY,3740
|
|
11
|
+
cells/cli/render.py,sha256=fAvDr-MyC6_4WcH6XeTvnSSaKLbWD3AJso5LZNag5bI,4622
|
|
12
|
+
cells/cli/resolver.py,sha256=HjBuBQh_3frZYGH-KxXYugb2xiCAtgyCLXlCzE3R76U,6629
|
|
13
|
+
cells/cli/session.py,sha256=EZ_gd7_Y6KPavktID7c-rMoIaw4NsNkGvKMO5DL0y64,7905
|
|
14
|
+
cells/cli/style.py,sha256=vbB3lwRbMok5F3LBjdZHjH6hwTuZfAewKI5fFpQSl2Q,1412
|
|
15
|
+
cells/cli/text.py,sha256=PdtWl-r6g4swLh5JAgx9xdBY8TFnXYf_PENDx9iytvU,5117
|
|
16
|
+
cells/cli/version.py,sha256=ysBNBwHSIPxpfG3I1E_yH3Rc_tbdELpk39M9azestvM,60
|
|
17
|
+
cells_cli-0.2.1.dist-info/licenses/LICENSE,sha256=CAG42uRYlSJaCpc2dVRMEWpLjT3VjoUUJGY0Soh6CJg,1064
|
|
18
|
+
cells_cli-0.2.1.dist-info/METADATA,sha256=yxcu_TVZ2_9pY0-OukKazJ9F4n1LsrmgylFFNHPCeYg,7783
|
|
19
|
+
cells_cli-0.2.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
20
|
+
cells_cli-0.2.1.dist-info/top_level.txt,sha256=TQEM1e_Z0biNOeSjH-EA0r2urQIScAq4YCH6vxzbE7g,6
|
|
21
|
+
cells_cli-0.2.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 swoiows
|
|
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 @@
|
|
|
1
|
+
cells
|