unifi-cli 0.0.4__py3-none-win_amd64.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.
- unifi_cli/__init__.py +10 -0
- unifi_cli/__main__.py +52 -0
- unifi_cli-0.0.4.data/scripts/unifi-cli.exe +0 -0
- unifi_cli-0.0.4.dist-info/METADATA +191 -0
- unifi_cli-0.0.4.dist-info/RECORD +8 -0
- unifi_cli-0.0.4.dist-info/WHEEL +4 -0
- unifi_cli-0.0.4.dist-info/licenses/LICENSE +21 -0
- unifi_cli-0.0.4.dist-info/sboms/unifi-cli.cyclonedx.json +6261 -0
unifi_cli/__init__.py
ADDED
unifi_cli/__main__.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Command-line interface for unifi-cli.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
import sys
|
|
9
|
+
import subprocess
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def find_native_binary() -> str:
|
|
14
|
+
"""Find the native Rust binary."""
|
|
15
|
+
project_root = Path(__file__).resolve().parent.parent
|
|
16
|
+
target_binary = project_root / "target" / "release" / "unifi-cli"
|
|
17
|
+
if target_binary.exists() and not target_binary.is_dir():
|
|
18
|
+
return str(target_binary)
|
|
19
|
+
|
|
20
|
+
if sys.platform == "win32":
|
|
21
|
+
target_binary = project_root / "target" / "release" / "unifi-cli.exe"
|
|
22
|
+
if target_binary.exists() and not target_binary.is_dir():
|
|
23
|
+
return str(target_binary)
|
|
24
|
+
|
|
25
|
+
raise FileNotFoundError(
|
|
26
|
+
"Could not find the native unifi-cli binary. "
|
|
27
|
+
"Please ensure it was built with 'cargo build --release'."
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def main() -> int:
|
|
32
|
+
"""Run the unifi-cli command line tool."""
|
|
33
|
+
try:
|
|
34
|
+
native_binary = find_native_binary()
|
|
35
|
+
args = [native_binary] + sys.argv[1:]
|
|
36
|
+
|
|
37
|
+
if sys.platform == "win32":
|
|
38
|
+
completed_process = subprocess.run(args)
|
|
39
|
+
return completed_process.returncode
|
|
40
|
+
else:
|
|
41
|
+
os.execv(native_binary, args)
|
|
42
|
+
return 0
|
|
43
|
+
except FileNotFoundError as e:
|
|
44
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
45
|
+
return 1
|
|
46
|
+
except Exception as e:
|
|
47
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
48
|
+
return 1
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
if __name__ == "__main__":
|
|
52
|
+
sys.exit(main())
|
|
Binary file
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: unifi-cli
|
|
3
|
+
Version: 0.0.4
|
|
4
|
+
Classifier: Development Status :: 3 - Alpha
|
|
5
|
+
Classifier: Environment :: Console
|
|
6
|
+
Classifier: Intended Audience :: System Administrators
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Rust
|
|
11
|
+
Classifier: Topic :: System :: Networking
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Summary: CLI for UniFi Network controller
|
|
14
|
+
Home-Page: https://github.com/rvben/unifi-cli
|
|
15
|
+
Author-email: "Ruben J. Jongejan" <ruben.jongejan@gmail.com>
|
|
16
|
+
License: MIT
|
|
17
|
+
Requires-Python: >=3.8
|
|
18
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
19
|
+
Project-URL: Homepage, https://github.com/rvben/unifi-cli
|
|
20
|
+
Project-URL: Repository, https://github.com/rvben/unifi-cli.git
|
|
21
|
+
|
|
22
|
+
# unifi-cli
|
|
23
|
+
|
|
24
|
+
CLI for UniFi Network controller. Designed for both human operators and AI agents.
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
### From source
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
cargo install unifi-cli
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### From GitHub releases
|
|
35
|
+
|
|
36
|
+
Pre-built binaries are available for Linux (x64, arm64), macOS (x64, arm64), and Windows (x64) on the [releases page](https://github.com/rvben/unifi-cli/releases).
|
|
37
|
+
|
|
38
|
+
## Configuration
|
|
39
|
+
|
|
40
|
+
Configuration can be provided via CLI flags, environment variables, or a config file.
|
|
41
|
+
|
|
42
|
+
### CLI flags
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
unifi-cli --host https://unifi.example.com --api-key YOUR_KEY clients list
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Environment variables
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
export UNIFI_HOST=https://unifi.example.com
|
|
52
|
+
export UNIFI_API_KEY=YOUR_KEY
|
|
53
|
+
unifi-cli clients list
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Config file
|
|
57
|
+
|
|
58
|
+
Create `~/.config/unifi-cli/config.toml`:
|
|
59
|
+
|
|
60
|
+
```toml
|
|
61
|
+
host = "https://unifi.example.com"
|
|
62
|
+
api_key = "YOUR_KEY"
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Usage
|
|
66
|
+
|
|
67
|
+
### Clients
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
unifi-cli clients list # List connected clients
|
|
71
|
+
unifi-cli clients show aa:bb:cc:dd:ee:ff # Show client details
|
|
72
|
+
unifi-cli clients block aa:bb:cc:dd:ee:ff # Block a client
|
|
73
|
+
unifi-cli clients unblock aa:bb:cc:dd:ee:ff # Unblock a client
|
|
74
|
+
unifi-cli clients kick aa:bb:cc:dd:ee:ff # Disconnect a client
|
|
75
|
+
unifi-cli clients set-fixed-ip MAC IP [--name] # Set DHCP reservation
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Devices
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
unifi-cli devices list # List network devices
|
|
82
|
+
unifi-cli devices restart aa:bb:cc:dd:ee:ff # Restart a device
|
|
83
|
+
unifi-cli devices locate aa:bb:cc:dd:ee:ff # Blink locate LED
|
|
84
|
+
unifi-cli devices locate aa:bb:cc:dd:ee:ff --off # Stop blinking
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Networks
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
unifi-cli networks # List all networks
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### System
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
unifi-cli system health # Show subsystem health
|
|
97
|
+
unifi-cli system info # Show controller info
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Agent-friendly design
|
|
101
|
+
|
|
102
|
+
unifi-cli is designed to work well with AI agents and automation scripts. Instead of requiring an MCP server, agents can call the CLI directly with lower overhead and better composability.
|
|
103
|
+
|
|
104
|
+
### Automatic JSON output
|
|
105
|
+
|
|
106
|
+
When stdout is not a terminal (piped or redirected), output switches to JSON automatically. No flags needed.
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
# Human at terminal: gets a formatted table
|
|
110
|
+
unifi-cli clients list
|
|
111
|
+
|
|
112
|
+
# Agent piping output: gets JSON automatically
|
|
113
|
+
data=$(unifi-cli clients list)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
You can also force JSON mode explicitly:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
unifi-cli --json clients list
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Clean stdout/stderr separation
|
|
123
|
+
|
|
124
|
+
Data goes to stdout. Human messages (summaries, confirmations) go to stderr. This means piping and redirection always capture clean, parseable data.
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
# stdout has only the JSON data, stderr has "12 clients"
|
|
128
|
+
unifi-cli clients list > clients.json
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Quiet mode
|
|
132
|
+
|
|
133
|
+
Suppress all non-data output with `--quiet`:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
unifi-cli --quiet clients list # No summary line on stderr
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Structured mutation responses
|
|
140
|
+
|
|
141
|
+
Commands that change state (block, kick, restart, etc.) return structured JSON:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
unifi-cli --json clients block aa:bb:cc:dd:ee:ff
|
|
145
|
+
# {"action": "block", "mac": "AA:BB:CC:DD:EE:FF", "status": "ok"}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Runtime schema introspection
|
|
149
|
+
|
|
150
|
+
The `schema` command dumps all commands, arguments, output fields, and exit codes as JSON. Agents can discover capabilities at runtime without parsing `--help` text.
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
unifi-cli schema
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
This outputs the full command tree including which commands are mutating, what arguments they accept, and what fields appear in the JSON output.
|
|
157
|
+
|
|
158
|
+
### Distinct exit codes
|
|
159
|
+
|
|
160
|
+
Agents can branch on specific failure modes without parsing error messages:
|
|
161
|
+
|
|
162
|
+
| Code | Meaning |
|
|
163
|
+
|------|---------|
|
|
164
|
+
| 0 | Success |
|
|
165
|
+
| 1 | General error |
|
|
166
|
+
| 2 | Configuration error (missing host or API key) |
|
|
167
|
+
| 3 | Authentication error (401/403) |
|
|
168
|
+
| 4 | Not found (404) |
|
|
169
|
+
| 5 | API error (server error) |
|
|
170
|
+
|
|
171
|
+
### Why CLI over MCP?
|
|
172
|
+
|
|
173
|
+
For AI agent integrations, a well-designed CLI has several advantages over an MCP server:
|
|
174
|
+
|
|
175
|
+
- **Token efficiency** -- a CLI call uses ~35x fewer tokens than the MCP tool-call protocol
|
|
176
|
+
- **Composability** -- pipe output to `jq`, `grep`, or other tools
|
|
177
|
+
- **No server process** -- no sidecar to run, no port to manage
|
|
178
|
+
- **Universal** -- works from any language, shell, or automation framework
|
|
179
|
+
|
|
180
|
+
## Development
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
make check # Lint and test
|
|
184
|
+
make test # Run tests
|
|
185
|
+
make install # Build and install to ~/.local/bin
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## License
|
|
189
|
+
|
|
190
|
+
MIT
|
|
191
|
+
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
unifi_cli/__init__.py,sha256=mxTST28R42dvCYtJy5l7PZkps696B4E_9X3zQNQw5kA,253
|
|
2
|
+
unifi_cli/__main__.py,sha256=QkjbxdgqykyrS94JwstDVcNdgXO4RecJ9L41koBRxeE,1491
|
|
3
|
+
unifi_cli-0.0.4.data/scripts/unifi-cli.exe,sha256=3Q2y-sh9FrYePiNMdH5WebaIKKh3DO8wgDnHPC6RtaM,5531648
|
|
4
|
+
unifi_cli-0.0.4.dist-info/METADATA,sha256=rpaokG5dnnHJLjyUWPIxCbiBx2OtqrCTdI2vmdpxGrk,5377
|
|
5
|
+
unifi_cli-0.0.4.dist-info/WHEEL,sha256=uJOc2U-Q1x95AlblQcqMRb3iR4QnPtdI7X2ycPN99rM,94
|
|
6
|
+
unifi_cli-0.0.4.dist-info/licenses/LICENSE,sha256=YyJnikhAW7_HwaUPeO-iJud1fh2UplNX6MZP1zd1OXY,1092
|
|
7
|
+
unifi_cli-0.0.4.dist-info/sboms/unifi-cli.cyclonedx.json,sha256=pL2EsLdfdeMhPzSKldARPJRyBKUZhr58OzT467dwI9M,199878
|
|
8
|
+
unifi_cli-0.0.4.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ruben Jongejan
|
|
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.
|