mudis-cli 0.1.0
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.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +76 -0
- data/bin/mudis +6 -0
- data/lib/mudis/cli/runner.rb +454 -0
- data/lib/mudis/cli/version.rb +7 -0
- data/lib/mudis/cli.rb +11 -0
- data/sig/mudis/cli/runner.rbs +40 -0
- data/sig/mudis/cli.rbs +9 -0
- metadata +118 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 5fb70c45a76d4ba85610a896b51c40a51953f1026370eb8108115b14f5469eff
|
|
4
|
+
data.tar.gz: ca7ebbf3dad48c107231e544f9ce3cc593f1ebcfacd068d05b36f4dbe8467b5a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: cca5bbb33145be264050db3838445a04c9e00093b124f1fb7d865ea5a478e7c910ef4c519e41314ca2a1c04fe35f394ab5ac62aadd8ee5d9ac0c45fc1300e960
|
|
7
|
+
data.tar.gz: d19759346f44ee4141141c9e57ccc0fe34cf35fe21410dc212a714d656af723a1f90df235d4ceef95925a7e2a167e655e958914631fd4e951531ffbd5b9356c7
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
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.
|
data/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Mudis CLI
|
|
2
|
+
|
|
3
|
+
CLI utilities for Mudis development and runtime debugging. The CLI loads your application environment, attaches to the `Mudis` entry point, and provides a small set of commands for inspection and mutation.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bundle add mudis-cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Load a Rails app and list keys:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
mudis -r ./config/environment.rb keys
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Read a key:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
mudis -r ./config/environment.rb get user:42
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Write a key with TTL:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
mudis -r ./config/environment.rb set --ttl 60 user:42 '{"name":"Ada"}' --json
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Run a Mudis-QL expression:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
mudis -r ./config/environment.rb ql "from('users').where(id: 42).first"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Start a REPL with helpers:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
mudis -r ./config/environment.rb repl
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Commands
|
|
44
|
+
|
|
45
|
+
- `keys [--namespace NS]`
|
|
46
|
+
- `get [--namespace NS] [--raw] KEY`
|
|
47
|
+
- `set [--namespace NS] [--ttl SECONDS] [--json] KEY VALUE`
|
|
48
|
+
- `del [--namespace NS] KEY`
|
|
49
|
+
- `clear-namespace NAMESPACE`
|
|
50
|
+
- `metrics`
|
|
51
|
+
- `reset`
|
|
52
|
+
- `reset-metrics`
|
|
53
|
+
- `least-touched`
|
|
54
|
+
- `ql 'EXPR'`
|
|
55
|
+
- `repl`
|
|
56
|
+
|
|
57
|
+
## Global Options
|
|
58
|
+
|
|
59
|
+
- `-r, --require PATH` Require a file before running (repeatable).
|
|
60
|
+
- `-e, --env NAME` Set `RACK_ENV` / `RAILS_ENV` before requiring files.
|
|
61
|
+
- `--const NAME` Constant name for Mudis entry point (default: `Mudis`).
|
|
62
|
+
- `--format FORMAT` Output format: `text` or `json`.
|
|
63
|
+
- `--[no-]color` Enable/disable colored output (default: auto). Respects `NO_COLOR`.
|
|
64
|
+
- `--verbose` Show stacktraces on errors.
|
|
65
|
+
|
|
66
|
+
## Notes
|
|
67
|
+
|
|
68
|
+
- The CLI defaults to the `Mudis` constant. Use `--const` if your app exposes a different entry point.
|
|
69
|
+
- `ql` and `repl` depend on `mudis-ql` and will fail if it is not installed.
|
|
70
|
+
- `ql` evaluates the expression with `mudis` and `ql` variables in scope (`ql` points to `MudisQL`).
|
|
71
|
+
|
|
72
|
+
## Development
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
bundle exec ruby -I lib bin/mudis --help
|
|
76
|
+
```
|
data/bin/mudis
ADDED
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "optparse"
|
|
5
|
+
|
|
6
|
+
require "mudis/cli/version"
|
|
7
|
+
|
|
8
|
+
class Mudis
|
|
9
|
+
module CLI
|
|
10
|
+
class Runner
|
|
11
|
+
DEFAULT_CONST = "Mudis"
|
|
12
|
+
|
|
13
|
+
def initialize(argv, out: $stdout, err: $stderr)
|
|
14
|
+
@argv = argv.dup
|
|
15
|
+
@out = out
|
|
16
|
+
@err = err
|
|
17
|
+
@requires = []
|
|
18
|
+
@env = nil
|
|
19
|
+
@const_name = DEFAULT_CONST
|
|
20
|
+
@format = "text"
|
|
21
|
+
@color = true
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def call
|
|
25
|
+
parse_global_options!
|
|
26
|
+
|
|
27
|
+
if @show_version
|
|
28
|
+
@out.puts(VERSION)
|
|
29
|
+
return 0
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
command = @argv.shift
|
|
33
|
+
return help(0) if @show_help || command.nil? || command == "help"
|
|
34
|
+
|
|
35
|
+
load_environment!
|
|
36
|
+
|
|
37
|
+
case command
|
|
38
|
+
when "keys"
|
|
39
|
+
run_keys(@argv)
|
|
40
|
+
when "get"
|
|
41
|
+
run_get(@argv)
|
|
42
|
+
when "set"
|
|
43
|
+
run_set(@argv)
|
|
44
|
+
when "del", "delete"
|
|
45
|
+
run_delete(@argv)
|
|
46
|
+
when "clear-namespace"
|
|
47
|
+
run_clear_namespace(@argv)
|
|
48
|
+
when "metrics"
|
|
49
|
+
run_metrics(@argv)
|
|
50
|
+
when "reset"
|
|
51
|
+
run_reset(@argv)
|
|
52
|
+
when "reset-metrics"
|
|
53
|
+
run_reset_metrics(@argv)
|
|
54
|
+
when "least-touched"
|
|
55
|
+
run_least_touched(@argv)
|
|
56
|
+
when "ql"
|
|
57
|
+
run_ql(@argv)
|
|
58
|
+
when "repl"
|
|
59
|
+
run_repl(@argv)
|
|
60
|
+
else
|
|
61
|
+
@err.puts("Unknown command: #{command}")
|
|
62
|
+
help(1)
|
|
63
|
+
end
|
|
64
|
+
rescue OptionParser::ParseError => e
|
|
65
|
+
@err.puts(e.message)
|
|
66
|
+
help(1)
|
|
67
|
+
rescue LoadError => e
|
|
68
|
+
@err.puts("Load error: #{e.message}")
|
|
69
|
+
@err.puts("Tip: ensure required gems are installed and --require points at your app environment.")
|
|
70
|
+
1
|
|
71
|
+
rescue StandardError => e
|
|
72
|
+
@err.puts("Error: #{e.class}: #{e.message}")
|
|
73
|
+
@err.puts(e.backtrace.first(5).join("\n")) if @verbose
|
|
74
|
+
1
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
private
|
|
78
|
+
|
|
79
|
+
def parse_global_options!
|
|
80
|
+
OptionParser.new do |opts|
|
|
81
|
+
opts.banner = "Usage: mudis [global options] <command> [command options]"
|
|
82
|
+
opts.on("-r", "--require PATH", "Require file before running command (repeatable)") do |value|
|
|
83
|
+
@requires << value
|
|
84
|
+
end
|
|
85
|
+
opts.on("-e", "--env NAME", "Set RACK_ENV/RAILS_ENV before requiring files") do |value|
|
|
86
|
+
@env = value
|
|
87
|
+
end
|
|
88
|
+
opts.on("--const NAME", "Constant name for Mudis entry point (default: #{DEFAULT_CONST})") do |value|
|
|
89
|
+
@const_name = value
|
|
90
|
+
end
|
|
91
|
+
opts.on("--format FORMAT", "Output format: text|json (default: text)") do |value|
|
|
92
|
+
@format = value
|
|
93
|
+
end
|
|
94
|
+
opts.on("--[no-]color", "Enable/disable colored output (default: auto)") do |value|
|
|
95
|
+
@color = value
|
|
96
|
+
end
|
|
97
|
+
opts.on("--verbose", "Show stacktraces on errors") do
|
|
98
|
+
@verbose = true
|
|
99
|
+
end
|
|
100
|
+
opts.on("-h", "--help", "Show help") do
|
|
101
|
+
@show_help = true
|
|
102
|
+
end
|
|
103
|
+
opts.on("--version", "Show version") do
|
|
104
|
+
@show_version = true
|
|
105
|
+
end
|
|
106
|
+
end.order!(@argv)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def load_environment!
|
|
110
|
+
if @env
|
|
111
|
+
ENV["RACK_ENV"] = @env
|
|
112
|
+
ENV["RAILS_ENV"] = @env
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
require "mudis"
|
|
116
|
+
@requires.each { |path| require path }
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def mudis_constant
|
|
120
|
+
Object.const_get(@const_name)
|
|
121
|
+
rescue NameError
|
|
122
|
+
raise NameError, "Could not resolve constant #{@const_name}. Use --const to specify the Mudis entry point."
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def run_keys(argv)
|
|
126
|
+
namespace = nil
|
|
127
|
+
OptionParser.new do |opts|
|
|
128
|
+
opts.banner = "Usage: mudis keys [--namespace NS]"
|
|
129
|
+
opts.on("--namespace NS", "Namespace to filter") { |value| namespace = value }
|
|
130
|
+
end.parse!(argv)
|
|
131
|
+
|
|
132
|
+
mudis = mudis_constant
|
|
133
|
+
unless mudis.respond_to?(:keys)
|
|
134
|
+
error("Mudis does not expose .keys. Available methods: #{mudis.methods(false).sort.join(", ")}")
|
|
135
|
+
return 1
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
result = namespace ? mudis.keys(namespace: namespace) : mudis.keys
|
|
139
|
+
print_output(result)
|
|
140
|
+
0
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def run_get(argv)
|
|
144
|
+
namespace = nil
|
|
145
|
+
raw = false
|
|
146
|
+
OptionParser.new do |opts|
|
|
147
|
+
opts.banner = "Usage: mudis get [--namespace NS] [--raw] KEY"
|
|
148
|
+
opts.on("--namespace NS", "Namespace to read from") { |value| namespace = value }
|
|
149
|
+
opts.on("--raw", "Print raw value without formatting") { raw = true }
|
|
150
|
+
end.parse!(argv)
|
|
151
|
+
|
|
152
|
+
key = argv.shift
|
|
153
|
+
return usage_error("Missing key", "mudis get [--namespace NS] [--raw] KEY") unless key
|
|
154
|
+
|
|
155
|
+
mudis = mudis_constant
|
|
156
|
+
reader = if mudis.respond_to?(:read)
|
|
157
|
+
:read
|
|
158
|
+
elsif mudis.respond_to?(:get)
|
|
159
|
+
:get
|
|
160
|
+
else
|
|
161
|
+
error("Mudis does not expose .read or .get")
|
|
162
|
+
return 1
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
value = if namespace
|
|
166
|
+
mudis.public_send(reader, key, namespace: namespace)
|
|
167
|
+
else
|
|
168
|
+
mudis.public_send(reader, key)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
raw ? @out.puts(value) : print_output(value)
|
|
172
|
+
0
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def run_set(argv)
|
|
176
|
+
namespace = nil
|
|
177
|
+
ttl = nil
|
|
178
|
+
parse_json = false
|
|
179
|
+
OptionParser.new do |opts|
|
|
180
|
+
opts.banner = "Usage: mudis set [--namespace NS] [--ttl SECONDS] [--json] KEY VALUE"
|
|
181
|
+
opts.on("--namespace NS", "Namespace to write to") { |value| namespace = value }
|
|
182
|
+
opts.on("--ttl SECONDS", Integer, "Expiration in seconds") { |value| ttl = value }
|
|
183
|
+
opts.on("--json", "Parse VALUE as JSON") { parse_json = true }
|
|
184
|
+
end.parse!(argv)
|
|
185
|
+
|
|
186
|
+
key = argv.shift
|
|
187
|
+
value = argv.shift
|
|
188
|
+
return usage_error("Missing key/value", "mudis set [--namespace NS] [--ttl SECONDS] [--json] KEY VALUE") unless key && value
|
|
189
|
+
|
|
190
|
+
if parse_json
|
|
191
|
+
begin
|
|
192
|
+
value = JSON.parse(value)
|
|
193
|
+
rescue JSON::ParserError => e
|
|
194
|
+
error("Invalid JSON: #{e.message}")
|
|
195
|
+
return 1
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
mudis = mudis_constant
|
|
200
|
+
writer = if mudis.respond_to?(:write)
|
|
201
|
+
:write
|
|
202
|
+
elsif mudis.respond_to?(:set)
|
|
203
|
+
:set
|
|
204
|
+
else
|
|
205
|
+
error("Mudis does not expose .write or .set")
|
|
206
|
+
return 1
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
args = [key, value]
|
|
210
|
+
kwargs = {}
|
|
211
|
+
kwargs[:namespace] = namespace if namespace
|
|
212
|
+
kwargs[:expires_in] = ttl if ttl
|
|
213
|
+
|
|
214
|
+
mudis.public_send(writer, *args, **kwargs)
|
|
215
|
+
success("OK")
|
|
216
|
+
0
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
def run_delete(argv)
|
|
220
|
+
namespace = nil
|
|
221
|
+
OptionParser.new do |opts|
|
|
222
|
+
opts.banner = "Usage: mudis del [--namespace NS] KEY"
|
|
223
|
+
opts.on("--namespace NS", "Namespace to delete from") { |value| namespace = value }
|
|
224
|
+
end.parse!(argv)
|
|
225
|
+
|
|
226
|
+
key = argv.shift
|
|
227
|
+
return usage_error("Missing key", "mudis del [--namespace NS] KEY") unless key
|
|
228
|
+
|
|
229
|
+
mudis = mudis_constant
|
|
230
|
+
deleter = if mudis.respond_to?(:delete)
|
|
231
|
+
:delete
|
|
232
|
+
elsif mudis.respond_to?(:del)
|
|
233
|
+
:del
|
|
234
|
+
else
|
|
235
|
+
error("Mudis does not expose .delete or .del")
|
|
236
|
+
return 1
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
result = namespace ? mudis.public_send(deleter, key, namespace: namespace) : mudis.public_send(deleter, key)
|
|
240
|
+
print_output(result)
|
|
241
|
+
0
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def run_clear_namespace(argv)
|
|
245
|
+
OptionParser.new do |opts|
|
|
246
|
+
opts.banner = "Usage: mudis clear-namespace NAMESPACE"
|
|
247
|
+
end.parse!(argv)
|
|
248
|
+
|
|
249
|
+
namespace = argv.shift
|
|
250
|
+
return usage_error("Missing namespace", "mudis clear-namespace NAMESPACE") unless namespace
|
|
251
|
+
|
|
252
|
+
mudis = mudis_constant
|
|
253
|
+
unless mudis.respond_to?(:clear_namespace)
|
|
254
|
+
error("Mudis does not expose .clear_namespace")
|
|
255
|
+
return 1
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
begin
|
|
259
|
+
result = mudis.clear_namespace(namespace: namespace)
|
|
260
|
+
rescue ArgumentError
|
|
261
|
+
result = mudis.clear_namespace(namespace)
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
print_output(result)
|
|
265
|
+
0
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
def run_metrics(_argv)
|
|
269
|
+
mudis = mudis_constant
|
|
270
|
+
unless mudis.respond_to?(:metrics)
|
|
271
|
+
error("Mudis does not expose .metrics")
|
|
272
|
+
return 1
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
result = mudis.metrics
|
|
276
|
+
print_output(result)
|
|
277
|
+
0
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
def run_reset(_argv)
|
|
281
|
+
mudis = mudis_constant
|
|
282
|
+
unless mudis.respond_to?(:reset!)
|
|
283
|
+
error("Mudis does not expose .reset!")
|
|
284
|
+
return 1
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
mudis.reset!
|
|
288
|
+
success("OK")
|
|
289
|
+
0
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
def run_reset_metrics(_argv)
|
|
293
|
+
mudis = mudis_constant
|
|
294
|
+
unless mudis.respond_to?(:reset_metrics!)
|
|
295
|
+
error("Mudis does not expose .reset_metrics!")
|
|
296
|
+
return 1
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
mudis.reset_metrics!
|
|
300
|
+
success("OK")
|
|
301
|
+
0
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
def run_least_touched(_argv)
|
|
305
|
+
mudis = mudis_constant
|
|
306
|
+
unless mudis.respond_to?(:least_touched)
|
|
307
|
+
error("Mudis does not expose .least_touched")
|
|
308
|
+
return 1
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
result = mudis.least_touched
|
|
312
|
+
print_output(result)
|
|
313
|
+
0
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
def run_ql(argv)
|
|
317
|
+
OptionParser.new do |opts|
|
|
318
|
+
opts.banner = "Usage: mudis ql 'EXPR'"
|
|
319
|
+
end.parse!(argv)
|
|
320
|
+
|
|
321
|
+
expr = argv.join(" ")
|
|
322
|
+
return usage_error("Missing expression", "mudis ql 'EXPR'") if expr.empty?
|
|
323
|
+
|
|
324
|
+
require "mudis_ql"
|
|
325
|
+
|
|
326
|
+
mudis = mudis_constant
|
|
327
|
+
ql = MudisQL
|
|
328
|
+
result = eval(expr, binding, __FILE__, __LINE__)
|
|
329
|
+
print_output(result)
|
|
330
|
+
0
|
|
331
|
+
rescue LoadError
|
|
332
|
+
error("mudis-ql is not available. Add it to your bundle or install the gem.")
|
|
333
|
+
1
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
def run_repl(_argv)
|
|
337
|
+
require "irb"
|
|
338
|
+
require "mudis_ql"
|
|
339
|
+
|
|
340
|
+
mudis = mudis_constant
|
|
341
|
+
@out.puts("Mudis CLI REPL. Helper vars: mudis, ql")
|
|
342
|
+
ql = MudisQL
|
|
343
|
+
|
|
344
|
+
IRB.setup(nil)
|
|
345
|
+
workspace = IRB::WorkSpace.new(binding)
|
|
346
|
+
irb = IRB::Irb.new(workspace)
|
|
347
|
+
IRB.conf[:MAIN_CONTEXT] = irb.context
|
|
348
|
+
catch(:IRB_EXIT) { irb.eval_input }
|
|
349
|
+
0
|
|
350
|
+
rescue LoadError
|
|
351
|
+
error("mudis-ql is not available. Add it to your bundle or install the gem.")
|
|
352
|
+
1
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
def print_output(value)
|
|
356
|
+
if @format == "json"
|
|
357
|
+
payload = if value.is_a?(Array) || value.is_a?(Hash)
|
|
358
|
+
value
|
|
359
|
+
elsif value.respond_to?(:as_json)
|
|
360
|
+
value.as_json
|
|
361
|
+
elsif value.respond_to?(:to_h)
|
|
362
|
+
value.to_h
|
|
363
|
+
else
|
|
364
|
+
value
|
|
365
|
+
end
|
|
366
|
+
begin
|
|
367
|
+
@out.puts(JSON.pretty_generate(payload))
|
|
368
|
+
rescue JSON::GeneratorError
|
|
369
|
+
@out.puts(JSON.pretty_generate(payload.to_s))
|
|
370
|
+
end
|
|
371
|
+
else
|
|
372
|
+
case value
|
|
373
|
+
when Array
|
|
374
|
+
value.each { |item| @out.puts(item) }
|
|
375
|
+
when Hash
|
|
376
|
+
value.each { |k, v| @out.puts("#{k}: #{v}") }
|
|
377
|
+
else
|
|
378
|
+
@out.puts(value.inspect)
|
|
379
|
+
end
|
|
380
|
+
end
|
|
381
|
+
end
|
|
382
|
+
|
|
383
|
+
def usage_error(message, usage)
|
|
384
|
+
error(message)
|
|
385
|
+
warn_line("Usage: #{usage}")
|
|
386
|
+
1
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
def help(code)
|
|
390
|
+
@out.puts <<~HELP
|
|
391
|
+
Mudis CLI
|
|
392
|
+
|
|
393
|
+
Usage:
|
|
394
|
+
mudis [global options] <command> [command options]
|
|
395
|
+
|
|
396
|
+
Global options:
|
|
397
|
+
-r, --require PATH Require a file before running (repeatable)
|
|
398
|
+
-e, --env NAME Set RACK_ENV/RAILS_ENV before requiring files
|
|
399
|
+
--const NAME Mudis constant name (default: Mudis)
|
|
400
|
+
--format FORMAT Output format: text|json
|
|
401
|
+
--[no-]color Enable/disable colored output (default: auto)
|
|
402
|
+
--verbose Show stacktraces on errors
|
|
403
|
+
--version Show version
|
|
404
|
+
-h, --help Show help
|
|
405
|
+
|
|
406
|
+
Commands:
|
|
407
|
+
keys [--namespace NS]
|
|
408
|
+
get [--namespace NS] [--raw] KEY
|
|
409
|
+
set [--namespace NS] [--ttl SECONDS] [--json] KEY VALUE
|
|
410
|
+
del [--namespace NS] KEY
|
|
411
|
+
clear-namespace NAMESPACE
|
|
412
|
+
metrics
|
|
413
|
+
reset
|
|
414
|
+
reset-metrics
|
|
415
|
+
least-touched
|
|
416
|
+
ql 'EXPR'
|
|
417
|
+
repl
|
|
418
|
+
HELP
|
|
419
|
+
code
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
def color_enabled?(io)
|
|
423
|
+
return false unless @color
|
|
424
|
+
return false if ENV["NO_COLOR"]
|
|
425
|
+
io.respond_to?(:tty?) && io.tty?
|
|
426
|
+
end
|
|
427
|
+
|
|
428
|
+
def colorize(io, text, code)
|
|
429
|
+
return text unless color_enabled?(io)
|
|
430
|
+
"\e[#{code}m#{text}\e[0m"
|
|
431
|
+
end
|
|
432
|
+
|
|
433
|
+
def info(message)
|
|
434
|
+
@out.puts(colorize(@out, message, 36))
|
|
435
|
+
end
|
|
436
|
+
|
|
437
|
+
def success(message)
|
|
438
|
+
@out.puts(colorize(@out, message, 32))
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
def debug(message)
|
|
442
|
+
@out.puts(colorize(@out, message, 90))
|
|
443
|
+
end
|
|
444
|
+
|
|
445
|
+
def warn_line(message)
|
|
446
|
+
@err.puts(colorize(@err, message, 33))
|
|
447
|
+
end
|
|
448
|
+
|
|
449
|
+
def error(message)
|
|
450
|
+
@err.puts(colorize(@err, message, 31))
|
|
451
|
+
end
|
|
452
|
+
end
|
|
453
|
+
end
|
|
454
|
+
end
|
data/lib/mudis/cli.rb
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# RBS for Mudis::CLI::Runner
|
|
2
|
+
|
|
3
|
+
module Mudis
|
|
4
|
+
module CLI
|
|
5
|
+
class Runner
|
|
6
|
+
def initialize: (Array[String], out: IO, err: IO) -> void
|
|
7
|
+
def call: () -> Integer
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
def parse_global_options!: () -> void
|
|
12
|
+
def load_environment!: () -> void
|
|
13
|
+
def mudis_constant: () -> untyped
|
|
14
|
+
|
|
15
|
+
def run_keys: (Array[String]) -> Integer
|
|
16
|
+
def run_get: (Array[String]) -> Integer
|
|
17
|
+
def run_set: (Array[String]) -> Integer
|
|
18
|
+
def run_delete: (Array[String]) -> Integer
|
|
19
|
+
def run_clear_namespace: (Array[String]) -> Integer
|
|
20
|
+
def run_metrics: (Array[String]) -> Integer
|
|
21
|
+
def run_reset: (Array[String]) -> Integer
|
|
22
|
+
def run_reset_metrics: (Array[String]) -> Integer
|
|
23
|
+
def run_least_touched: (Array[String]) -> Integer
|
|
24
|
+
def run_ql: (Array[String]) -> Integer
|
|
25
|
+
def run_repl: (Array[String]) -> Integer
|
|
26
|
+
|
|
27
|
+
def print_output: (untyped) -> void
|
|
28
|
+
def usage_error: (String, String) -> Integer
|
|
29
|
+
def help: (Integer) -> Integer
|
|
30
|
+
|
|
31
|
+
def color_enabled?: (IO) -> bool
|
|
32
|
+
def colorize: (IO, String, String) -> String
|
|
33
|
+
def info: (String) -> void
|
|
34
|
+
def success: (String) -> void
|
|
35
|
+
def debug: (String) -> void
|
|
36
|
+
def warn_line: (String) -> void
|
|
37
|
+
def error: (String) -> void
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
data/sig/mudis/cli.rbs
ADDED
metadata
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: mudis-cli
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- kiebor81
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 2026-02-08 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: mudis
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0.9'
|
|
19
|
+
- - ">="
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: 0.9.4
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - "~>"
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: '0.9'
|
|
29
|
+
- - ">="
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: 0.9.4
|
|
32
|
+
- !ruby/object:Gem::Dependency
|
|
33
|
+
name: mudis-ql
|
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - "~>"
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0.2'
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: 0.2.1
|
|
42
|
+
type: :runtime
|
|
43
|
+
prerelease: false
|
|
44
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - "~>"
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '0.2'
|
|
49
|
+
- - ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: 0.2.1
|
|
52
|
+
- !ruby/object:Gem::Dependency
|
|
53
|
+
name: rspec
|
|
54
|
+
requirement: !ruby/object:Gem::Requirement
|
|
55
|
+
requirements:
|
|
56
|
+
- - "~>"
|
|
57
|
+
- !ruby/object:Gem::Version
|
|
58
|
+
version: '3.12'
|
|
59
|
+
type: :development
|
|
60
|
+
prerelease: false
|
|
61
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
62
|
+
requirements:
|
|
63
|
+
- - "~>"
|
|
64
|
+
- !ruby/object:Gem::Version
|
|
65
|
+
version: '3.12'
|
|
66
|
+
- !ruby/object:Gem::Dependency
|
|
67
|
+
name: simplecov
|
|
68
|
+
requirement: !ruby/object:Gem::Requirement
|
|
69
|
+
requirements:
|
|
70
|
+
- - "~>"
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
version: '0.22'
|
|
73
|
+
type: :development
|
|
74
|
+
prerelease: false
|
|
75
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
76
|
+
requirements:
|
|
77
|
+
- - "~>"
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: '0.22'
|
|
80
|
+
description: Command line utilities for inspecting and debugging Mudis caches, with
|
|
81
|
+
optional Mudis-QL support.
|
|
82
|
+
email:
|
|
83
|
+
- ''
|
|
84
|
+
executables:
|
|
85
|
+
- mudis
|
|
86
|
+
extensions: []
|
|
87
|
+
extra_rdoc_files: []
|
|
88
|
+
files:
|
|
89
|
+
- LICENSE.txt
|
|
90
|
+
- README.md
|
|
91
|
+
- bin/mudis
|
|
92
|
+
- lib/mudis/cli.rb
|
|
93
|
+
- lib/mudis/cli/runner.rb
|
|
94
|
+
- lib/mudis/cli/version.rb
|
|
95
|
+
- sig/mudis/cli.rbs
|
|
96
|
+
- sig/mudis/cli/runner.rbs
|
|
97
|
+
homepage: https://github.com/kiebor81/mudis
|
|
98
|
+
licenses:
|
|
99
|
+
- MIT
|
|
100
|
+
metadata: {}
|
|
101
|
+
rdoc_options: []
|
|
102
|
+
require_paths:
|
|
103
|
+
- lib
|
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
|
+
requirements:
|
|
106
|
+
- - ">="
|
|
107
|
+
- !ruby/object:Gem::Version
|
|
108
|
+
version: '3.0'
|
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
|
+
requirements:
|
|
111
|
+
- - ">="
|
|
112
|
+
- !ruby/object:Gem::Version
|
|
113
|
+
version: '0'
|
|
114
|
+
requirements: []
|
|
115
|
+
rubygems_version: 3.6.2
|
|
116
|
+
specification_version: 4
|
|
117
|
+
summary: CLI utilities for Mudis development and runtime debugging
|
|
118
|
+
test_files: []
|