Class: Clockker::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/clockker/cli.rb

Instance Method Summary collapse

Instance Method Details

#versionObject



69
70
71
# File 'lib/clockker/cli.rb', line 69

def version
  puts Clockker.version_string
end

#watchObject



20
21
22
23
24
25
26
27
28
29
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
# File 'lib/clockker/cli.rb', line 20

def watch
  logger = Logger.new(STDERR)
  case options[:verbose]
  when 'debug'
    logger.level = Logger::DEBUG
  when 'info'
    logger.level = Logger::INFO
  when 'warn'
    logger.level = Logger::WARN
  when 'error'
    logger.level = Logger::ERROR
  else # fatal and no preference
    logger.level = Logger::FATAL
  end
  logger.debug "Setting verbosity to #{options[:verbose]}"
  
  # config_params = {}
  # config_params[:submit_frequency] = options[:submit_frequency].to_i if options[:submit_frequency].present?
  # config_params[:log_level] = options[:verbose] if options[:verbose].present?
  # config_params[:token] = options[:token] if options[:token].present?
  # config_params[:whitelist] = options[:whitelist] if options[:whitelist].present?
  # config_params[:blacklist] = options[:blacklist] if options[:blacklist].present?

  clockker_config = Clockker::Config.new(
    submit_frequency: options[:submit_frequency].to_i,
    log_level: options[:verbose],
    identifier: options[:identifier]
  )

  clockker_config.token = options[:token] if options[:token]
  clockker_config.region = options[:region] if options[:region]
  clockker_config.whitelist = options[:whitelist] if options[:whitelist]
  clockker_config.blacklist = options[:blacklist] if options[:blacklist]
  clockker_config.development = options[:development] if options[:development]

  if options[:token].nil? && clockker_config.token.nil?
    puts "You must provide a value for the token, either as a parameter (--token=x) or in the ~/.clockker_config file."
    exit
  end

  if options[:region].nil? && clockker_config.region.nil?
    puts "You must provide a value for the server region (e.g. ca-central, us-east, eu-frankfurt, etc.), either as a parameter (--region=x) or in the ~/.clockker_config file."
    exit
  end

  Clockker::Watcher.new(clockker_config, logger: logger)
end