Class: Flydata::Cli

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

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Cli

Returns a new instance of Cli.



3
4
5
# File 'lib/flydata/cli.rb', line 3

def initialize(args)
  @args = args
end

Instance Method Details

#runObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/flydata/cli.rb', line 7

def run
  begin
    if @args.size > 0
      first_arg = @args.shift
      cmd, sub_cmd = parse_command(first_arg)
      cmd_cls = "Flydata::Command::#{cmd.capitalize}".constantize
      cmd_obj = cmd_cls.new
      sub_cmd ? cmd_obj.send(sub_cmd) : cmd_obj.run
    else
      raise 'no command given'
    end
  rescue => e
    #raise e
    puts "! #{e.to_s}"
    puts
    print_usage
  end
end