Class: RubyCms::CLI::ShellRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_cms/cli.rb

Overview

Runs shell commands in the host app root with a compact, fancy status line: a spinner while running, a red check on success (output hidden), or a red cross plus the captured output when a step fails.

Constant Summary collapse

FRAMES =
%w[         ].freeze
LABELS =

Friendly labels per command (matched by substring); falls back to the command.

{
  "bundle install" => "Installing gems",
  "generate authentication" => "Setting up authentication",
  "ruby_ui:install" => "Installing UI components",
  "tailwindcss:install" => "Installing Tailwind",
  "ahoy:install" => "Installing analytics",
  "action_text:install" => "Installing rich text",
  "noticed:install:migrations" => "Installing notifications",
  "db:migrate" => "Running migrations",
  "seed_permissions" => "Seeding permissions",
  "reconcile_migrations" => "Reconciling migrations",
  "tailwindcss:build" => "Building styles"
}.freeze
NOISE =

Noise lines suppressed even on failure (environment chatter, not real errors).

%r{Unresolved or ambiguous specs|Clearing out unresolved|Available/installed versions|already initialized constant|report a bug if this causes|gem cleanup}

Instance Method Summary collapse

Constructor Details

#initialize(thor, app_root) ⇒ ShellRunner

Returns a new instance of ShellRunner.



161
162
163
164
# File 'lib/ruby_cms/cli.rb', line 161

def initialize(thor, app_root)
  @thor = thor
  @app_root = app_root
end

Instance Method Details

#heading(text) ⇒ Object

A bold cyan section header.



190
# File 'lib/ruby_cms/cli.rb', line 190

def heading(text) = @thor.say(@thor.set_color(text, :cyan, :bold))

#ok(label, hint: nil) ⇒ Object

A red ✓ item: bright check, plain label, dimmed hint (e.g. a description).



193
194
195
196
197
# File 'lib/ruby_cms/cli.rb', line 193

def ok(label, hint: nil)
  line = "  #{@thor.set_color('', :red, :bold)} #{label}"
  line += @thor.set_color("#{hint}", :white) if hint
  @thor.say(line)
end

#run(cmd) ⇒ Object

Returns true on success, false on failure (so the Installer can decide whether a failed step is fatal).



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/ruby_cms/cli.rb', line 168

def run(cmd) # rubocop:disable Naming/PredicateMethod
  require "open3"
  label = label_for(cmd)
  done = false
  spinner = spin(label) { done }
  output, status = Open3.capture2e(cmd, chdir: @app_root.to_s)
  done = true
  spinner&.join

  if status.success?
    @thor.say("#{clear}  #{@thor.set_color('', :red, :bold)} #{label}")
    true
  else
    @thor.say("#{clear}  #{@thor.set_color('', :red, :bold)} #{label}")
    @thor.say(@thor.set_color(filter_noise(output), :red))
    false
  end
end

#say(msg, color = nil) ⇒ Object



187
# File 'lib/ruby_cms/cli.rb', line 187

def say(msg, color=nil) = @thor.say(msg, color)