Class: Tailer::CommandLine
- Inherits:
-
Object
- Object
- Tailer::CommandLine
- Defined in:
- lib/tailer/command_line.rb
Instance Attribute Summary collapse
-
#downloader ⇒ Object
Returns the value of attribute downloader.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize ⇒ CommandLine
constructor
A new instance of CommandLine.
Constructor Details
#initialize ⇒ CommandLine
Returns a new instance of CommandLine.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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 |
# File 'lib/tailer/command_line.rb', line 28 def initialize @options = {} begin @optparse = OptionParser.new do |opts| opts. = "Usage: #{$0} options" @options[:output] = STDOUT opts.on( '--output FILE', 'Send all recieved data to FILE (defaults to STDOUT)') do |file| @options[:output] = File.new(file, 'a+') end @options[:hosts] = [] opts.on( '--host HOST', 'Host to connect to via SSH' ) do |host| @options[:hosts] << host end @options[:files] = [] opts.on( '--file FILE', 'File to tail' ) do |file| @options[:files] << file end @options[:log_level] = Logger::INFO opts.on( '--log-level LEVEL', 'Logging level' ) do|level| @options[:log_level] = Logger.const_get level.upcase end opts.on( '-V', '--version', 'Display version information' ) do puts "Tailer #{Tailer::VERSION}" puts "Copyright (C) 2012 Erik Osterman <[email protected]>" puts "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>" puts "This is free software: you are free to change and redistribute it." puts "There is NO WARRANTY, to the extent permitted by law." exit end opts.on( '-h', '--help', 'Display this screen' ) do puts opts exit end end @optparse.parse! raise MissingArgumentException.new("Missing --host argument") if @options[:hosts].length == 0 raise MissingArgumentException.new("Missing --file argument") if @options[:files].length == 0 @listener = Listener.new(@options) rescue MissingArgumentException => e puts e. puts @optparse exit (1) end end |
Instance Attribute Details
#downloader ⇒ Object
Returns the value of attribute downloader.
27 28 29 |
# File 'lib/tailer/command_line.rb', line 27 def downloader @downloader end |
Instance Method Details
#execute ⇒ Object
83 84 85 |
# File 'lib/tailer/command_line.rb', line 83 def execute @listener.execute end |