Class: Cliffy::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/cliffy/api.rb

Instance Method Summary collapse

Constructor Details

#initialize(commands, arguments, help_points, abort_method, puts_method) ⇒ Service

Returns a new instance of Service.



11
12
13
14
15
16
17
# File 'lib/cliffy/api.rb', line 11

def initialize commands, arguments, help_points, abort_method, puts_method
  @commands = commands
  @arguments = arguments
  @help_points = help_points
  @abort_method = abort_method
  @puts_method = puts_method
end

Instance Method Details

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cliffy/api.rb', line 19

def run
  begin
    validate_commands
    if @arguments.empty?
      show_usage
    elsif @arguments.first == 'help'
      show_help
    else
      run_command
    end
  rescue => e
    @abort_method.call e.to_s
  end
  nil
end