Class: Perfer::CLI
- Inherits:
-
Object
- Object
- Perfer::CLI
- Defined in:
- lib/perfer/cli.rb
Constant Summary collapse
- COMMANDS =
%w[ config graph help report results run ]
- HELP =
<<-EOS Usage: perfer <command> [options] arguments Commands: run files+ - run with current ruby report files+ - show the results config reset - reset the configuration file to the defaults (or create it) help - show this help results path files+ - show the paths to the result files rm,delete files+ - remove the result files rewrite files+ - rewrite the result files in the latest format <files+> are a set of benchmark files Common options: EOS
Instance Method Summary collapse
- #common_options(options) ⇒ Object
- #config ⇒ Object
- #error(message) ⇒ Object
- #execute ⇒ Object
- #graph ⇒ Object
- #help ⇒ Object
-
#initialize(argv) ⇒ CLI
constructor
A new instance of CLI.
- #report ⇒ Object
- #results ⇒ Object
- #run ⇒ Object
- #unknown_subcommand(subcommand) ⇒ Object
Constructor Details
Instance Method Details
#common_options(options) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/perfer/cli.rb', line 112 def () .on('-t TIME', Float, "Minimal time to run (greater usually improve accuracy)") do |t| error "Minimal time must be > 0" if t <= 0 Perfer.configuration.minimal_time = t end .on('-m N', Integer, "Numbers of measurements per job") do |n| error "There must be at least 2 measurements" if n < 2 Perfer.configuration.measurements = n end .on('-v', "Verbose") do Perfer.configuration.verbose = true end .on('-h', '--help', "Show this help") do puts .help exit end end |
#config ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/perfer/cli.rb', line 103 def config case subcommand = @argv.shift when "reset" Perfer.configuration.write_defaults else unknown_subcommand subcommand end end |
#error(message) ⇒ Object
62 63 64 65 66 |
# File 'lib/perfer/cli.rb', line 62 def error $stderr.puts $stderr.puts abort @opts.help end |
#execute ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/perfer/cli.rb', line 40 def execute begin @opts.order!(@argv) rescue OptionParser::ParseError => e error e. end @command = @argv.shift error "A command must be given, one of: #{COMMANDS*', '}" unless @command error "Unknown command: #{@command.inspect}" unless COMMANDS.include? @command send(@command) end |
#graph ⇒ Object
97 98 99 100 101 |
# File 'lib/perfer/cli.rb', line 97 def graph each_session { |session| session.graph } end |
#help ⇒ Object
68 69 70 |
# File 'lib/perfer/cli.rb', line 68 def help puts @opts.help end |
#report ⇒ Object
72 73 74 75 |
# File 'lib/perfer/cli.rb', line 72 def report measurements = (@argv.shift if @argv.first == '--measurements') each_session { |session| session.report(:measurements => measurements) } end |
#results ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/perfer/cli.rb', line 84 def results case subcommand = @argv.shift when "path" each_session { |session| puts session.store.file } when "delete", "rm" each_session { |session| session.store.delete } when "rewrite" each_session { |session| session.store.rewrite } else unknown_subcommand subcommand end end |
#run ⇒ Object
77 78 79 80 81 82 |
# File 'lib/perfer/cli.rb', line 77 def run # load files files.each do |file| require file.path end end |
#unknown_subcommand(subcommand) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/perfer/cli.rb', line 54 def unknown_subcommand(subcommand) if subcommand error "Unknown subcommand for #{@command}: #{subcommand.inspect}" else error "`perfer #{@command}` needs a subcommand" end end |