Class: RailsMarkup::Cli
- Inherits:
-
Thor
- Object
- Thor
- RailsMarkup::Cli
show all
- Defined in:
- lib/rails_markup/cli.rb,
lib/rails_markup/cli/base.rb,
lib/rails_markup/cli/setup_wizard.rb,
lib/rails_markup/cli/initializer_writer.rb
Defined Under Namespace
Classes: InitializerWriter, SetupWizard
Constant Summary
collapse
Lipgloss::Style.new.bold(true).foreground("#FFFFFF").background("#5C4AE4").padding(0, 1)
- ODD_STYLE =
Lipgloss::Style.new.foreground("#E2E2E2").padding(0, 1)
- EVEN_STYLE =
Lipgloss::Style.new.foreground("#A0A0A0").padding(0, 1)
- MASKED_STYLE =
Lipgloss::Style.new.foreground("#6B7280").padding(0, 1)
- LABEL_STYLE =
Lipgloss::Style.new.bold(true).foreground("#FFFFFF")
- HINT_STYLE =
Lipgloss::Style.new.foreground("#6B7280")
- SUCCESS_STYLE =
Lipgloss::Style.new.bold(true).foreground("#22C55E")
- ERROR_STYLE =
Lipgloss::Style.new.bold(true).foreground("#EF4444")
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.exit_on_failure? ⇒ Boolean
534
535
536
|
# File 'lib/rails_markup/cli.rb', line 534
def self.exit_on_failure?
true
end
|
Instance Method Details
#acknowledge(id = nil) ⇒ Object
408
409
410
411
412
413
414
415
416
417
418
|
# File 'lib/rails_markup/cli.rb', line 408
def acknowledge(id = nil)
return say("#{ERROR_STYLE.render("Error:")} annotation ID is required") unless id
env = resolve_env(options[:production])
return unless env
result = patch_annotation(env, id, "acknowledge")
return unless result
$stdout.puts "#{SUCCESS_STYLE.render("Acknowledged")} ##{id}"
end
|
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/rails_markup/cli.rb', line 116
def configure
env_updates = McpConfig::ENV_KEYS.each_with_object({}) do |(opt, env_key), hash|
hash[env_key] = options[opt] if options[opt]
end
if env_updates.empty?
say "No options provided. Usage:", :yellow
say ""
say " bin/markup configure --dev-url http://localhost:3000"
say " bin/markup configure --prod-url URL --prod-token TOKEN"
say " bin/markup configure --prod-url URL --global # Claude Code global"
say " bin/markup configure --prod-url URL --codex # Codex CLI global"
say ""
say " Dev needs only a URL (no token). Production requires both."
say ""
say " Or run: bin/markup setup-production --url=https://yourapp.com"
say ""
return
end
config = McpConfig.new(scope: resolve_scope)
config.update_env(env_updates)
$stdout.puts "#{LABEL_STYLE.render("Updated #{config.scope_label}")} #{HINT_STYLE.render("(#{config.path})")}"
$stdout.puts env_table(config.display_env, label: config.scope_label)
end
|
#dismiss(id = nil) ⇒ Object
361
362
363
364
365
366
367
368
369
370
371
|
# File 'lib/rails_markup/cli.rb', line 361
def dismiss(id = nil)
return say("#{ERROR_STYLE.render("Error:")} annotation ID is required") unless id
env = resolve_env(options[:production])
return unless env
result = patch_annotation(env, id, "dismiss", reason: options[:reason])
return unless result
$stdout.puts "#{SUCCESS_STYLE.render("Dismissed")} ##{id}"
end
|
#fetch(env_arg = nil) ⇒ Object
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
|
# File 'lib/rails_markup/cli.rb', line 437
def fetch(env_arg = nil)
production = env_arg == "production" || options[:production] || options[:environment] == "production"
env = resolve_env(production)
return unless env
annotations = fetch_pending_from(env)
return unless annotations
env_label = production ? "Production" : "Development"
$stdout.puts ""
$stdout.puts "#{LABEL_STYLE.render(" #{env_label} ")} #{HINT_STYLE.render(env[:base_url])}"
$stdout.puts ""
if annotations.empty?
say " No pending annotations.", :yellow
say ""
return
end
$stdout.puts annotation_table(annotations)
say ""
annotations.each { |ann| render_annotation(ann) }
end
|
#init ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/rails_markup/cli.rb', line 59
def init
wizard = Cli::SetupWizard.new(dir: Dir.pwd)
Bubbletea.run(wizard)
if wizard.completed
say ""
say "Setup complete!", :green
else
say ""
say "Setup cancelled.", :yellow
end
end
|
#man ⇒ Object
523
524
525
526
|
# File 'lib/rails_markup/cli.rb', line 523
def man
require_relative "version"
$stdout.puts render_man_page
end
|
#mcp ⇒ Object
82
83
84
85
|
# File 'lib/rails_markup/cli.rb', line 82
def mcp
srv = RailsMarkup::Server.new(port: options[:port], mcp_only: true)
srv.start
end
|
#pending ⇒ Object
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
# File 'lib/rails_markup/cli.rb', line 263
def pending
env = resolve_env(options[:production])
return unless env
annotations = fetch_pending_from(env)
return unless annotations
env_label = options[:production] ? "Production" : "Development"
$stdout.puts ""
$stdout.puts "#{LABEL_STYLE.render(" #{env_label} ")} #{HINT_STYLE.render(env[:base_url])}"
$stdout.puts ""
if annotations.empty?
say " No pending annotations.", :yellow
say ""
return
end
$stdout.puts annotation_table(annotations)
say ""
annotations.each { |ann| render_annotation(ann) }
end
|
#reply(id = nil, message = nil) ⇒ Object
384
385
386
387
388
389
390
391
392
393
394
395
|
# File 'lib/rails_markup/cli.rb', line 384
def reply(id = nil, message = nil)
return say("#{ERROR_STYLE.render("Error:")} annotation ID is required") unless id
return say("#{ERROR_STYLE.render("Error:")} message is required") unless message
env = resolve_env(options[:production])
return unless env
result = patch_annotation(env, id, "reply", message: message)
return unless result
$stdout.puts "#{SUCCESS_STYLE.render("Reply sent")} to ##{id}"
end
|
#resolve(id = nil) ⇒ Object
337
338
339
340
341
342
343
344
345
346
347
|
# File 'lib/rails_markup/cli.rb', line 337
def resolve(id = nil)
return say("#{ERROR_STYLE.render("Error:")} annotation ID is required") unless id
env = resolve_env(options[:production])
return unless env
result = patch_annotation(env, id, "resolve", summary: options[:summary])
return unless result
$stdout.puts "#{SUCCESS_STYLE.render("Resolved")} ##{id}"
end
|
#resolve_all ⇒ Object
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
# File 'lib/rails_markup/cli.rb', line 298
def resolve_all
env = resolve_env(options[:production])
return unless env
annotations = fetch_pending_from(env)
return unless annotations
if annotations.empty?
say "No pending annotations.", :yellow
return
end
resolved = 0
annotations.each do |ann|
result = patch_annotation(env, ann["id"], "resolve", summary: options[:summary])
if result
$stdout.puts "#{SUCCESS_STYLE.render("Resolved")} ##{ann["id"]} #{HINT_STYLE.render(ann["content"].to_s[0, 50])}"
resolved += 1
else
$stdout.puts "#{ERROR_STYLE.render("Failed")} ##{ann["id"]}"
end
end
say ""
say "#{resolved}/#{annotations.size} annotations resolved.", :green
end
|
#server ⇒ Object
44
45
46
47
|
# File 'lib/rails_markup/cli.rb', line 44
def server
srv = RailsMarkup::Server.new(port: options[:port], bind: options[:host])
srv.start
end
|
#session(id = nil) ⇒ Object
188
189
190
191
192
193
194
|
# File 'lib/rails_markup/cli.rb', line 188
def session(id = nil)
say "Sessions are only available via MCP tools (in-memory store).", :yellow
say ""
say " Use the rails_markup_session MCP tool in your AI editor."
say ""
say " To view pending annotations: bin/markup pending"
end
|
#sessions ⇒ Object
177
178
179
180
181
182
183
184
185
|
# File 'lib/rails_markup/cli.rb', line 177
def sessions
say "Sessions are only available via MCP tools (in-memory store).", :yellow
say ""
say " Use the rails_markup_sessions MCP tool in your AI editor."
say " The CLI talks to the Rails API which has database-backed annotations,"
say " not session-based ones."
say ""
say " To view pending annotations: bin/markup pending"
end
|
#setup_production ⇒ Object
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
|
# File 'lib/rails_markup/cli.rb', line 477
def setup_production
require "securerandom"
prod_url = options[:url]
unless prod_url
say "Usage: bin/markup setup-production --url=https://yourapp.com", :red
return
end
token = SecureRandom.hex(24)
config = McpConfig.new(scope: resolve_scope)
config.update_env({
"RAILS_MARKUP_PROD_URL" => prod_url,
"RAILS_MARKUP_PROD_TOKEN" => token
})
say ""
say "Production token generated!", :green
say ""
say "Token: #{token}"
say ""
say "Saved to #{config.scope_label} — CLI and MCP tools are ready."
say ""
say "Now add the same token to your Rails app:"
say ""
say " Option A: Rails credentials (recommended)"
say " rails credentials:edit"
say " # Add:"
say " # rails_markup:"
say " # api_token: #{token}"
say ""
say " Option B: Environment variable"
say " RAILS_MARKUP_API_TOKEN=#{token}"
say ""
say "Then in config/initializers/rails_markup.rb:"
say ' config.api_token = Rails.application.credentials.dig(:rails_markup, :api_token)'
say " # or"
say ' config.api_token = ENV["RAILS_MARKUP_API_TOKEN"]'
say ""
say "Deploy, then verify:"
say " bin/markup pending --production"
say ""
end
|
#status ⇒ Object
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/rails_markup/cli.rb', line 149
def status
found = false
McpConfig::SCOPES.each do |scope|
config = McpConfig.new(scope: scope)
next unless config.exist?
env = config.display_env
next if env.empty?
found = true
say ""
$stdout.puts env_table(env, label: config.scope_label)
end
unless found
say ""
say "No MCP config found. Run:", :yellow
say " rails-markup configure --prod-url URL --prod-token TOKEN"
say " rails-markup configure --prod-url URL --global # Claude Code global"
say " rails-markup configure --prod-url URL --codex # Codex CLI global"
end
say ""
end
|
#version ⇒ Object
529
530
531
532
|
# File 'lib/rails_markup/cli.rb', line 529
def version
require_relative "version"
say "rails-markup #{RailsMarkup::VERSION}"
end
|
#watch ⇒ Object
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
# File 'lib/rails_markup/cli.rb', line 214
def watch
env = resolve_env(options[:production])
return unless env
env_label = options[:production] ? "Production" : "Development"
interval = [options[:interval], 1].max
$stdout.puts ""
$stdout.puts "#{LABEL_STYLE.render(" Watching #{env_label} ")} #{HINT_STYLE.render(env[:base_url])}"
$stdout.puts "#{HINT_STYLE.render(" Polling every #{interval}s. Press Ctrl+C to stop.")}"
$stdout.puts ""
seen_ids = Set.new
loop do
annotations = fetch_pending_from(env)
break unless annotations
new_annotations = annotations.reject { |ann| seen_ids.include?(ann["id"]) }
if new_annotations.any?
new_annotations.each do |ann|
seen_ids.add(ann["id"])
render_annotation(ann)
end
$stdout.puts "#{HINT_STYLE.render(" #{seen_ids.size} total seen, #{annotations.size} pending")}"
$stdout.puts ""
end
sleep interval
rescue Interrupt
say ""
say "Stopped watching.", :yellow
break
end
end
|