Class: TrelloCli::CLI::Run

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

Instance Method Summary collapse

Instance Method Details

#runObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/trello_cli/cli/run.rb', line 4

def run
  target = ARGV.shift
  cmd    = ARGV.shift || 'help'

  case target
  when *targets
    target_object = CLI::Commands.const_get(target.capitalize).new

    cmd = 'help' unless target_object.actions.include?(cmd.to_sym)

    begin
      target_object.send cmd
    rescue OptionParser::InvalidOption, Trello::Error => e
      puts e.message
      exit 1
    rescue NoMethodError => e
      if e.message.match /SocketError/
        puts 'Please connect to the internet to access Trello'
        exit 1
      else
        raise e
      end
    end
  when '-v'
    puts TrelloCli::VERSION
  else
    puts "Unkown target: '#{target}'." unless target == '-h'
    puts "trello [#{targets.join('|')}] [command] OPTIONS"
    puts "Append -h for help on specific target."
  end
end