kctl-redis 0.8.4__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.
Files changed (36) hide show
  1. kctl_redis-0.8.4/.gitignore +7 -0
  2. kctl_redis-0.8.4/PKG-INFO +19 -0
  3. kctl_redis-0.8.4/README.md +123 -0
  4. kctl_redis-0.8.4/pyproject.toml +47 -0
  5. kctl_redis-0.8.4/skills/redis-admin/SKILL.md +289 -0
  6. kctl_redis-0.8.4/src/kctl_redis/__init__.py +3 -0
  7. kctl_redis-0.8.4/src/kctl_redis/__main__.py +5 -0
  8. kctl_redis-0.8.4/src/kctl_redis/cli.py +154 -0
  9. kctl_redis-0.8.4/src/kctl_redis/commands/__init__.py +0 -0
  10. kctl_redis-0.8.4/src/kctl_redis/commands/backup.py +144 -0
  11. kctl_redis-0.8.4/src/kctl_redis/commands/clients.py +71 -0
  12. kctl_redis-0.8.4/src/kctl_redis/commands/config_cmd.py +242 -0
  13. kctl_redis-0.8.4/src/kctl_redis/commands/dashboard.py +82 -0
  14. kctl_redis-0.8.4/src/kctl_redis/commands/db.py +93 -0
  15. kctl_redis-0.8.4/src/kctl_redis/commands/doctor_cmd.py +87 -0
  16. kctl_redis-0.8.4/src/kctl_redis/commands/health.py +133 -0
  17. kctl_redis-0.8.4/src/kctl_redis/commands/keys.py +216 -0
  18. kctl_redis-0.8.4/src/kctl_redis/commands/maintenance.py +57 -0
  19. kctl_redis-0.8.4/src/kctl_redis/commands/memory.py +124 -0
  20. kctl_redis-0.8.4/src/kctl_redis/commands/performance.py +112 -0
  21. kctl_redis-0.8.4/src/kctl_redis/commands/persistence.py +93 -0
  22. kctl_redis-0.8.4/src/kctl_redis/commands/pubsub.py +70 -0
  23. kctl_redis-0.8.4/src/kctl_redis/commands/query.py +42 -0
  24. kctl_redis-0.8.4/src/kctl_redis/commands/replication.py +82 -0
  25. kctl_redis-0.8.4/src/kctl_redis/commands/server.py +101 -0
  26. kctl_redis-0.8.4/src/kctl_redis/commands/skill_cmd.py +76 -0
  27. kctl_redis-0.8.4/src/kctl_redis/commands/streams.py +168 -0
  28. kctl_redis-0.8.4/src/kctl_redis/core/__init__.py +0 -0
  29. kctl_redis-0.8.4/src/kctl_redis/core/callbacks.py +46 -0
  30. kctl_redis-0.8.4/src/kctl_redis/core/client.py +137 -0
  31. kctl_redis-0.8.4/src/kctl_redis/core/config.py +160 -0
  32. kctl_redis-0.8.4/src/kctl_redis/core/exceptions.py +41 -0
  33. kctl_redis-0.8.4/src/kctl_redis/core/output.py +5 -0
  34. kctl_redis-0.8.4/tests/conftest.py +132 -0
  35. kctl_redis-0.8.4/tests/test_core.py +77 -0
  36. kctl_redis-0.8.4/tests/test_standard.py +79 -0
