Class: Gem::Micro::OptionsParser
- Inherits:
-
Object
- Object
- Gem::Micro::OptionsParser
- Defined in:
- lib/microgem/options_parser.rb
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.
8 9 10 |
# File 'lib/microgem/options_parser.rb', line 8 def initialize = {} end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
6 7 8 |
# File 'lib/microgem/options_parser.rb', line 6 def arguments @arguments end |
#command ⇒ Object
Returns the value of attribute command.
6 7 8 |
# File 'lib/microgem/options_parser.rb', line 6 def command @command end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/microgem/options_parser.rb', line 6 def end |
Instance Method Details
#banner ⇒ Object
55 56 57 |
# File 'lib/microgem/options_parser.rb', line 55 def parser.to_s end |
#parse(arguments) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/microgem/options_parser.rb', line 59 def parse(arguments) parser.parse! arguments self.command = arguments.shift self.arguments = arguments self end |
#parser ⇒ Object
12 13 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 |
# File 'lib/microgem/options_parser.rb', line 12 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 "" opts.separator " Usage:" opts.separator " µgem [command] [arguments…] [options…]" opts.separator "" opts.separator " Example:" opts.separator " µgem install rake" opts.separator " µgem install rails --force" opts.separator " µgem cache update --debug" opts.separator "" opts.separator " Options:" opts.on("--debug", "Raises the log level to `debug'") do [:log_level] = :debug end opts.on("--force", "Forces a command") do [:force] = true end opts.on("--simple-downloader", "Use curl to download files instead of Net::HTTP") do [:simple_downloader] = true end opts.on("--simple-unpacker", "Use external tools to unpack archives instead of Zlib") do [:simple_unpacker] = true end opts.on("--simple", "Enables --simple-downloader and --simple-unpacker") do [:simple_downloader] = [:simple_unpacker] = true end opts.on("--help", "Show help information") do puts opts exit end end end |