Class: SmarterMeter::Interfaces::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/smartermeter/interfaces/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ CLI

Returns a new instance of CLI.



6
7
8
# File 'lib/smartermeter/interfaces/cli.rb', line 6

def initialize(options)
  @options = options
end

Instance Method Details

#logObject

Returns a logger like interface to log errors and warnings to.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/smartermeter/interfaces/cli.rb', line 11

def log
  return @logger if @logger
  @logger = Logger.new STDOUT

  if @options[:debug]
    @logger.level = Logger::DEBUG
  else
    @logger.level = Logger::INFO
  end

  @logger
end

#setup {|config| ... } ⇒ Object

Public: Called when ~/.smartermeter needs to be configured. Yields a hash containing the configuration by the user.

Returns nothing

Yields:

  • (config)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/smartermeter/interfaces/cli.rb', line 28

def setup
  puts
  puts "SmarterMeter: Initial Configuration"
  puts "--------------------------------------------------------------------------------"
  puts "This program stores your PG&E account username and password on disk. The"
  puts "password is encrypted but could be retrieved fairly easily. If this makes you"
  puts "uncomfortable quit now (use ctrl-c)."
  puts "--------------------------------------------------------------------------------"

  config = {}

  print "PG&E account username: "
  config[:username] = gets.strip

  print "PG&E account password: "
  config[:password] = gets.strip

  puts "Configuration finished"

  yield config
end