Class: RubySearch::CLI
- Inherits:
-
Object
- Object
- RubySearch::CLI
- Defined in:
- lib/ruby_search/cli.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #bundler_groups ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #load_environment ⇒ Object
- #parse_options(args = ARGV) ⇒ Object
- #working_dir ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
17 18 19 |
# File 'lib/ruby_search/cli.rb', line 17 def initialize @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/ruby_search/cli.rb', line 15 def @options end |
Class Method Details
Instance Method Details
#bundler_groups ⇒ Object
52 53 54 55 |
# File 'lib/ruby_search/cli.rb', line 52 def bundler_groups groups = [:default] groups << (ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development').to_sym end |
#load_environment ⇒ Object
57 58 59 60 61 |
# File 'lib/ruby_search/cli.rb', line 57 def load_environment # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.('../../Gemfile', working_dir) Bundler.require(*bundler_groups) if File.exists?(ENV['BUNDLE_GEMFILE']) end |
#parse_options(args = ARGV) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ruby_search/cli.rb', line 21 def (args=ARGV) = {} opt_parser = OptionParser.new do |opts| opts. = 'Usage: rs some_method [options]' opts.on '-e', '--escape', 'search literal string' do |e| [:escape] = e end opts.on '-v', '--[no-]verbose', 'verbose output' do |v| [:verbose] = v end opts.on '-c', '--[no-]colorize', 'colored output' do |v| [:colorize] = v end end opt_parser.parse!(args) if args.empty? puts opt_parser.help exit end if [:escape] [:q] = Regexp.new(Regexp.escape(args.first)) else [:q] = Regexp.new(args.first) end end |
#working_dir ⇒ Object
48 49 50 |
# File 'lib/ruby_search/cli.rb', line 48 def working_dir ENV['PWD'] end |