Class: Apt::Kusa::CLI

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

Instance Method Summary collapse

Instance Method Details

#postObject



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
# File 'lib/apt/kusa/cli.rb', line 28

def post
  config = load_config

  unless username = ENV["PIXELA_USER_NAME"] || config['username']
    puts "Please set your username."
    exit
  end
  unless token = ENV["PIXELA_USER_TOKEN"] || config['token']
    puts "Please set your API token"
    exit
  end

  summary = parse_and_summarize

  client = Pixela::Client.new(username: username, token: token)
  graph = client.graph(options[:graph])
  if options[:create]
    graph.create(
      type: "int",
      name: options[:graph_name],
      unit: options[:graph_unit],
      color: options[:graph_color],
      timezone: options[:graph_tz]
    )
  end

  summary.each do |date, count|
    q = count.to_a.select{|h| [:install,:upgrade].include?(h[0])}.inject(0) {|s,h| s+=h[1]}
    graph.pixel(Date.parse(date)).update(quantity: q)
  end
end

#summaryObject



13
14
15
16
17
18
# File 'lib/apt/kusa/cli.rb', line 13

def summary
  summary = parse_and_summarize
  summary.each do |k, v|
    puts "#{k} #{v.to_a.map{|a| a.join(":")}.join(" ")}"
  end
end

#versionObject



61
62
63
# File 'lib/apt/kusa/cli.rb', line 61

def version
  puts Apt::Kusa::VERSION
end