Method: Olib::ScriptVars#initialize

Defined in:
lib/Olib/utils/cli.rb,
lib/Olib/core/utils.rb

#initializeScriptVars

Returns a new instance of ScriptVars.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/Olib/utils/cli.rb', line 4

def initialize
  opts          = {}
  opts[:flags]  = {}
  return opts if Script.current.vars.empty?
  list          = Script.current.vars.map(&:downcase).last(Script.current.vars.length-1)
  
  unless list.first.start_with?('--')
    opts[:cmd]   = list.shift
  end

  # iterate over list for flag values
  flags = list.compact.join(' ').split('--')
  flags.shift
  flags.each { |flag|
    segments  = flag.split(' ')
    name      =  symbolize(segments.shift)
    opts[:flags][name] = true 
    if !segments.empty?
      value = segments.join(' ').strip
      if value =~ /[\d]+/
        value = value.to_i
      end
      opts[:flags][name] = value
    end
  }

  @opts = opts
  self
end