Class: Specbandit::CLI

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

Constant Summary collapse

COMMANDS =
%w[push work].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



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

def initialize(argv)
  @argv = argv.dup
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



13
14
15
# File 'lib/specbandit/cli.rb', line 13

def argv
  @argv
end

Class Method Details

.run(argv = ARGV) ⇒ Object



9
10
11
# File 'lib/specbandit/cli.rb', line 9

def self.run(argv = ARGV)
  new(argv).execute
end

Instance Method Details

#executeObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/specbandit/cli.rb', line 19

def execute
  command = argv.shift

  case command
  when 'push'
    run_push
  when 'work'
    run_work
  when nil, '-h', '--help'
    print_usage
    0
  when '-v', '--version'
    puts "specbandit #{VERSION}"
    0
  else
    warn "Unknown command: #{command}"
    print_usage
    1
  end
rescue Specbandit::Error => e
  warn "[specbandit] Error: #{e.message}"
  1
rescue Redis::BaseError => e
  warn "[specbandit] Redis error: #{e.message}"
  1
end