Class: Hieracles::Optparse
- Inherits:
-
Object
- Object
- Hieracles::Optparse
- Defined in:
- lib/hieracles/optparse.rb
Constant Summary collapse
- OPTIONS =
{ config: { has_arg: true, aliases: ['c', 'conf', 'config'] }, format: { has_arg: true, aliases: ['f', 'format'] }, params: { has_arg: true, aliases: ['p', 'params'] }, hierafile: { has_arg: true, aliases: ['h', 'hierafile'] }, basepath: { has_arg: true, aliases: ['b', 'basepath'] }, encpath: { has_arg: true, aliases: ['e', 'encpath'] }, version: { has_arg: false, aliases: ['v', 'version'] }, yaml_facts: { has_arg: true, aliases: ['y', 'yaml'] }, json_facts: { has_arg: true, aliases: ['j', 'json'] }, interactive: { has_arg: false, aliases: ['i', 'interactive'] } }
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
Instance Method Summary collapse
-
#initialize(array) ⇒ Optparse
constructor
A new instance of Optparse.
- #optionkeys ⇒ Object
Constructor Details
#initialize(array) ⇒ Optparse
Returns a new instance of Optparse.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/hieracles/optparse.rb', line 50 def initialize(array) = {} @payload = [] ok = optionkeys while x = array.shift if x[0] == '-' found = ok[x[/[a-z][-_a-z]*$/]] if found if found[:has_args] [found[:var]] = array.shift else [found[:var]] = true end else array.shift end else @payload << x end end end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/hieracles/optparse.rb', line 5 def end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
5 6 7 |
# File 'lib/hieracles/optparse.rb', line 5 def payload @payload end |
Instance Method Details
#optionkeys ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/hieracles/optparse.rb', line 72 def optionkeys back = {} OPTIONS.each do |k, v| v[:aliases].each do |a| back[a] = { var: k, has_args: v[:has_arg] } end end back end |