Class: BenchPress::CLI
- Inherits:
-
Object
- Object
- BenchPress::CLI
- Defined in:
- lib/bench_press/cli.rb
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #email ⇒ Object
- #file_exists? ⇒ Boolean
- #file_path ⇒ Object
- #git_email ⇒ Object
-
#initialize(argv) ⇒ CLI
constructor
A new instance of CLI.
- #optparse ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(argv) ⇒ CLI
Returns a new instance of CLI.
6 7 8 9 10 11 |
# File 'lib/bench_press/cli.rb', line 6 def initialize(argv) @argv = argv @options = {} optparse.parse!(argv) @filename = argv.shift end |
Instance Attribute Details
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
4 5 6 |
# File 'lib/bench_press/cli.rb', line 4 def argv @argv end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
4 5 6 |
# File 'lib/bench_press/cli.rb', line 4 def filename @filename end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/bench_press/cli.rb', line 4 def @options end |
Instance Method Details
#email ⇒ Object
13 14 15 |
# File 'lib/bench_press/cli.rb', line 13 def email [:email] || git_email end |
#file_exists? ⇒ Boolean
21 22 23 |
# File 'lib/bench_press/cli.rb', line 21 def file_exists? filename && File.exists?(file_path) end |
#file_path ⇒ Object
17 18 19 |
# File 'lib/bench_press/cli.rb', line 17 def file_path @file_path ||= File.join(Dir.pwd, filename) end |
#git_email ⇒ Object
25 26 27 |
# File 'lib/bench_press/cli.rb', line 25 def git_email @git_email ||= %x(git config --global --get user.email).strip end |
#optparse ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bench_press/cli.rb', line 29 def optparse @optparse ||= OptionParser.new do |opts| opts. = "Usage: bench_press [options] file_to_benchmark.rb" opts.on( '-n', '--new', 'Create a new benchmark' ) do [:new] = true end opts.on( '-p', '--publish', 'Publish the benchmark to http://rubybenchmark.com' ) do [:publish] = true end opts.on('--email EMAIL', String, "Author email used when publishing, defaults to #{git_email}") do |email| [:email] = email end opts.on( '-v', '--version', 'Show the version of bench_press' ) do [:version] = true end end end |
#run ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/bench_press/cli.rb', line 51 def run if [:version] exit_with_version elsif file_exists? perform_bench_press elsif [:new] new_bench_press else abort "Could not proceed, please supply the filename you wish to benchmark" end end |