Class: Juicer::Cli

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCli

Returns a new instance of Cli.



8
9
10
11
# File 'lib/juicer/cli.rb', line 8

def initialize
  @log = Juicer::LOGGER
  @log.level = Logger::INFO
end

Class Method Details

.run(arguments = ARGV) ⇒ Object

Run CLI



35
36
37
38
# File 'lib/juicer/cli.rb', line 35

def self.run(arguments = ARGV)
  juicer = self.new
  juicer.parse(arguments)
end

Instance Method Details

#parse(arguments = ARGV) ⇒ Object

Set up command parser and parse arguments



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/juicer/cli.rb', line 15

def parse(arguments = ARGV)
  @cmd = CmdParse::CommandParser.new(true, true)
  @cmd.program_name = "juicer"
  @cmd.program_version = Juicer.version.split(".")

  @cmd.options = CmdParse::OptionParserWrapper.new do |opt|
    opt.separator "Global options:"
    opt.on("-v", "--verbose", "Be verbose when outputting info") { |t| @log.level = Logger::DEBUG }
    opt.on("-q", "--quiet", "Only log warnings and errors") { |t| @log.level = Logger::WARN }
  end

  add_commands
  @cmd.parse(arguments)
  @log.close
rescue SystemExit
  exit
end