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'] } }
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
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/hieracles/optparse.rb', line 46 def initialize(array) = {} @payload = [] ok = optionkeys while x = array.shift if x[0] == '-' if ok[x[/[a-z][-_a-z]*$/]] [ok[x[/[a-z][-_a-z]*$/]]] = array.shift 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
63 64 65 66 67 68 69 70 71 |
# File 'lib/hieracles/optparse.rb', line 63 def optionkeys back = {} OPTIONS.each do |k, v| v[:aliases].each do |a| back[a] = k end end back end |