Sha256: 7346ee1651dc516b4a1ab63460dfa82ce15b406f6cdb5e51850657372ef021d0
Contents?: true
Size: 1.11 KB
Versions: 6
Compression:
Stored size: 1.11 KB
Contents
module Hieracles class Optparse attr_reader :options, :payload 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'] } } 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 else array.shift end else @payload << x end end end def optionkeys back = {} OPTIONS.each do |k, v| v[:aliases].each do |a| back[a] = k end end back end end end
Version data entries
6 entries across 6 versions & 1 rubygems