Module: SimpleCov::CLI::Open

Extended by:
CommandHelpers, Open
Included in:
Open
Defined in:
lib/simplecov/cli/open.rb

Constant Summary

Constants included from CommandHelpers

CommandHelpers::STATS_ROW_FORMAT

Instance Method Summary collapse

Methods included from CommandHelpers

build_parser, command_name, common_options, error, error_nil, on_help, one?, parse_common, quiet_option, recorded_contexts, stats_row

Instance Method Details

#browser_openerObject

The argv for the platform's "open this file" command, or nil if the host OS isn't recognized. On Windows, start is a cmd.exe builtin rather than an executable, so it routes through cmd /c; the empty string is the window-title positional start takes before the path, so a quoted path isn't mis-parsed as the title.



36
37
38
39
40
41
42
# File 'lib/simplecov/cli/open.rb', line 36

def browser_opener
  case RbConfig::CONFIG.fetch("host_os")
  when /darwin/ then ["open"]
  when /mswin|mingw|cygwin/ then ["cmd", "/c", "start", ""]
  when /linux|bsd|solaris/ then ["xdg-open"]
  end
end

#parse(args) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/simplecov/cli/open.rb', line 23

def parse(args)
  path = CLI.default_report
  build_parser do |o|
    o.on("--report PATH") { |v| path = v }
  end.parse(args)
  path
end

#run(args, stderr:) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/simplecov/cli/open.rb', line 13

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.fetch("host_os")}") unless opener

  system(*opener, path) ? 0 : 1
end