class Kontena::Cli::BrowserLauncher
Attributes
url[R]
Public Class Methods
new(url)
click to toggle source
# File lib/kontena/cli/browser_launcher.rb, line 12 def initialize(url) @url = url end
open(url)
click to toggle source
# File lib/kontena/cli/browser_launcher.rb, line 6 def self.open(url) Kontena::Cli::BrowserLauncher.new(url).launch end
Public Instance Methods
command()
click to toggle source
# File lib/kontena/cli/browser_launcher.rb, line 20 def command cmd = if Kontena.on_windows? ['cmd', '/c', 'start', '/b', url.gsub(/&/, '^&')] elsif RUBY_PLATFORM =~ /darwin/ ["open", url] elsif Kontena.browserless? raise RuntimeError, "Environment variable DISPLAY not set, assuming non-desktop session, unable to open browser. Try using '--remote' option." else [detect_unixlike_command, url] end Kontena.logger.debug { "Using %p to launch browser" % cmd } cmd end
detect_unixlike_command()
click to toggle source
# File lib/kontena/cli/browser_launcher.rb, line 36 def detect_unixlike_command Kontena.logger.debug { "Assuming unix-like environment, looking for browser" } cmd = %w( xdg-open sensible-browser x-www-browser ).find { |c| !which(c).nil? } if cmd.nil? if ENV['BROWSER'] cmd = which(ENV['BROWSER']) return cmd unless cmd.nil? end raise RuntimeError, "Unable to launch a local browser. Try installing xdg-utils or sensible-utils package, setting BROWSER environment variable or using the --remote option" end cmd end
launch()
click to toggle source
# File lib/kontena/cli/browser_launcher.rb, line 16 def launch system(*command) end
which(cmd)
click to toggle source
# File lib/kontena/cli/browser_launcher.rb, line 56 def which(cmd) Kontena::Util.which(cmd) end