Class: Buncho::CLI

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

Class Method Summary collapse

Class Method Details

.run(argv) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/buncho/cli.rb', line 8

def run(argv)
  options = {}
  logger = NameLogger.new

  OptionParser.new do |opts|
    opts.on("-n NAME", "--name", "Buncho's name (Example: buncho -n Sora)") { |v| options[:name] = v }
    opts.on("-w WEIGHT", "--wieght", "Buncho's Weight (Example: buncho -w 25)") { |v| options[:weight] = v }
    opts.on("-l", "--weight-list", "Show list of registered buncho weights") { |v| options[:weight_list] = v }
    opts.on("-h", "--help", "Show this help message") do
      puts opts
      exit
    end
  end.parse!

  weight = options[:weight]
  resolver = NameResolver.new(logger)
  name = resolver.resolve_name(options[:name])
  weight_logger = WeightLogger.new(name)

  unless weight.nil?
    weight_logger.add(weight)
    puts "#{name}'s weight is #{weight}g."
  end

  if options[:weight_list]
    weight_logger.show
  end
end