diff --git a/launchy.gemspec b/launchy.gemspec index f403fb8..3ba62ac 100644 --- a/launchy.gemspec +++ b/launchy.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |s| s.homepage = "https://github.com/copiousfreetime/launchy".freeze s.licenses = ["ISC".freeze] s.rdoc_options = ["--main".freeze, "README.md".freeze, "--markup".freeze, "tomdoc".freeze] - s.required_ruby_version = Gem::Requirement.new(">= 2.3.0".freeze) + s.required_ruby_version = Gem::Requirement.new(">= 2.5.0".freeze) s.rubygems_version = "3.6.3".freeze s.summary = "Launchy is helper class for launching cross-platform applications in a fire and forget manner.".freeze diff --git a/lib/launchy.rb b/lib/launchy.rb index 032fb44..5bcee63 100644 --- a/lib/launchy.rb +++ b/lib/launchy.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require "English" require "addressable/uri" require "shellwords" require "stringio" @@ -27,9 +26,10 @@ class << self # Launch an application for the given uri string # def open(uri_s, options = {}) + handled_error = nil leftover = extract_global_options(options) uri = string_to_uri(uri_s) - if (name = options[:application]) + if (name = Launchy.application) app = app_for_name(name) end @@ -37,13 +37,15 @@ def open(uri_s, options = {}) app.new.open(uri, leftover) rescue Launchy::Error => e + handled_error = e raise e rescue StandardError => e msg = "Failure in opening uri #{uri_s.inspect} with options #{options.inspect}: #{e}" - raise Launchy::Error, msg + handled_error = Launchy::Error.new(msg) + raise handled_error ensure - if $ERROR_INFO && block_given? - yield $ERROR_INFO + if handled_error && block_given? + yield handled_error # explicitly return here to swallow the errors if there was an error # and we yielded to the block @@ -94,6 +96,7 @@ def extract_global_options(options) Launchy.application = leftover.delete(:application) || ENV.fetch("LAUNCHY_APPLICATION", nil) Launchy.host_os = leftover.delete(:host_os) || ENV.fetch("LAUNCHY_HOST_OS", nil) Launchy.dry_run = leftover.delete(:dry_run) || ENV.fetch("LAUNCHY_DRY_RUN", nil) + leftover end def debug=(enabled) diff --git a/lib/launchy/application.rb b/lib/launchy/application.rb index f188d4a..d1863b2 100644 --- a/lib/launchy/application.rb +++ b/lib/launchy/application.rb @@ -41,7 +41,7 @@ def for_name(name) # # returns the path to the executable or nil if not found def find_executable(bin, *paths) - paths = Launchy.path.split(File::PATH_SEPARATOR) if paths.empty? + paths = Launchy.path.to_s.split(File::PATH_SEPARATOR) if paths.empty? paths.each do |path| file = File.join(path, bin) if File.executable?(file) diff --git a/lib/launchy/cli.rb b/lib/launchy/cli.rb index d44cc24..e5555aa 100644 --- a/lib/launchy/cli.rb +++ b/lib/launchy/cli.rb @@ -63,8 +63,9 @@ def parse(argv, _env) def good_run(argv, env) return false unless parse(argv, env) - Launchy.open(argv.shift, options) { |e| error_output(e) } - true + success = true + Launchy.open(argv.shift, options) { |e| success = error_output(e) } + success end def error_output(error) diff --git a/tasks/this.rb b/tasks/this.rb index 5c1f71a..85a1231 100644 --- a/tasks/this.rb +++ b/tasks/this.rb @@ -147,7 +147,7 @@ def core_gemspec spec.rdoc_options = ["--main", "README.md", "--markup", "tomdoc",] - spec.required_ruby_version = ">= 2.3.0" + spec.required_ruby_version = ">= 2.5.0" end end