lib/hieracles/optparse.rb in hieracles-0.1.4 vs lib/hieracles/optparse.rb in hieracles-0.1.5
- old
+ new
@@ -38,21 +38,30 @@
aliases: ['y', 'yaml']
},
json_facts: {
has_arg: true,
aliases: ['j', 'json']
+ },
+ interactive: {
+ has_arg: false,
+ aliases: ['i', 'interactive']
}
}
def initialize(array)
@options = {}
@payload = []
ok = optionkeys
while x = array.shift
if x[0] == '-'
- if ok[x[/[a-z][-_a-z]*$/]]
- @options[ok[x[/[a-z][-_a-z]*$/]]] = array.shift
+ found = ok[x[/[a-z][-_a-z]*$/]]
+ if found
+ if found[:has_args]
+ @options[found[:var]] = array.shift
+ else
+ @options[found[:var]] = true
+ end
else
array.shift
end
else
@payload << x
@@ -62,10 +71,10 @@
def optionkeys
back = {}
OPTIONS.each do |k, v|
v[:aliases].each do |a|
- back[a] = k
+ back[a] = { var: k, has_args: v[:has_arg] }
end
end
back
end