Class: Gem::Micro::OptionsParser

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

Constant Summary collapse

EXECUTABLE =
File.basename($0)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptionsParser

Returns a new instance of OptionsParser.



10
11
12
# File 'lib/microgem/options_parser.rb', line 10

def initialize
  @options = {}
end

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments.



8
9
10
# File 'lib/microgem/options_parser.rb', line 8

def arguments
  @arguments
end

#commandObject

Returns the value of attribute command.



8
9
10
# File 'lib/microgem/options_parser.rb', line 8

def command
  @command
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/microgem/options_parser.rb', line 8

def options
  @options
end

Instance Method Details



58
59
60
# File 'lib/microgem/options_parser.rb', line 58

def banner
  parser.to_s
end

#parse(arguments) ⇒ Object



62
63
64
65
66
67
# File 'lib/microgem/options_parser.rb', line 62

def parse(arguments)
  parser.parse! arguments
  self.command = arguments.shift
  self.arguments = arguments
  self
end

#parserObject



14
15
16
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
# File 'lib/microgem/options_parser.rb', line 14

def parser
  @parser ||= OptionParser.new do |opts|
    opts.banner =  "Microgem is an unsophisticated package manager for Ruby."
    opts.separator "And the first commandline utility to start with a multibyte character; µ"
    opts.separator "Although you apperantly don’t appreciate unicode enough, how lame… ;-)" if EXECUTABLE != 'µgem'
    opts.separator ""
    opts.separator "  Usage:"
    opts.separator "        #{EXECUTABLE} [command] [arguments…] [options…]"
    opts.separator ""
    opts.separator "  Example:"
    opts.separator "        #{EXECUTABLE} install rake"
    opts.separator "        #{EXECUTABLE} install rails --force"
    opts.separator "        #{EXECUTABLE} cache update --debug"
    opts.separator ""
    opts.separator "  Options:"
    
    opts.on("--debug", "Raises the log level to `debug'") do
      @options[:log_level] = :debug
    end
    
    opts.on("--force", "Forces a command") do
      @options[:force] = true
    end
    
    opts.on("--simple-downloader", "Use curl to download files instead of Net::HTTP") do
      @options[:simple_downloader] = true
    end
    
    opts.on("--simple-unpacker", "Use external tools to unpack archives instead of Zlib") do
      @options[:simple_unpacker] = true
    end
    
    opts.on("--simple", "Enables --simple-downloader and --simple-unpacker") do
      @options[:simple_downloader] = @options[:simple_unpacker] = true
    end
    
    opts.on("--help", "Show help information") do
      puts opts
      exit
    end
    
  end
end