Class: GGem::CLI::CLIRB
- Inherits:
-
Object
- Object
- GGem::CLI::CLIRB
- Defined in:
- lib/ggem/cli/clirb.rb
Overview
Version 1.2.0, github.com/redding/cli.rb
Defined Under Namespace
Classes: Option
Constant Summary collapse
- Error =
Class.new(RuntimeError)
- HelpExit =
Class.new(RuntimeError)
- VersionExit =
Class.new(RuntimeError)
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#initialize(&block) ⇒ CLIRB
constructor
A new instance of CLIRB.
- #inspect ⇒ Object
- #option(*args, **kargs) ⇒ Object
- #parse!(argv) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(&block) ⇒ CLIRB
Returns a new instance of CLIRB.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ggem/cli/clirb.rb', line 10 def initialize(&block) @options = []; instance_eval(&block) if block require "optparse" @data, @args, @opts = [], [], {}; @parser = OptionParser.new do |p| p. = ""; @options.each do |o| @opts[o.name] = o.value; p.on(*o.parser_args){ |v| @opts[o.name] = v } end p.on_tail("--version", ""){ |v| raise VersionExit, v.to_s } p.on_tail("--help", ""){ |v| raise HelpExit, v.to_s } end end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
8 9 10 |
# File 'lib/ggem/cli/clirb.rb', line 8 def args @args end |
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
8 9 10 |
# File 'lib/ggem/cli/clirb.rb', line 8 def argv @argv end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/ggem/cli/clirb.rb', line 8 def data @data end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
8 9 10 |
# File 'lib/ggem/cli/clirb.rb', line 8 def opts @opts end |
Instance Method Details
#inspect ⇒ Object
30 31 32 |
# File 'lib/ggem/cli/clirb.rb', line 30 def inspect "#<#{self.class}:#{"0x0%x" % (object_id << 1)} @data=#{@data.inspect}>" end |
#option(*args, **kargs) ⇒ Object
22 |
# File 'lib/ggem/cli/clirb.rb', line 22 def option(*args, **kargs); @options << Option.new(*args, **kargs); end |
#parse!(argv) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/ggem/cli/clirb.rb', line 23 def parse!(argv) @args = (argv || []).dup.tap do |args_list| begin; @parser.parse!(args_list) rescue OptionParser::ParseError => err; raise Error, err.; end end; @data = @args + [@opts] end |
#to_s ⇒ Object
29 |
# File 'lib/ggem/cli/clirb.rb', line 29 def to_s; @parser.to_s; end |