Class: Yardstick::CLI
- Inherits:
-
Object
- Object
- Yardstick::CLI
- Defined in:
- lib/yardstick/cli.rb
Overview
Handle the yardstick command line interface
Class Method Summary collapse
-
.display_exit(message) ⇒ undefined
private
Display a message and exit.
-
.option_parser(_options) ⇒ Yardstick::OptionParser
private
Return an OptionParser instance for the command-line app.
-
.parse_config(args) ⇒ Config
private
Parse the options provided from the command-line.
-
.run(*args) ⇒ Yardstick::MeasurementSet
Parse the command line options, and run the command.
Class Method Details
.display_exit(message) ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Display a message and exit
68 69 70 71 |
# File 'lib/yardstick/cli.rb', line 68 def self.display_exit() puts .to_str exit end |
.option_parser(_options) ⇒ Yardstick::OptionParser
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return an OptionParser instance for the command-line app
53 54 55 56 57 58 |
# File 'lib/yardstick/cli.rb', line 53 def self.option_parser() opts = OptionParser.new opts.on_tail('-v', '--version', 'print version information and exit') { display_exit("#{opts.program_name} #{Yardstick::VERSION}") } opts.on_tail('-h', '--help', 'display this help and exit') { display_exit(opts.to_s) } opts end |
.parse_config(args) ⇒ Config
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parse the options provided from the command-line
35 36 37 38 39 40 41 42 |
# File 'lib/yardstick/cli.rb', line 35 def self.parse_config(args) args << '--help' if args.empty? = {} option_parser().parse!(args) Config.new(.merge(:path => args)) rescue OptionParser::InvalidOption => error display_exit(error.) end |
.run(*args) ⇒ Yardstick::MeasurementSet
Parse the command line options, and run the command
20 21 22 23 24 |
# File 'lib/yardstick/cli.rb', line 20 def self.run(*args) measurements = Yardstick.measure(parse_config(args)) measurements.puts measurements end |