Class: PhTools::Runner
- Inherits:
-
Object
- Object
- PhTools::Runner
- Defined in:
- lib/phtools/runner.rb
Overview
Main class processing input stream
Direct Known Subclasses
Phbackup, Phevent, Phfixdto, Phfixfmd, Phgettags, Phls, Phmove, Phrename, Phtagset
Instance Method Summary collapse
-
#initialize(usage, file_type = []) ⇒ Runner
constructor
A new instance of Runner.
- #run! ⇒ Object
Constructor Details
#initialize(usage, file_type = []) ⇒ Runner
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/phtools/runner.rb', line 16 def initialize(usage, file_type = []) case Utils.os when :windows # workaround for win32 ARGV.map! { |a| a.encode('utf-8', 'filesystem') } @os = Utils::OSWin.new else @os = Utils::OSUnix.new end @tool_name = File.basename($PROGRAM_NAME) = Docopt.docopt(usage, version: "v#{PhTools::VERSION}") @file_type = file_type PhTools.debug = true if ['--debug'] rescue Docopt::Exit => e STDERR.puts e. exit 1 rescue => e PhTools.puts_error "FATAL: #{e.message}", e exit 1 ensure if PhTools.debug STDERR.puts "Runner Instance Variables: " STDERR.puts context end end |
Instance Method Details
#run! ⇒ Object
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 |
# File 'lib/phtools/runner.rb', line 45 def run! return if STDIN.tty? ARGV.clear process_before ARGF.each_line do |line| filename = line.chomp begin PhFile.validate_file!(filename, @file_type) phfile = PhFile.new(filename) @os.output process_file(phfile) rescue PhTools::Error => e PhTools.puts_error "ERROR: '#{filename}' - #{e.message}", e end end process_after rescue SignalException PhTools.puts_error 'EXIT on user interrupt Ctrl-C' exit 1 rescue => e PhTools.puts_error "FATAL: #{e.message}", e exit 1 end |