Module: SimpleCov::CLI::Open
| Relationships & Source Files | |
| Defined in: | lib/simplecov/cli/open.rb |
Overview
simplecov open [--report PATH] — open the HTML report in the
platform's default browser. Tiny QoL wrapper around xdg-open /
open / SimpleCov.start so users don't have to type a file:// URL.
Class Method Summary
-
.browser_opener
mod_func
Returns the argv for the platform's "open this file" command, or nil if the host OS isn't recognized.
- .error(stderr, message) mod_func
- .parse(args) mod_func
- .run(args, stderr:) mod_func
Class Method Details
.browser_opener (mod_func)
Returns the argv for the platform's "open this file" command, or
nil if the host OS isn't recognized. On Windows, SimpleCov.start is a
cmd.exe builtin (not an executable), so route through cmd /c;
the empty string is the window-title positional SimpleCov.start takes
before the path so a quoted path isn't mis-parsed as the title.
# File 'lib/simplecov/cli/open.rb', line 41
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
.error(stderr, message) (mod_func)
[ GitHub ]# File 'lib/simplecov/cli/open.rb', line 23
def error(stderr, ) stderr.puts("simplecov open: #{}") 1 end
.parse(args) (mod_func)
[ GitHub ]# File 'lib/simplecov/cli/open.rb', line 28
def parse(args) path = SimpleCov::CLI.default_report OptionParser.new do |o| o.on("--report PATH") { |v| path = v } end.parse(args) path end
.run(args, stderr:) (mod_func)
[ GitHub ]# 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['host_os']}") unless opener system(*opener, path) ? 0 : 1 end