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 clean help].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of CLI.



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

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

Class Method Details

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



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

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

Instance Method Details

#run(argv) ⇒ Object



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

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 "clean"  then cmd_clean
  when "help", "--help", "-h" then cmd_help
  else
    @stderr.puts "Unknown command: #{command}"
    cmd_help
    1
  end
end