Class: RubyConfig::OptionsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_config/options_parser.rb

Constant Summary collapse

COMMANDS =
{ 
  'list' => 'List installed Ruby runtimes',
  'available' => 'List available Ruby runtimes',
  'switch' => 'Switch to specific Ruby runtime',
  'install' => 'Install specific Ruby runtime',
  'uninstall' => 'Uninstall specific Ruby runtime',
  'setup' => 'Setup your bash environment'
}
OPTIONS =
{
  '-v, --version' => "Display version",
  '-h, --help' => "Display this screen"
}
EXAMPLES =
[
  'ruby-config list ',
  'ruby-config install jruby-1.3.1',
  'ruby-config switch jruby-1.3.1',
  'ruby-config -v'
]

Instance Method Summary collapse

Constructor Details

#initializeOptionsParser

Returns a new instance of OptionsParser.



25
26
27
# File 'lib/ruby_config/options_parser.rb', line 25

def initialize
  create_options
end

Instance Method Details

#parse_commands!(arguments) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/ruby_config/options_parser.rb', line 53

def parse_commands!(arguments)
  args = find_commands(arguments)
  
  @commands = OpenStruct.new
  @commands.list = false
  @commands.available = false
  @commands.switch = false
  @commands.install = false
  @commands.uninstall = false
  @commands.setup = false
 
  case args.first
  when 'list'
    @commands.list = true
  when 'available'
    @commands.available = true
  when 'setup'
    @commands.setup = true
  when 'install'
    @commands.install = true
    @commands.handle = args[1]
    abort("No Runtime specified") unless @commands.handle
  when 'uninstall'
    @commands.uninstall = true
    @commands.handle = args[1]
    abort("No Runtime specified") unless @commands.handle
  when 'switch'
    @commands.switch = true
    @commands.handle = args[1]
    abort("No Runtime specified") unless @commands.handle
  end
  
  @commands
end

#parse_options!(arguments) ⇒ Object



88
89
90
91
# File 'lib/ruby_config/options_parser.rb', line 88

def parse_options!(arguments)
  @optparse.parse!(arguments)
  @options
end


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ruby_config/options_parser.rb', line 29

def print_help
  puts "Usage: ruby-config [command] [options]"
  puts
  puts " Available Commands:"
  
  COMMANDS.each do |key, value|
    puts "  #{key} #{indent} #{value}"
  end
  
  puts
  puts " Available Options:"
  OPTIONS.each do |key, value|
    puts "  #{key} #{indent} #{value}"
  end
  
  puts 
  puts " Examples:"
  EXAMPLES.each do |value|
    puts "  #{value}"
  end
  
  puts
end