Module: WLIConfig

Defined in:
lib/wliconfig.rb

Defined Under Namespace

Modules: Product Classes: Options, ProductFactory, WLANConfig

Instance Method Summary collapse

Instance Method Details

#create_option_parser(container) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/wliconfig.rb', line 146

def create_option_parser(container)
  op = OptionParser.new


  op.banner = "wliconfig -- The 3rd party configuration cli for BUFFALO INC wireless lan adapters are called 'WLI' series.\n\nUsage: wliconfig [options...]"
  op.version = "1.0.0"

  op.on('-f FILE', 'Read options from specified YAML file.'){|v| container[:fname] = v}
  op.on('-a', '--addr ADDR', 'WLI product\'s ip address. (eg. 192.168.0.1)'){|v| container[:addr] = v}
  op.on('-u', '--user USERNAME', 'Basic auth username. (eg. admin)'){|v| container[:user] = v}
  op.on('-p', '--pass PASSWORD', 'Basic auth password. (eg. password)'){|v| container[:pass] = v}
  op.on('-s', '--wlan-ssid SSID', 'SSID that to connect wireless lan.'){|v| container[:wlan_ssid] = v}
  op.on('-m', '--wlan-mode MODE', 'Auth mode that to connect wireless lan. (none, wep_hex, wep_char, tkip, aes, wpa2_tkip or wpa2_aes is valid.)'){|v| container[:wlan_mode] = v}
  op.on('-k', '--wlan-key KEY', 'Key or pass phrase that to connect wireless lan.'){|v| container[:wlan_key] = v}
  op.on('--debug', 'For developers only. Enabled debug mode.'){|v| $debug = true}

  op
end

#create_options(container) ⇒ Object



165
166
167
168
169
170
171
172
173
# File 'lib/wliconfig.rb', line 165

def create_options(container)
  opts = Options.new

  opts.update_from_file("#{ENV['HOME']}/.wliconfig")
  opts.update_from_file(container[:fname])
  opts.update_from_map(container)

  opts
end

#main(argv) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/wliconfig.rb', line 175

def main(argv)
  container = {}
  parser = create_option_parser(container)
  parser.parse(argv)

  unless $debug
    $wlog.level = Logger::INFO
    $wlog.formatter = proc{|severity, datetime, progname, msg| "#{msg}\n"}
  end

  $wlog.info("Start processing...")

  $wlog.debug("container:" + container.inspect)

  options = create_options(container)
  $wlog.debug("options:" + options.inspect)

  unless options.valid?
    raise "Some options were not specified. Please read usage 'wliconfig --help'."
  end

  product = ProductFactory.create(options.product, options.addr, options.user, options.pass)
  $wlog.debug("product:" + product.inspect)

  config = WLANConfig.new(options.wlan_ssid, options.wlan_mode, options.wlan_key)
  $wlog.debug("config:" + config.inspect)

  product.change_config(config)

  $wlog.info("Complete processing successfully.")

  return 0
rescue
  $wlog.error($!)
  $wlog.error("Processing failure.")

  return 1
end