Class: RailsWayback::CLI

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

Overview

Small CLI powering the rails-wayback executable.

rails-wayback on      # enable the engine in the host app
rails-wayback off     # disable it
rails-wayback status  # print current state
rails-wayback clean   # remove the ref cache under tmp/

Constant Summary collapse

COMMANDS =
%w[on off status cache prune clean doctor help].freeze
DOCTOR_LABELS =
{ ok: "OK", warning: "WARN", error: "ERROR" }.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout: $stdout, stderr: $stderr) ⇒ CLI

Returns a new instance of CLI.



20
21
22
23
# File 'lib/rails_wayback/cli.rb', line 20

def initialize(stdout: $stdout, stderr: $stderr)
  @stdout = stdout
  @stderr = stderr
end

Class Method Details

.start(argv, stdout: $stdout, stderr: $stderr) ⇒ Object



16
17
18
# File 'lib/rails_wayback/cli.rb', line 16

def self.start(argv, stdout: $stdout, stderr: $stderr)
  new(stdout: stdout, stderr: stderr).run(argv)
end

Instance Method Details

#run(argv) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rails_wayback/cli.rb', line 25

def run(argv)
  command = (argv.first || "help").to_s
  case command
  when "on"     then cmd_on
  when "off"    then cmd_off
  when "status" then cmd_status
  when "cache"  then cmd_cache
  when "prune"  then cmd_prune
  when "clean"  then cmd_clean
  when "doctor" then cmd_doctor
  when "help", "--help", "-h" then cmd_help
  else
    @stderr.puts "Unknown command: #{command}"
    cmd_help
    1
  end
end