Class: Hapyrus::Cli

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/hapyrus/cli.rb

Instance Method Summary collapse

Methods included from Helpers

home_directory, parse_command, to_command_class

Constructor Details

#initialize(args) ⇒ Cli

Returns a new instance of Cli.



5
6
7
# File 'lib/hapyrus/cli.rb', line 5

def initialize(args)
  @args = args
end

Instance Method Details

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/hapyrus/cli.rb', line 9

def run
  begin
    command_class, method = parse_args
    command = command_class.new

    if @args.size > 0
      command.send(ask_for(method), *@args) if command.respond_to?(ask_for method)
      command.send(method, *@args)
      command.send(display(method), *@args) if command.respond_to?(display method)
    else
      command.send(ask_for method) if command.respond_to?(ask_for method)
      command.send(method)
      command.send(display method) if command.respond_to?(display method)
    end
  rescue => e
    #raise e
    puts "! #{e.to_s}"
    puts
    usage
  end
end