30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/dldinternet/aws/ec2/instance_types/mixins/no_commands.rb', line 30
def parse_options
if options[:help]
Cli.start(['help'])
exit 0
end
validate_options
lcs = ::Logging::ColorScheme.new( 'compiler', :levels => {
:trace => :blue,
:debug => :cyan,
:info => :green,
:step => :green,
:warn => :yellow,
:error => :red,
:fatal => :red,
:todo => :purple,
})
scheme = lcs.scheme
scheme['trace'] = "\e[38;5;33m"
scheme['fatal'] = "\e[38;5;89m"
scheme['todo'] = "\e[38;5;55m"
lcs.scheme scheme
@config = @options.dup
@config[:log_opts] = lambda{|mlll| {
:pattern => "%#{mlll}l: %m %g\n",
:date_pattern => '%Y-%m-%d %H:%M:%S',
:color_scheme => 'compiler',
:trace => (@config[:trace].nil? ? false : @config[:trace]),
}
}
@logger = getLogger(@config)
if @options[:inifile]
@options[:inifile] = File.expand_path(@options[:inifile])
unless File.exist?(@options[:inifile])
raise "#{@options[:inifile]} not found!"
end
begin
ini = ::IniFile.load(@options[:inifile])
ini['global'].each{ |key,value|
@options[key.to_s]=value
}
def _expand(k,v,regex,rerun)
matches = v.match(regex)
if matches
var = matches[1]
if options[var]
options[k]=v.gsub(/\%\(#{var}\)/,options[var]).gsub(/\%#{var}/,options[var])
else
rerun[var] = 1
end
end
end
pending = nil
rerun = {}
begin
pending = rerun
rerun = {}
options.to_hash.each{|k,v|
if v.to_s.match(/\%/)
_expand(k,v,%r'[^\\]\%\((\w+)\)', rerun)
_expand(k,v,%r'[^\\]\%(\w+)', rerun)
end
}
end while pending != rerun
rescue ::IniFile::Error => e
rescue ::Exception => e
@logger.error "#{e.class.name} #{e.message}"
raise e
end
end
if options[:verbose]
@logger.info "Options:\n#{options.ai}"
end
end
|