@@ -0,0 +1,7 @@
1
+ __pycache__/
2
+ *.pyc
3
+ .venv/
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ uv.lock
@@ -0,0 +1,19 @@
1
+ Metadata-Version: 2.4
2
+ Name: kctl-redis
3
+ Version: 0.8.4
4
+ Summary: Kodemeio Redis CLI — manage Redis servers via SSH tunnel
5
+ Requires-Python: >=3.12
6
+ Requires-Dist: kctl-lib>=0.12.0
7
+ Requires-Dist: paramiko<4.0.0,>=3.4.0
8
+ Requires-Dist: pydantic>=2.10.0
9
+ Requires-Dist: pyyaml>=6.0.2
10
+ Requires-Dist: redis[hiredis]>=5.0.0
11
+ Requires-Dist: rich>=13.9.0
12
+ Requires-Dist: sshtunnel>=0.4.0
13
+ Requires-Dist: typer>=0.15.0
14
+ Provides-Extra: dev
15
+ Requires-Dist: mypy>=1.14.0; extra == 'dev'
16
+ Requires-Dist: pytest>=8.3.0; extra == 'dev'
17
+ Requires-Dist: ruff>=0.9.0; extra == 'dev'
18
+ Requires-Dist: types-pyyaml>=6.0.0; extra == 'dev'
19
+ Requires-Dist: types-redis>=4.6.0; extra == 'dev'
@@ -0,0 +1,123 @@
1
+ # kctl-redis
2
+
3
+ Kodemeio Redis CLI — manage Redis servers via SSH tunnel.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ uv tool install kctl-redis
9
+ # or within the workspace
10
+ uv sync --all-packages
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```bash
16
+ # Initialize a profile
17
+ kctl-redis config init --profile production
18
+
19
+ # Test the connection
20
+ kctl-redis config validate
21
+
22
+ # Check health
23
+ kctl-redis health ping
24
+
25
+ # Live dashboard
26
+ kctl-redis dashboard overview
27
+
28
+ # Scan keys
29
+ kctl-redis keys scan --pattern "session:*"
30
+
31
+ # Run a raw command
32
+ kctl-redis query run GET mykey
33
+ ```
34
+
35
+ ## Command Groups
36
+
37
+ | Group | Description | Commands |
38
+ |-------|-------------|----------|
39
+ | `config` | Profile management (init, add, use, show, validate, remove, set, profiles, current) | 9 |
40
+ | `health` | Ping, latency check, info summary | 3 |
41
+ | `dashboard` | Live server overview | 1 |
42
+ | `query` | Execute raw Redis commands | 1 |
43
+ | `keys` | Scan, get, set, delete, TTL, type, rename | 7 |
44
+ | `db` | List databases, flush, select, move keys | 4 |
45
+ | `memory` | Memory stats, usage by key, doctor, purge | 4 |
46
+ | `clients` | List clients, kill, info | 3 |
47
+ | `server` | Get/set config, save config, reset stats | 4 |
48
+ | `persistence` | RDB status, AOF status, BGSAVE, BGREWRITEAOF | 4 |
49
+ | `replication` | Replication info, promote replica, reset | 3 |
50
+ | `pubsub` | List channels, subscribers, numsub | 3 |
51
+ | `streams` | Stream info, read, trim, delete, groups | 5 |
52
+ | `performance` | Slow log, latency history, command stats, monitor | 4 |
53
+ | `backup` | Dump RDB via SSH, restore, list backups | 3 |
54
+ | `maintenance` | Memory purge, defrag check, flush expired | 3 |
55
+
56
+ **Total: 61 commands**
57
+
58
+ ## Global Options
59
+
60
+ ```
61
+ --json Output as JSON
62
+ --quiet / -q Suppress info messages
63
+ --profile / -p Config profile name
64
+ --host / -H Redis host override
65
+ --port Redis port override
66
+ --user / -U Redis username override
67
+ --password Redis password override
68
+ --db Redis database number override
69
+ --version / -V Show version
70
+ ```
71
+
72
+ ## Configuration
73
+
74
+ Config is stored in `~/.config/kodemeio/config.yaml` under the `redis` service key.
75
+
76
+ ```yaml
77
+ profiles:
78
+ production:
79
+ redis:
80
+ host: 10.0.0.5 # Redis host (internal, accessed via SSH tunnel)
81
+ port: 6379
82
+ username: default
83
+ password: ${REDIS_PASSWORD}
84
+ db: 0
85
+ ssh_host: 49.13.14.79 # Jump host IP
86
+ ssh_port: 22
87
+ ssh_user: root
88
+ ssh_key: ~/.ssh/id_ed25519
89
+ ```
90
+
91
+ ### Environment Variables
92
+
93
+ | Variable | Description |
94
+ |----------|-------------|
95
+ | `KCTL_REDIS_HOST` | Redis host |
96
+ | `KCTL_REDIS_PORT` | Redis port |
97
+ | `KCTL_REDIS_USERNAME` | Redis username |
98
+ | `KCTL_REDIS_PASSWORD` | Redis password |
99
+ | `KCTL_REDIS_SSH_HOST` | SSH tunnel host |
100
+ | `KCTL_REDIS_DB` | Redis database number |
101
+ | `REDIS_HOST` / `REDIS_PORT` | Standard Redis env vars (lower priority) |
102
+
103
+ Resolution order (highest to lowest): CLI flags > `KCTL_REDIS_*` env vars > `REDIS_*` env vars > config file profile.
104
+
105
+ ### Profile Management
106
+
107
+ ```bash
108
+ kctl-redis config init --profile production
109
+ kctl-redis config add --profile staging --host 10.0.0.6 --ssh-host 1.2.3.4
110
+ kctl-redis config use production
111
+ kctl-redis config show
112
+ kctl-redis config profiles
113
+ ```
114
+
115
+ ## Development
116
+
117
+ ```bash
118
+ cd packages/kctl-redis
119
+ uv sync --all-extras
120
+ uv run pytest tests/ -v
121
+ uv run ruff check src/
122
+ uv run mypy src/
123
+ ```
@@ -0,0 +1,47 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "kctl-redis"
7
+ version = "0.8.4"
8
+ description = "Kodemeio Redis CLI — manage Redis servers via SSH tunnel"
9
+ requires-python = ">=3.12"
10
+ dependencies = [
11
+ "kctl-lib>=0.12.0",
12
+ "typer>=0.15.0",
13
+ "rich>=13.9.0",
14
+ "pydantic>=2.10.0",
15
+ "pyyaml>=6.0.2",
16
+ "redis[hiredis]>=5.0.0",
17
+ "sshtunnel>=0.4.0",
18
+ "paramiko>=3.4.0,<4.0.0",
19
+ ]
20
+
21
+ [project.optional-dependencies]
22
+ dev = [
23
+ "pytest>=8.3.0",
24
+ "ruff>=0.9.0",
25
+ "mypy>=1.14.0",
26
+ "types-PyYAML>=6.0.0",
27
+ "types-redis>=4.6.0",
28
+ ]
29
+
30
+ [project.scripts]
31
+ kctl-redis = "kctl_redis.cli:_run"
32
+
33
+ [tool.uv.sources]
34
+ kctl-lib = { workspace = true }
35
+
36
+ [project.entry-points."kctl_redis.plugins"]
37
+
38
+ [tool.hatch.build.targets.wheel]
39
+ packages = ["src/kctl_redis"]
40
+
41
+ [tool.ruff]
42
+ target-version = "py312"
43
+ line-length = 120
44
+
45
+ [tool.mypy]
46
+ python_version = "3.12"
47
+ strict = true
@@ -0,0 +1,289 @@
1
+ ---
2
+ name: redis-admin
3
+ description: >
4
+ Redis server administration via kctl-redis CLI (22 groups, ~68 commands). MUST use for ANY kctl-redis operation. See SKILL.md ## Triggers for keywords.
5
+ Auto-generated: 2026-05-22
6
+ registry_hash: f7369f6882a2
7
+ ---
8
+
9
+ # redis-admin — kctl-redis CLI Reference
10
+
11
+ > Auto-generated from `kctl-redis` command registry. Do not edit manually.
12
+ > To regenerate: `kctl-redis skill generate`
13
+ > To add custom content: edit `SKILL.extra.md` in the same directory.
14
+
15
+ ## Overview
16
+
17
+ **CLI:** `kctl-redis`
18
+ **Command groups:** 22
19
+ **Total commands:** ~68
20
+ **Install:** `cd cli && uv tool install --editable .`
21
+
22
+ ## Global Options
23
+
24
+ | Flag | Description |
25
+ |------|-------------|
26
+ | `--json` | JSON output |
27
+ | `--quiet`, `-q` | Suppress info messages |
28
+ | `--format`, `-f` | Output format: pretty/json/csv/yaml |
29
+ | `--no-header` | Omit CSV header row |
30
+ | `--profile`, `-p` | Config profile name |
31
+ | `--version`, `-V` | Show version |
32
+
33
+ ## Quick Discovery (for AI agents)
34
+
35
+ **DO NOT GUESS command paths or flag names.** Before invoking `kctl-redis <group> <verb> ...`, use these AI-facing affordances:
36
+
37
+ 1. **Find a command by keyword** — substring filter, returns sorted leaf paths:
38
+ ```bash
39
+ kctl-redis commands list --filter <keyword>
40
+ ```
41
+ Example: `kctl-redis commands list --filter database` → all database-related commands in one call.
42
+
43
+ 2. **Inspect flags before invoking** — full param schema with
44
+ opts/defaults/required/choices/help:
45
+ ```bash
46
+ kctl-redis commands tree --json | jq '.. | objects | select(.name == "<verb>") | .params'
47
+ ```
48
+ Reading the `params` array tells you exact flag names (`--lang`), short aliases (`-l`), defaults, required-vs-optional, and choices — eliminating the `No such option '--xxx'` failure mode.
49
+
50
+ 3. **Preview destructive operations without executing** — `--explain` is supported on selected write commands:
51
+ ```bash
52
+ kctl-redis <group> <verb> <args> --explain
53
+ ```
54
+ Prints the planned action and exits 0. If `--explain` errors with "no such option", that command does not support it — fall back to verifying via `commands tree` schema inspection before running for real.
55
+
56
+ 4. **Errors are user-facing one-liners**, not Python tracebacks. A failed invocation shows `❌ <ErrorClass>: <message>` on stderr (or `{"error": ..., "message": ...}` JSON if `--json` was passed). Read the message — it usually tells you exactly what's missing.
57
+
58
+ ## Triggers
59
+
60
+ Auto-invoke this skill when the user references any of these keywords:
61
+
62
+ "aof-status", "backup", "bgrewriteaof", "bgsave", "big-keys", "channels", "check", "clients", "commands", "completions", "config", "config-get", "config-rewrite", "config-set", "consumers", "current", "dashboard", "db", "defrag", "doctor", "dump", "eviction", "exec", "flush", "fragmentation", "generate", "groups", "health", "hit-ratio", "info", "init", "kctl-redis", "keys", "kill", "latency", "maintenance", "memory", "memory-purge", "memory-usage", "monitor", "numsub", "ops-sec", "pending", "performance", "persistence", "ping", "profile", "profiles", "promote", "publish", "pubsub", "query", "rdb-status", "remove", "rename", "replication", "restore", "scan", "self-update", "server", "size", "skill", "slowlog", "stats", "streams", "swap", "test", "tree", "trim", "tui", "type"
63
+
64
+ ## Command Reference
65
+
66
+ ### `kctl-redis backup`
67
+
68
+ Redis backup operations via SSH.
69
+
70
+ | Command | Description |
71
+ |---------|-------------|
72
+ | `backup dump [--output_path]` | Trigger BGSAVE and download the RDB file. |
73
+ | `backup list [--remote_dir]` | List backup files on the remote server. |
74
+ | `backup restore <file_path>` | Upload an RDB file to the server. |
75
+
76
+ ### `kctl-redis clients`
77
+
78
+ Redis client management.
79
+
80
+ | Command | Description |
81
+ |---------|-------------|
82
+ | `clients info` | Show client connection info. |
83
+ | `clients kill <client_id>` | Kill a client connection by ID. |
84
+ | `clients list` | List connected clients. |
85
+
86
+ ### `kctl-redis commands`
87
+
88
+ Machine-readable command discovery (for AI agents).
89
+
90
+ | Command | Description |
91
+ |---------|-------------|
92
+ | `commands list [--json_flag] [--filter_substr]` | List all leaf commands as 'group verb' strings. |
93
+ | `commands tree [--json_flag]` | Dump the full command tree as JSON. |
94
+
95
+ ### `kctl-redis completions`
96
+
97
+ Generate or install shell completions.
98
+
99
+ Usage: `kctl-redis completions [--shell] [--install]`
100
+
101
+ ### `kctl-redis config`
102
+
103
+ Manage kctl-redis configuration profiles.
104
+
105
+ | Command | Description |
106
+ |---------|-------------|
107
+ | `config add <profile> [--host] [--port] [--username] [--password] [--db] [--ssh_host] [--ssh_port] [--ssh_user] [--ssh_key]` | Add or update a profile. |
108
+ | `config current` | Show the active profile name. |
109
+ | `config init [--profile] [--host] [--port] [--username] [--password] [--db] [--ssh_host] [--ssh_port] [--ssh_user] [--ssh_key]` | Initialize kctl-redis configuration. |
110
+ | `config profiles` | List all profiles. |
111
+ | `config remove <profile> [--force]` | Remove a profile. |
112
+ | `config set <key> <value>` | Set a configuration value. |
113
+ | `config show` | Show current configuration (passwords masked). |
114
+ | `config test` | Test Redis connection. |
115
+ | `config use <profile>` | Switch the default profile. |
116
+
117
+ ### `kctl-redis dashboard`
118
+
119
+ Redis system overview.
120
+
121
+ ### `kctl-redis db`
122
+
123
+ Redis database operations.
124
+
125
+ | Command | Description |
126
+ |---------|-------------|
127
+ | `db flush [--force] [--async_mode]` | Flush current database (delete all keys). |
128
+ | `db list` | List databases with key counts. |
129
+ | `db size` | Show key count for current database. |
130
+ | `db swap <db1> <db2>` | Swap two databases. |
131
+
132
+ ### `kctl-redis doctor`
133
+
134
+ Run diagnostic checks.
135
+
136
+ ### `kctl-redis health`
137
+
138
+ Redis health checks.
139
+
140
+ | Command | Description |
141
+ |---------|-------------|
142
+ | `health check [--memory_warn] [--memory_crit] [--clients_warn]` | Run health threshold checks. |
143
+ | `health info` | Show Redis server info summary. |
144
+ | `health ping` | Ping Redis and measure latency. |
145
+
146
+ ### `kctl-redis keys`
147
+
148
+ Redis key management.
149
+
150
+ | Command | Description |
151
+ |---------|-------------|
152
+ | `keys delete <key> [--force]` | Delete a key. |
153
+ | `keys get <key>` | Get value of a key (auto-detects type). |
154
+ | `keys memory-usage <key>` | Show memory usage of a key. |
155
+ | `keys rename <old_key> <new_key>` | Rename a key. |
156
+ | `keys scan [--pattern] [--count] [--key_type] [--limit]` | Scan keys matching a pattern. |
157
+ | `keys ttl <key> [--precise]` | Show time-to-live for a key. |
158
+ | `keys type <key>` | Show key type and encoding. |
159
+
160
+ ### `kctl-redis maintenance`
161
+
162
+ Redis maintenance operations.
163
+
164
+ | Command | Description |
165
+ |---------|-------------|
166
+ | `maintenance config-rewrite` | Persist runtime configuration to redis.conf. |
167
+ | `maintenance defrag` | Check and enable active defragmentation. |
168
+ | `maintenance memory-purge` | Release memory back to the OS. |
169
+
170
+ ### `kctl-redis memory`
171
+
172
+ Redis memory analysis.
173
+
174
+ | Command | Description |
175
+ |---------|-------------|
176
+ | `memory big-keys [--count] [--limit]` | Find largest keys by memory usage. |
177
+ | `memory eviction` | Show eviction policy and stats. |
178
+ | `memory fragmentation` | Show memory fragmentation and recommendation. |
179
+ | `memory stats` | Show memory statistics. |
180
+
181
+ ### `kctl-redis performance`
182
+
183
+ Redis performance monitoring.
184
+
185
+ | Command | Description |
186
+ |---------|-------------|
187
+ | `performance hit-ratio` | Show keyspace hit ratio. |
188
+ | `performance latency` | Show latency monitoring data. |
189
+ | `performance ops-sec` | Show current operations per second. |
190
+ | `performance slowlog [--count]` | Show slow log entries. |
191
+
192
+ ### `kctl-redis persistence`
193
+
194
+ Redis persistence management.
195
+
196
+ | Command | Description |
197
+ |---------|-------------|
198
+ | `persistence aof-status` | Show AOF persistence status. |
199
+ | `persistence bgrewriteaof` | Trigger AOF rewrite. |
200
+ | `persistence bgsave` | Trigger a background RDB save. |
201
+ | `persistence rdb-status` | Show RDB persistence status. |
202
+
203
+ ### `kctl-redis pubsub`
204
+
205
+ Redis Pub/Sub operations.
206
+
207
+ | Command | Description |
208
+ |---------|-------------|
209
+ | `pubsub channels [--pattern]` | List active Pub/Sub channels. |
210
+ | `pubsub numsub <channel_names>` | Show subscriber counts for channels. |
211
+ | `pubsub publish <channel> <message>` | Publish a message to a channel. |
212
+
213
+ ### `kctl-redis query`
214
+
215
+ Execute raw Redis commands.
216
+
217
+ | Command | Description |
218
+ |---------|-------------|
219
+ | `query exec <command>` | Execute a raw Redis command. |
220
+
221
+ ### `kctl-redis replication`
222
+
223
+ Redis replication management.
224
+
225
+ | Command | Description |
226
+ |---------|-------------|
227
+ | `replication info` | Show replication info. |
228
+ | `replication lag` | Show replication lag for replicas. |
229
+ | `replication promote` | Promote this replica to master (REPLICAOF NO ONE). |
230
+
231
+ ### `kctl-redis self-update`
232
+
233
+ Check for updates and upgrade kctl-redis.
234
+
235
+ ### `kctl-redis server`
236
+
237
+ Redis server management.
238
+
239
+ | Command | Description |
240
+ |---------|-------------|
241
+ | `server acl [--user]` | List ACL users or show user details. |
242
+ | `server config-get [--pattern]` | Get Redis configuration parameters. |
243
+ | `server config-set <parameter> <value>` | Set a Redis configuration parameter at runtime. |
244
+ | `server info [--section]` | Show Redis INFO output. |
245
+
246
+ ### `kctl-redis skill`
247
+
248
+ Claude Code skill management.
249
+
250
+ | Command | Description |
251
+ |---------|-------------|
252
+ | `skill generate [--output] [--install] [--check]` | Auto-generate SKILL.md from CLI command registry. |
253
+
254
+ **Examples:**
255
+ ```bash
256
+ kctl-redis skill generate
257
+ kctl-redis skill generate --install
258
+ kctl-redis skill generate --check
259
+ ```
260
+
261
+ ### `kctl-redis streams`
262
+
263
+ Redis Streams operations.
264
+
265
+ | Command | Description |
266
+ |---------|-------------|
267
+ | `streams consumers <key> <group>` | Show consumers in a group. |
268
+ | `streams groups <key>` | Show consumer groups for a stream. |
269
+ | `streams info <key>` | Show stream information. |
270
+ | `streams pending <key> <group> [--count]` | Show pending messages for a consumer group. |
271
+ | `streams trim <key> [--maxlen] [--minid] [--approximate]` | Trim a stream. |
272
+
273
+ ### `kctl-redis tui`
274
+
275
+ Launch the interactive TUI.
276
+
277
+ Usage: `kctl-redis tui [--profile]`
278
+
279
+ ## Configuration
280
+
281
+ Shared config: `~/.config/kodemeio/config.yaml`
282
+
283
+ ```bash
284
+ kctl-redis config init # Interactive setup
285
+ kctl-redis config show # Show current config
286
+ kctl-redis config profiles # List profiles
287
+ kctl-redis config current # Show active profile
288
+ kctl-redis config validate # Verify config
289
+ ```
@@ -0,0 +1,3 @@
1
+ """Kodemeio Redis CLI."""
2
+
3
+ __version__ = "0.8.4"
@@ -0,0 +1,5 @@
1
+ """Allow running as: python -m kctl_redis."""
2
+
3
+ from kctl_redis.cli import _run
4
+
5
+ _run()
@@ -0,0 +1,154 @@
1
+ """Main CLI entry point for kctl-redis."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Annotated
6
+
7
+ import typer
8
+ from kctl_lib import handle_cli_error
9
+ from kctl_lib import cli_entrypoint, register_introspection_commands
10
+
11
+ from kctl_redis import __version__
12
+ from kctl_redis.commands.backup import app as backup_app
13
+ from kctl_redis.commands.clients import app as clients_app
14
+ from kctl_redis.commands.config_cmd import app as config_app
15
+ from kctl_redis.commands.dashboard import app as dashboard_app
16
+ from kctl_redis.commands.db import app as db_app
17
+ from kctl_redis.commands.health import app as health_app
18
+ from kctl_redis.commands.keys import app as keys_app
19
+ from kctl_redis.commands.maintenance import app as maintenance_app
20
+ from kctl_redis.commands.memory import app as memory_app
21
+ from kctl_redis.commands.performance import app as performance_app
22
+ from kctl_redis.commands.persistence import app as persistence_app
23
+ from kctl_redis.commands.pubsub import app as pubsub_app
24
+ from kctl_redis.commands.query import app as query_app
25
+ from kctl_redis.commands.replication import app as replication_app
26
+ from kctl_redis.commands.server import app as server_app
27
+ from kctl_redis.commands.streams import app as streams_app
28
+ from kctl_redis.commands.skill_cmd import app as skill_app
29
+ from kctl_redis.commands.doctor_cmd import app as doctor_app
30
+ from kctl_redis.core.callbacks import AppContext
31
+ from kctl_redis.core.exceptions import KctlError
32
+ from kctl_lib.self_update import notify_if_outdated
33
+ from kctl_lib.tui import add_tui_command
34
+
35
+
36
+ def version_callback(value: bool) -> None:
37
+ if value:
38
+ typer.echo(f"kctl-redis {__version__}")
39
+ raise typer.Exit()
40
+
41
+
42
+ app = typer.Typer(
43
+ name="kctl-redis",
44
+ help="Kodemeio Redis CLI - manage Redis servers via SSH tunnel.",
45
+ no_args_is_help=True,
46
+ rich_markup_mode="rich",
47
+ pretty_exceptions_enable=False,
48
+ )
49
+
50
+
51
+ @app.callback()
52
+ def main(
53
+ ctx: typer.Context,
54
+ json_output: Annotated[bool, typer.Option("--json", help="Output as JSON")] = False,
55
+ quiet: Annotated[bool, typer.Option("--quiet", "-q", help="Suppress info messages")] = False,
56
+ profile: Annotated[str | None, typer.Option("--profile", "-p", help="Config profile name")] = None,
57
+ host: Annotated[str | None, typer.Option("--host", "-H", help="Redis host override")] = None,
58
+ port: Annotated[int | None, typer.Option("--port", help="Redis port override")] = None,
59
+ user: Annotated[str | None, typer.Option("--user", "-U", help="Redis username override")] = None,
60
+ password: Annotated[str | None, typer.Option("--password", help="Redis password override")] = None,
61
+ db: Annotated[int | None, typer.Option("--db", help="Redis database number override")] = None,
62
+ version: Annotated[
63
+ bool, typer.Option("--version", "-V", callback=version_callback, is_eager=True, help="Show version")
64
+ ] = False,
65
+ ) -> None:
66
+ """Kodemeio Redis CLI."""
67
+ ctx.ensure_object(dict)
68
+ ctx.obj = AppContext(
69
+ json_mode=json_output,
70
+ quiet=quiet,
71
+ profile=profile,
72
+ host_override=host,
73
+ port_override=port,
74
+ user_override=user,
75
+ password_override=password,
76
+ db_override=db,
77
+ )
78
+ notify_if_outdated(ctx.obj.output, "kctl-redis", __version__)
79
+
80
+
81
+ # Register all command groups
82
+ app.add_typer(config_app, name="config")
83
+ app.add_typer(health_app, name="health")
84
+ app.add_typer(dashboard_app, name="dashboard")
85
+ app.add_typer(query_app, name="query")
86
+ app.add_typer(keys_app, name="keys")
87
+ app.add_typer(db_app, name="db")
88
+ app.add_typer(memory_app, name="memory")
89
+ app.add_typer(clients_app, name="clients")
90
+ app.add_typer(server_app, name="server")
91
+ app.add_typer(persistence_app, name="persistence")
92
+ app.add_typer(replication_app, name="replication")
93
+ app.add_typer(pubsub_app, name="pubsub")
94
+ app.add_typer(streams_app, name="streams")
95
+ app.add_typer(performance_app, name="performance")
96
+ app.add_typer(backup_app, name="backup")
97
+ app.add_typer(maintenance_app, name="maintenance")
98
+ app.add_typer(skill_app, name="skill", hidden=True)
99
+ app.add_typer(doctor_app, name="doctor")
100
+ add_tui_command(app, service_key="redis", version=__version__)
101
+
102
+
103
+ @app.command("self-update")
104
+ def self_update_cmd(ctx: typer.Context) -> None:
105
+ """Check for updates and upgrade kctl-redis."""
106
+ actx = ctx.obj
107
+ out = actx.output
108
+
109
+ from kctl_lib.self_update import check_update
110
+ from kctl_lib.self_update import update as do_update
111
+
112
+ latest = check_update("kctl-redis", __version__)
113
+ if latest:
114
+ out.info(f"Updating to {latest}...")
115
+ do_update("kctl-redis")
116
+ out.success(f"Updated to {latest}")
117
+ else:
118
+ out.success("Already up to date")
119
+
120
+
121
+ @app.command()
122
+ def completions(
123
+ shell: Annotated[str, typer.Argument(help="Shell type: zsh, bash, fish")] = "zsh",
124
+ install: Annotated[bool, typer.Option("--install", help="Install completions")] = False,
125
+ ) -> None:
126
+ """Generate or install shell completions."""
127
+ from kctl_lib.completions import get_completion_script, install_completions
128
+
129
+ if install:
130
+ path = install_completions("kctl-redis", shell)
131
+ if path:
132
+ typer.echo(f"Completions installed to {path}")
133
+ else:
134
+ typer.echo(f"Could not install completions for {shell}", err=True)
135
+ raise typer.Exit(code=1)
136
+ else:
137
+ script = get_completion_script("kctl-redis", shell)
138
+ typer.echo(script)
139
+
140
+
141
+ # Wrap app so KctlError subclasses surface as clean user-facing messages.
142
+ app = cli_entrypoint(app)
143
+ register_introspection_commands(app)
144
+
145
+ def _run() -> None:
146
+ """Entry point with error handling."""
147
+ try:
148
+ app()
149
+ except KctlError as e:
150
+ handle_cli_error(e)
151
+
152
+
153
+ if __name__ == "__main__":
154
+ _run()
File without changes