Class: Gem::Micro::OptionsParser
- Inherits:
-
Object
- Object
- Gem::Micro::OptionsParser
- Defined in:
- lib/microgem/options_parser.rb
Constant Summary collapse
- EXECUTABLE =
File.basename($0)
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#command ⇒ Object
Returns the value of attribute command.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #banner ⇒ Object
-
#initialize ⇒ OptionsParser
constructor
A new instance of OptionsParser.
- #parse(arguments) ⇒ Object
- #parser ⇒ Object
Constructor Details
#initialize ⇒ OptionsParser
Returns a new instance of OptionsParser.
10 11 12 |
# File 'lib/microgem/options_parser.rb', line 10 def initialize @options = {} end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
8 9 10 |
# File 'lib/microgem/options_parser.rb', line 8 def arguments @arguments end |
#command ⇒ Object
Returns the value of attribute command.
8 9 10 |
# File 'lib/microgem/options_parser.rb', line 8 def command @command end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/microgem/options_parser.rb', line 8 def @options end |
Instance Method Details
#banner ⇒ Object
58 59 60 |
# File 'lib/microgem/options_parser.rb', line 58 def 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 |
#parser ⇒ Object
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. = "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 |