Class: Hieracles::Optparse

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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)
  @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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/hieracles/optparse.rb', line 5

def options
  @options
end

#payloadObject (readonly)

Returns the value of attribute payload.



5
6
7
# File 'lib/hieracles/optparse.rb', line 5

def payload
  @payload
end

Instance Method Details

#optionkeysObject



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