Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion launchy.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 8 additions & 5 deletions lib/launchy.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require "English"
require "addressable/uri"
require "shellwords"
require "stringio"
Expand All @@ -27,23 +26,26 @@ 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

app = app_for_uri(uri) if app.nil?

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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/launchy/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions lib/launchy/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tasks/this.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down