Method: EntryPoint#execute

Defined in:
lib/toolshed/entry_point.rb

#executeObject



17
18
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/toolshed/entry_point.rb', line 17

def execute
  if $0.split("/").last == 'toolshed'
    options = {}

    # @TODO - clean this up as it should really be part of the command it's being used in not globally.
    global = OptionParser.new do |opts|
      opts.on("-u", "--github-username [ARG]") do |username|
        Toolshed::Client.instance.github_username = username
      end
      opts.on("-p", "--github-password [ARG]") do |password|
        Toolshed::Client.instance.github_password = password
      end
      opts.on("-t", "--github-token [ARG]") do |token|
        Toolshed::Client.instance.github_token = token
      end
      opts.on("-u", "--pivotal-tracker-username [ARG]") do |username|
        Toolshed::Client.instance.pivotal_tracker_username = username
      end
      opts.on("-p", "--pivotal-tracker-password [ARG]") do |password|
        Toolshed::Client.instance.pivotal_tracker_password = password
      end
      opts.on("-d", "--debug [ARG]") do
        Toolshed::Client.instance.debug = true
      end
      opts.on('-v', '--version', 'Version') do
        Toolshed::Version.banner
      end
    end

    global.order!
    if command_parts.length == 0
      usage
    elsif command_parts[0] == 'version'
      Toolshed::Version.banner
      Toolshed.die
    else
      command_class = default_command_class_string
      attempts = 0
      begin
        require "toolshed/commands/#{command_parts.join('/')}"
        command_class = command_class.split('::').inject(Object) { |o,c| o.const_get c }
      rescue NameError => e
        name_error_name = e.message.sub('wrong constant name ', '')
        name_error_name = e.message.sub('uninitialized constant ', '')
        command_class = command_class.sub(name_error_name, name_error_name.upcase)
        attempts += 1
        retry unless attempts > command_parts.length
      end
      Toolshed::Commands::Base.parse(command_class, command_class.cli_options)
    end
  end
end