class Ronin::CLI::FileProcessorCommand
Base class for all commands which process files.
Public Instance Methods
open_file(path,mode='r',&block)
click to toggle source
Opens a file for reading.
@param [Stirng] path
The path to the file to open.
@param [String] mode
The mode to open the file with.
@yield [file]
If a block is given, the newly opened file will be yielded. Once the block returns the file will automatically be closed.
@yieldparam [File] file
The newly opened file.
@return [File, nil]
If no block is given, the newly opened file object will be returned. If no block was given, then `nil` will be returned.
# File lib/ronin/cli/file_processor_command.rb, line 66 def open_file(path,mode='r',&block) File.open(path,mode,&block) rescue Errno::ENOENT print_error "no such file or directory: #{path}" exit(1) end
process_file(path)
click to toggle source
Processes a file.
@param [String] path
The path to the file to read and process.
# File lib/ronin/cli/file_processor_command.rb, line 79 def process_file(path) open_file(path,&method(:process_input)) end
process_input(input)
click to toggle source
Processes an input stream.
@param [File, IO] input
The opened file or the `stdin` input stream.
@abstract
# File lib/ronin/cli/file_processor_command.rb, line 91 def process_input(input) raise(NotImplementedError,"#{self.class}##{__method__} method was not implemented") end
run(*files)
click to toggle source
Runs the command and processes files or stdin.
@param [Array<String>] files
Optional files to process.
# File lib/ronin/cli/file_processor_command.rb, line 38 def run(*files) if files.empty? process_input(stdin) else files.each(&method(:process_file)) end end