Class: Cl::Opts
Instance Attribute Summary collapse
Instance Method Summary collapse
- #<<(opt) ⇒ Object
- #[](key) ⇒ Object
- #apply(cmd, opts) ⇒ Object
- #define(const, *args, &block) ⇒ Object
- #delete(opt) ⇒ Object
- #deprecated ⇒ Object
- #dup ⇒ Object
- #each(&block) ⇒ Object
- #to_a ⇒ Object
Methods included from Regex
Instance Attribute Details
#opts ⇒ Object
52 53 54 |
# File 'lib/cl/opts.rb', line 52 def opts @opts ||= [] end |
Instance Method Details
#<<(opt) ⇒ Object
28 29 30 31 32 |
# File 'lib/cl/opts.rb', line 28 def <<(opt) delete(opt) # keep the --help option at the end for help output opts.empty? ? opts << opt : opts.insert(-2, opt) end |
#[](key) ⇒ Object
34 35 36 |
# File 'lib/cl/opts.rb', line 34 def [](key) opts.detect { |opt| opt.name == key } end |
#apply(cmd, opts) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cl/opts.rb', line 17 def apply(cmd, opts) return opts if opts[:help] cmd.deprecations = deprecations(cmd, opts) opts = with_defaults(cmd, opts) opts = downcase(opts) opts = cast(opts) opts = taint(opts) validate(cmd, opts) opts end |
#define(const, *args, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/cl/opts.rb', line 7 def define(const, *args, &block) opts = args.last.is_a?(Hash) ? args.pop : {} strs = args.select { |arg| arg.start_with?('-') } opts[:description] = args.-(strs).first opt = Opt.new(strs, opts, block) opt.define(const) self << opt end |
#delete(opt) ⇒ Object
42 43 44 |
# File 'lib/cl/opts.rb', line 42 def delete(opt) opts.delete(opts.detect { |o| o.strs == opt.strs }) end |
#deprecated ⇒ Object
56 57 58 |
# File 'lib/cl/opts.rb', line 56 def deprecated map(&:deprecated).flatten.compact end |
#dup ⇒ Object
60 61 62 |
# File 'lib/cl/opts.rb', line 60 def dup super.tap { |obj| obj.opts = opts.dup } end |
#each(&block) ⇒ Object
38 39 40 |
# File 'lib/cl/opts.rb', line 38 def each(&block) opts.each(&block) end |
#to_a ⇒ Object
46 47 48 |
# File 'lib/cl/opts.rb', line 46 def to_a opts end |