Class: ColorTail::Options
- Inherits:
-
Hash
- Object
- Hash
- ColorTail::Options
- Defined in:
- lib/colortail/configuration.rb
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#orig_args ⇒ Object
readonly
Returns the value of attribute orig_args.
Instance Method Summary collapse
-
#initialize(args) ⇒ Options
constructor
A new instance of Options.
Constructor Details
#initialize(args) ⇒ Options
Returns a new instance of Options.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/colortail/configuration.rb', line 51 def initialize(args) super() user_home = ENV['HOME'] @orig_args = args.clone = {} require 'optparse' @opts = OptionParser.new do |o| o. = "Usage: #{File.basename($0)} <file1> <file2> ..." [:group] = 'default' o.on( '-g', '--group <group>', 'Specify the color grouping to use for these files' ) do |group| [:group] = group end [:list] = false o.on( '-l', '--list', 'List all the available color groupings' ) do |group| [:list] = true end o.separator "" [:conf] = "#{user_home}/.colortailrc" o.on( '-c', '--conf <file>', 'Specify an alternate config file' ) do |file| if File.exists?(file) [:conf] = file else raise FileDoesNotExist, "Config file #{file} cannot be found." end end [:help] = false o.on_tail( '-h', '--help', 'Display this help screen' ) do [:help] = true end end begin @opts.parse!(args) self[:files] = args self[:options] = rescue OptionParser::InvalidOption => e self[:invalid_argument] = e. end end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
49 50 51 |
# File 'lib/colortail/configuration.rb', line 49 def opts @opts end |
#orig_args ⇒ Object (readonly)
Returns the value of attribute orig_args.
49 50 51 |
# File 'lib/colortail/configuration.rb', line 49 def orig_args @orig_args end |