module SimpleCov::CLI::Open
def browser_opener
the empty string is the window-title positional `start` takes
cmd.exe builtin (not an executable), so route through `cmd /c`;
nil if the host OS isn't recognized. On Windows, `start` is a
Returns the argv for the platform's "open this file" command, or
def browser_opener case RbConfig::CONFIG["host_os"] when /darwin/ then ["open"] when /mswin|mingw|cygwin/ then ["cmd", "/c", "start", ""] when /linux|bsd|solaris/ then ["xdg-open"] end end
def error(stderr, message)
def error(stderr, message) stderr.puts("simplecov open: #{message}") 1 end
def parse(args)
def parse(args) path = SimpleCov::CLI.default_report OptionParser.new do |o| o.on("--report PATH") { |v| path = v } end.parse(args) path end
def run(args, stderr:, **)
def run(args, stderr:, **) path = parse(args) return error(stderr, "#{path} not found") unless File.exist?(path) opener = browser_opener return error(stderr, "no known opener for #{RbConfig::CONFIG['host_os']}") unless opener system(*opener, path) ? 0 : 1 end