module Granify module Controller class Open < Controller::Base def files begin files = [] if !$request.custom.nil? && $request.custom.size > 0 # pull file list from CLI args $request.custom.each do |requested_file| files.push(requested_file) if File.exists? requested_file.to_s end else raise ::ArgumentError, "Command requires a list of files to open\ni.e. #{Granify::PACKAGE_NAME} open files file1.ext file2.ext file3.ext" end # we have some files, lets open them if files.size > 0 `$EDITOR -n #{files.join(' ')}` Notify.success("Opened #{files.size} file(s) in sublime text") else Notify.warning("The requested files (#{$request.custom.join(', ')}) could not be opened") end rescue => e Notify.error(e.message) end end def files_from_log begin files = [] if File.exists? $request.custom[0].to_s # pull file list from a log file files = IO.readlines($request.custom[0].to_s) files.each do |l| l.gsub!(/\r\n?/, "") end else raise ::ArgumentError, "Command requires a log file\ni.e. #{Granify::PACKAGE_NAME} open files_from_log file1.log" end if files.size > 0 `$EDITOR -n #{files.join(' ')}` Notify.success("Opened #{files.size} file(s) in sublime text") else Notify.warning("The requested files (#{$request.custom.join(', ')}) could not be opened") end rescue => e Notify.error(e.message) end end end end end