Class: ColorTail::Options

Inherits:
Hash
  • Object
show all
Defined in:
lib/colortail/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

    options = {}
    
    require 'optparse'
    @opts = OptionParser.new do |o|
        o.banner = "Usage: #{File.basename($0)} <file1> <file2> ..."
    
        options[:group] = 'default'
        o.on( '-g', '--group <group>', 'Specify the color grouping to use for these files' ) do |group|
            options[:group] = group
        end

        options[:list] = false
        o.on( '-l', '--list', 'List all the available color groupings' ) do |group|
            options[:list] = true
        end

        o.separator ""
    
        options[:conf] = "#{user_home}/.colortailrc"
        o.on( '-c', '--conf <file>', 'Specify an alternate config file' ) do |file|
            if File.exists?(file)
                options[:conf] = file
            else
                raise FileDoesNotExist, "Config file #{file} cannot be found."
            end
        end

        options[:help] = false
        o.on_tail( '-h', '--help', 'Display this help screen' ) do
            options[:help] = true
        end
    end

    begin
        @opts.parse!(args)
        self[:files] = args
        self[:options] = options
    rescue OptionParser::InvalidOption => e
        self[:invalid_argument] = e.message
    end
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



49
50
51
# File 'lib/colortail/configuration.rb', line 49

def opts
  @opts
end

#orig_argsObject (readonly)

Returns the value of attribute orig_args.



49
50
51
# File 'lib/colortail/configuration.rb', line 49

def orig_args
  @orig_args
end