class BBLib::OptsParser
Public Class Methods
build(&block)
click to toggle source
# File lib/bblib/cli/opts_parser.rb, line 25 def self.build(&block) new(&block) end
Public Instance Methods
at(position, **opts, &block)
click to toggle source
# File lib/bblib/cli/opts_parser.rb, line 34 def at(position, **opts, &block) add_options(opts.merge(type: :at, position: position, processor: block)) end
help()
click to toggle source
# File lib/bblib/cli/opts_parser.rb, line 56 def help usage.to_s + "\n\t" + options.join("\n\t") end
on(*flags, **opts, &block)
click to toggle source
# File lib/bblib/cli/opts_parser.rb, line 38 def on(*flags, **opts, &block) opts[:type] = :string unless opts[:type] add_options(opts.merge(flags: flags, processor: block)) end
parse(args = ARGV)
click to toggle source
# File lib/bblib/cli/opts_parser.rb, line 43 def parse(args = ARGV) parse!(args.dup) end
parse!(args = ARGV)
click to toggle source
# File lib/bblib/cli/opts_parser.rb, line 47 def parse!(args = ARGV) args = [args] unless args.is_a?(Array) HashStruct.new.tap do |hash| options.sort_by { |opt| opt.position || 10**100 }.each do |option| option.retrieve(args, hash) end end.merge(arguments: args.compact) end
to_s()
click to toggle source
# File lib/bblib/cli/opts_parser.rb, line 61 def to_s help end
usage(text = nil)
click to toggle source
# File lib/bblib/cli/opts_parser.rb, line 29 def usage(text = nil) @usage = text unless text.nil? @usage end
Protected Instance Methods
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/bblib/cli/opts_parser.rb, line 67 def method_missing(method, *args, &block) if Option.types.include?(method) define_singleton_method(method) do |*flags, **opts, &block| on(*flags, **opts.merge(type: method), &block) end send(method, *args, &block) else super end end
respond_to_missing?(method, include_private = false)
click to toggle source
Calls superclass method
# File lib/bblib/cli/opts_parser.rb, line 78 def respond_to_missing?(method, include_private = false) Option.types.include?(method) || super end