Skip to content

Commit

Permalink
env fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
copiousfreetime committed May 3, 2024
1 parent 70074ca commit be249b1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions lib/launchy.rb
Expand Up @@ -86,15 +86,15 @@ def reset_global_options
Launchy.application = nil
Launchy.host_os = nil
Launchy.dry_run = false
Launchy.path = ENV["PATH"]
Launchy.path = ENV.fetch("PATH", nil)
end

def extract_global_options(options)
leftover = options.dup
Launchy.debug = leftover.delete(:debug) || ENV["LAUNCHY_DEBUG"]
Launchy.application = leftover.delete(:application) || ENV["LAUNCHY_APPLICATION"]
Launchy.host_os = leftover.delete(:host_os) || ENV["LAUNCHY_HOST_OS"]
Launchy.dry_run = leftover.delete(:dry_run) || ENV["LAUNCHY_DRY_RUN"]
Launchy.debug = leftover.delete(:debug) || ENV.fetch("LAUNCHY_DEBUG", nil)
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)
end

def debug=(enabled)
Expand All @@ -104,31 +104,31 @@ def debug=(enabled)
# we may do logging before a call to 'open', hence the need to check
# LAUNCHY_DEBUG here
def debug?
@debug || to_bool(ENV["LAUNCHY_DEBUG"])
@debug || to_bool(ENV.fetch("LAUNCHY_DEBUG", nil))
end

def application=(app)
@application = app
end

def application
@application || ENV["LAUNCHY_APPLICATION"]
@application || ENV.fetch("LAUNCHY_APPLICATION", nil)
end

def host_os=(host_os)
@host_os = host_os
end

def host_os
@host_os || ENV["LAUNCHY_HOST_OS"]
@host_os || ENV.fetch("LAUNCHY_HOST_OS", nil)
end

def dry_run=(dry_run)
@dry_run = to_bool(dry_run)
end

def dry_run?
@dry_run || to_bool(ENV["LAUNCHY_DRY_RUN"])
@dry_run || to_bool(ENV.fetch("LAUNCHY_DRY_RUN", nil))
end

def bug_report_message
Expand Down
4 changes: 2 additions & 2 deletions lib/launchy/detect/nix_desktop_environment.rb
Expand Up @@ -36,7 +36,7 @@ def self.browsers
# KDE desktop environment
class Kde < NixDesktopEnvironment
def self.is_current_desktop_environment?
ENV["KDE_FULL_SESSION"] &&
ENV.fetch("KDE_FULL_SESSION", nil) &&
Launchy::Application.find_executable("kde-open")
end

Expand All @@ -48,7 +48,7 @@ def self.browser
# Gnome desktop environment
class Gnome < NixDesktopEnvironment
def self.is_current_desktop_environment?
ENV["GNOME_DESKTOP_SESSION_ID"] &&
ENV.fetch("GNOME_DESKTOP_SESSION_ID", nil) &&
Launchy::Application.find_executable("gnome-open")
end

Expand Down
2 changes: 1 addition & 1 deletion spec/detect/host_os_family_spec.rb
Expand Up @@ -12,7 +12,7 @@
Launchy.reset_global_options
end

YAML.load_file(File.expand_path("../../tattle-host-os.yaml", __FILE__))["host_os"].keys.sort.each do |os|
YAML.load_file(File.expand_path("../tattle-host-os.yaml", __dir__))["host_os"].keys.sort.each do |os|
it "OS family of #{os} is detected" do
os_family = Launchy::Detect::HostOsFamily.detect(os)
_(os_family).must_be_kind_of Launchy::Detect::HostOsFamily
Expand Down

0 comments on commit be249b1

Please sign in to comment.