command-router 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.
- command_router-1.0.0b1/LICENSE +32 -0
- command_router-1.0.0b1/PKG-INFO +120 -0
- command_router-1.0.0b1/README.md +71 -0
- command_router-1.0.0b1/pyproject.toml +55 -0
- command_router-1.0.0b1/src/command_router/__init__.py +654 -0
- command_router-1.0.0b1/src/command_router/__main__.py +17 -0
- command_router-1.0.0b1/src/command_router/_example/fixtures/README.md +72 -0
- command_router-1.0.0b1/src/command_router/_example/fixtures/__init__.py +86 -0
- command_router-1.0.0b1/src/command_router/_example/fixtures/err.json5 +28 -0
- command_router-1.0.0b1/src/command_router/_example/fixtures/grammars.json5 +15 -0
- command_router-1.0.0b1/src/command_router/_example/fixtures/grammars.py +164 -0
- command_router-1.0.0b1/src/command_router/_example/fixtures/grammars.toml +8 -0
- command_router-1.0.0b1/src/command_router/lib/commands/__init__.py +73 -0
- command_router-1.0.0b1/src/command_router/lib/commands/context.py +159 -0
- command_router-1.0.0b1/src/command_router/lib/commands/dispatcher/__init__.py +277 -0
- command_router-1.0.0b1/src/command_router/lib/commands/dispatcher/nodes/__init__.py +16 -0
- command_router-1.0.0b1/src/command_router/lib/commands/dispatcher/nodes/argument.py +55 -0
- command_router-1.0.0b1/src/command_router/lib/commands/dispatcher/nodes/command.py +94 -0
- command_router-1.0.0b1/src/command_router/lib/commands/dispatcher/nodes/kinds.py +17 -0
- command_router-1.0.0b1/src/command_router/lib/commands/dispatcher/nodes/literal.py +23 -0
- command_router-1.0.0b1/src/command_router/lib/commands/dispatcher/nodes/root.py +21 -0
- command_router-1.0.0b1/src/command_router/lib/commands/typing.py +123 -0
- command_router-1.0.0b1/src/command_router/lib/control/__init__.py +24 -0
- command_router-1.0.0b1/src/command_router/lib/control/api/__init__.py +103 -0
- command_router-1.0.0b1/src/command_router/lib/control/api/context.py +182 -0
- command_router-1.0.0b1/src/command_router/lib/control/api/control.py +577 -0
- command_router-1.0.0b1/src/command_router/lib/control/api/result.py +352 -0
- command_router-1.0.0b1/src/command_router/lib/control/compiler.py +356 -0
- command_router-1.0.0b1/src/command_router/lib/control/fixture_loader.py +137 -0
- command_router-1.0.0b1/src/command_router/lib/control/grammar.py +421 -0
- command_router-1.0.0b1/src/command_router/lib/grammar/loader.py +84 -0
- command_router-1.0.0b1/src/command_router/lib/grammar/parsers.py +58 -0
- command_router-1.0.0b1/src/command_router/py.typed +0 -0
- command_router-1.0.0b1/src/command_router/sdk/__init__.py +74 -0
- command_router-1.0.0b1/src/command_router/sdk/backend/__init__.py +24 -0
- command_router-1.0.0b1/src/command_router/sdk/backend/builder.py +253 -0
- command_router-1.0.0b1/src/command_router/sdk/backend/holder.py +73 -0
- command_router-1.0.0b1/src/command_router/sdk/backend/loader.py +55 -0
- command_router-1.0.0b1/src/command_router/sdk/backend/settings.py +300 -0
- command_router-1.0.0b1/src/command_router/sdk/backend/setup.py +149 -0
- command_router-1.0.0b1/src/command_router/sdk/user.py +106 -0
- command_router-1.0.0b1/src/command_router/suggestions/__init__.py +314 -0
- command_router-1.0.0b1/src/command_router/suggestions/algo.py +173 -0
- command_router-1.0.0b1/src/command_router/suggestions/context.py +98 -0
- command_router-1.0.0b1/src/command_router/suite/__init__.py +392 -0
- command_router-1.0.0b1/src/command_router/suite/css.py +98 -0
- command_router-1.0.0b1/src/command_router/utils/__init__.py +10 -0
- command_router-1.0.0b1/src/command_router/utils/cli/__init__.py +426 -0
- command_router-1.0.0b1/src/command_router/utils/cli/env_flags.py +284 -0
- command_router-1.0.0b1/src/command_router/utils/context.py +183 -0
- command_router-1.0.0b1/src/command_router/utils/lazy_server.py +60 -0
- command_router-1.0.0b1/src/command_router/utils/logger.py +383 -0
- command_router-1.0.0b1/src/command_router/utils/status.py +119 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
The Clear BSD License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ian Hylton
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted (subject to the limitations in the disclaimer
|
|
8
|
+
below) provided that the following conditions are met:
|
|
9
|
+
|
|
10
|
+
* Redistributions of source code must retain the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer.
|
|
12
|
+
|
|
13
|
+
* Redistributions in binary form must reproduce the above copyright
|
|
14
|
+
notice, this list of conditions and the following disclaimer in the
|
|
15
|
+
documentation and/or other materials provided with the distribution.
|
|
16
|
+
|
|
17
|
+
* Neither the name of the copyright holder nor the names of its
|
|
18
|
+
contributors may be used to endorse or promote products derived from this
|
|
19
|
+
software without specific prior written permission.
|
|
20
|
+
|
|
21
|
+
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
|
|
22
|
+
THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
23
|
+
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
24
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
25
|
+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
26
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
27
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
28
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
29
|
+
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
|
30
|
+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
31
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
32
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: command-router
|
|
3
|
+
Version: 1.0.0b1
|
|
4
|
+
Summary: Small, Brigadier-inspired command router.
|
|
5
|
+
Author: Ian Hylton
|
|
6
|
+
Author-email: Ian Hylton <dcxrpse@krwwstudios.com>
|
|
7
|
+
License: The Clear BSD License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2026 Ian Hylton
|
|
10
|
+
All rights reserved.
|
|
11
|
+
|
|
12
|
+
Redistribution and use in source and binary forms, with or without
|
|
13
|
+
modification, are permitted (subject to the limitations in the disclaimer
|
|
14
|
+
below) provided that the following conditions are met:
|
|
15
|
+
|
|
16
|
+
* Redistributions of source code must retain the above copyright notice,
|
|
17
|
+
this list of conditions and the following disclaimer.
|
|
18
|
+
|
|
19
|
+
* Redistributions in binary form must reproduce the above copyright
|
|
20
|
+
notice, this list of conditions and the following disclaimer in the
|
|
21
|
+
documentation and/or other materials provided with the distribution.
|
|
22
|
+
|
|
23
|
+
* Neither the name of the copyright holder nor the names of its
|
|
24
|
+
contributors may be used to endorse or promote products derived from this
|
|
25
|
+
software without specific prior written permission.
|
|
26
|
+
|
|
27
|
+
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
|
|
28
|
+
THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
29
|
+
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
30
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
31
|
+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
32
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
33
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
34
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
35
|
+
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
|
36
|
+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
37
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
38
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
39
|
+
Requires-Dist: click>=8.4.2
|
|
40
|
+
Requires-Dist: json5>=0.15.0
|
|
41
|
+
Requires-Dist: prompt-toolkit>=3.0.53
|
|
42
|
+
Requires-Dist: rapidfuzz>=3.14.6
|
|
43
|
+
Requires-Dist: textual>=8.2.8
|
|
44
|
+
Requires-Python: >=3.14
|
|
45
|
+
Project-URL: Repository, https://gitlab.com/denniscxrpse/command-router
|
|
46
|
+
Project-URL: Issues, https://gitlab.com/denniscxrpse/command-router/-/work_items
|
|
47
|
+
Project-URL: Documentation, https://gitlab.com/denniscxrpse/command-router/-/wikis/
|
|
48
|
+
Description-Content-Type: text/markdown
|
|
49
|
+
|
|
50
|
+
# command-router
|
|
51
|
+
|
|
52
|
+
Command Router is a small Python library for applications that accept textual commands. Define a command tree or load a
|
|
53
|
+
grammar file, convert input into typed arguments, and invoke the action attached to the matching path. The library keeps
|
|
54
|
+
syntax, application state, error details, completion, and process transports as separate pieces that can be used
|
|
55
|
+
together or independently.
|
|
56
|
+
|
|
57
|
+
The main user-facing features are:
|
|
58
|
+
|
|
59
|
+
- hand-built and fluent command trees with literals, typed arguments, choices, optionals, and greedy text;
|
|
60
|
+
- TOML and JSON5 grammar files for file-backed command surfaces;
|
|
61
|
+
- fixture classes that bind command names to application actions and state;
|
|
62
|
+
- structured parse, initialization, and execution results with useful expectations and partial arguments;
|
|
63
|
+
- prefix-first and typo-aware suggestions, including an optional HTTP suggestions endpoint;
|
|
64
|
+
- aliases and repeating modifier chains through redirect edges;
|
|
65
|
+
- embedded, interactive, and stdin/stdio service modes.
|
|
66
|
+
|
|
67
|
+
## Install
|
|
68
|
+
|
|
69
|
+
The [uv](https://docs.astral.sh/uv/) package manager can be used to install the library:
|
|
70
|
+
|
|
71
|
+
```sh
|
|
72
|
+
uv venv
|
|
73
|
+
uv add command-router
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
You may use [pip](https://pip.pypa.io/en/stable/) for a more conventional approach:
|
|
77
|
+
|
|
78
|
+
```sh
|
|
79
|
+
python -m venv ./venv
|
|
80
|
+
pip install command-router
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## How it works
|
|
84
|
+
|
|
85
|
+
```mermaid
|
|
86
|
+
flowchart LR
|
|
87
|
+
Input["Command text"] --> Control["Control checks input"]
|
|
88
|
+
Control --> Dispatcher["Dispatcher walks command tree"]
|
|
89
|
+
Dispatcher --> Action["Fixture action"]
|
|
90
|
+
Dispatcher --> Failure["Structured error + suggestions"]
|
|
91
|
+
Action --> Result["ControlResult"]
|
|
92
|
+
Failure --> Result
|
|
93
|
+
Result --> Consumer["Application, REPL, or process client"]
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`Control` handles the command prefix and execution lifecycle. The dispatcher handles tokenization and tree matching.
|
|
97
|
+
Fixtures supply actions and state. Every path returns a result that can be inspected directly or serialized for another
|
|
98
|
+
process.
|
|
99
|
+
|
|
100
|
+
## Run it
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
just -l # see available recipes
|
|
104
|
+
just test # run the test suite
|
|
105
|
+
just run # start the router
|
|
106
|
+
just run -L # start the router in lazy grammar mode
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
[Install `just`](https://just.systems/man/en/packages.html) if you don't have it yet.
|
|
110
|
+
|
|
111
|
+
## Documentation
|
|
112
|
+
|
|
113
|
+
Start with the [project documentation](https://gitlab.com/denniscxrpse/command-router/-/wikis/home). It explains the
|
|
114
|
+
command tree, fixture SDK, grammar files, structured response contracts, suggestions, redirects, service modes, and
|
|
115
|
+
the external consumer example.
|
|
116
|
+
|
|
117
|
+
## Mirrors
|
|
118
|
+
|
|
119
|
+
- Primary: https://gitlab.com/denniscxrpse/command-router
|
|
120
|
+
- Mirror: https://github.com/denniscxrpse/command-router
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# command-router
|
|
2
|
+
|
|
3
|
+
Command Router is a small Python library for applications that accept textual commands. Define a command tree or load a
|
|
4
|
+
grammar file, convert input into typed arguments, and invoke the action attached to the matching path. The library keeps
|
|
5
|
+
syntax, application state, error details, completion, and process transports as separate pieces that can be used
|
|
6
|
+
together or independently.
|
|
7
|
+
|
|
8
|
+
The main user-facing features are:
|
|
9
|
+
|
|
10
|
+
- hand-built and fluent command trees with literals, typed arguments, choices, optionals, and greedy text;
|
|
11
|
+
- TOML and JSON5 grammar files for file-backed command surfaces;
|
|
12
|
+
- fixture classes that bind command names to application actions and state;
|
|
13
|
+
- structured parse, initialization, and execution results with useful expectations and partial arguments;
|
|
14
|
+
- prefix-first and typo-aware suggestions, including an optional HTTP suggestions endpoint;
|
|
15
|
+
- aliases and repeating modifier chains through redirect edges;
|
|
16
|
+
- embedded, interactive, and stdin/stdio service modes.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
The [uv](https://docs.astral.sh/uv/) package manager can be used to install the library:
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
uv venv
|
|
24
|
+
uv add command-router
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
You may use [pip](https://pip.pypa.io/en/stable/) for a more conventional approach:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
python -m venv ./venv
|
|
31
|
+
pip install command-router
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## How it works
|
|
35
|
+
|
|
36
|
+
```mermaid
|
|
37
|
+
flowchart LR
|
|
38
|
+
Input["Command text"] --> Control["Control checks input"]
|
|
39
|
+
Control --> Dispatcher["Dispatcher walks command tree"]
|
|
40
|
+
Dispatcher --> Action["Fixture action"]
|
|
41
|
+
Dispatcher --> Failure["Structured error + suggestions"]
|
|
42
|
+
Action --> Result["ControlResult"]
|
|
43
|
+
Failure --> Result
|
|
44
|
+
Result --> Consumer["Application, REPL, or process client"]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`Control` handles the command prefix and execution lifecycle. The dispatcher handles tokenization and tree matching.
|
|
48
|
+
Fixtures supply actions and state. Every path returns a result that can be inspected directly or serialized for another
|
|
49
|
+
process.
|
|
50
|
+
|
|
51
|
+
## Run it
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
just -l # see available recipes
|
|
55
|
+
just test # run the test suite
|
|
56
|
+
just run # start the router
|
|
57
|
+
just run -L # start the router in lazy grammar mode
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
[Install `just`](https://just.systems/man/en/packages.html) if you don't have it yet.
|
|
61
|
+
|
|
62
|
+
## Documentation
|
|
63
|
+
|
|
64
|
+
Start with the [project documentation](https://gitlab.com/denniscxrpse/command-router/-/wikis/home). It explains the
|
|
65
|
+
command tree, fixture SDK, grammar files, structured response contracts, suggestions, redirects, service modes, and
|
|
66
|
+
the external consumer example.
|
|
67
|
+
|
|
68
|
+
## Mirrors
|
|
69
|
+
|
|
70
|
+
- Primary: https://gitlab.com/denniscxrpse/command-router
|
|
71
|
+
- Mirror: https://github.com/denniscxrpse/command-router
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "command-router"
|
|
3
|
+
version = "1.0.0b1"
|
|
4
|
+
requires-python = ">=3.14"
|
|
5
|
+
license = { file = "LICENSE" }
|
|
6
|
+
license-expression = "BSD-3-Clause-Clear"
|
|
7
|
+
authors = [
|
|
8
|
+
{ name = "Ian Hylton", email = "dcxrpse@krwwstudios.com" }
|
|
9
|
+
]
|
|
10
|
+
description = "Small, Brigadier-inspired command router."
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"click>=8.4.2",
|
|
14
|
+
"json5>=0.15.0",
|
|
15
|
+
"prompt-toolkit>=3.0.53",
|
|
16
|
+
"rapidfuzz>=3.14.6",
|
|
17
|
+
"textual>=8.2.8",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[dependency-groups]
|
|
21
|
+
dev = [
|
|
22
|
+
"black>=26.5.1",
|
|
23
|
+
# The only reason to add `mypy` was because of `stubgen`.
|
|
24
|
+
# Do not use `mypy` for anything else, if not at all.
|
|
25
|
+
"mypy>=2.3.1",
|
|
26
|
+
"pytest>=9.1.1",
|
|
27
|
+
"ruff>=0.15.22",
|
|
28
|
+
"rust-just>=1.58.0",
|
|
29
|
+
"ty>=0.0.77",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.scripts]
|
|
33
|
+
cmd-router = "command_router.__main__:console_main"
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Repository = "https://gitlab.com/denniscxrpse/command-router"
|
|
37
|
+
Issues = "https://gitlab.com/denniscxrpse/command-router/-/work_items"
|
|
38
|
+
Documentation = "https://gitlab.com/denniscxrpse/command-router/-/wikis/"
|
|
39
|
+
|
|
40
|
+
[tool.black]
|
|
41
|
+
line-length = 120
|
|
42
|
+
target-version = ['py314']
|
|
43
|
+
|
|
44
|
+
[tool.pytest.ini_options]
|
|
45
|
+
pythonpath = ["src"]
|
|
46
|
+
|
|
47
|
+
[tool.pyrefly]
|
|
48
|
+
project-includes = [
|
|
49
|
+
"**/*.py*",
|
|
50
|
+
"**/*.ipynb",
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
[build-system]
|
|
54
|
+
requires = ["uv_build>=0.11.29,<0.12.0"]
|
|
55
|
+
build-backend = "uv_build"
|