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.
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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/colortail/configuration.rb', line 53 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 [:filename_prefix] = false o.on( '-F', '--filename_prefix', 'Prefix each colored line with it\'s filename') do [:filename_prefix] = true 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 o.on('-V', '--version', "Display version information") do [:version] = true end [:help] = false o.on( '-h', '--help', 'Display this help screen' ) do [:help] = true end o.separator "" o.separator "Examples:" o.separator " Tail messages and mail log through STDIN with syslog group:" o.separator " cat /var/log/maillog | #{File.basename($0)} -g syslog /var/log/messages" o.separator " Tail messages with syslog group and maillog with mail group:" o.separator " #{File.basename($0)} /var/log/messages#syslog /var/log/messages#mail" o.separator " Tail messages with syslog group and maillog with mail group with line prefix:" o.separator " #{File.basename($0)} -F /var/log/messages#syslog /var/log/messages#mail" end begin @opts.parse!(args) self[:files] = args self[:options] = rescue OptionParser::InvalidOption => e self[:invalid_argument] = e. @opts.parse(args, flags={ :delete_invalid_opts => true }) self[:files] = args self[:options] = end end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
51 52 53 |
# File 'lib/colortail/configuration.rb', line 51 def opts @opts end |
#orig_args ⇒ Object (readonly)
Returns the value of attribute orig_args.
51 52 53 |
# File 'lib/colortail/configuration.rb', line 51 def orig_args @orig_args end |