Module: SimpleCov::CLI::Open
- Extended by:
- CommandHelpers
- 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 / start so users don't have to type a file:// URL.
Constant Summary
Constants included from CommandHelpers
CommandHelpers::STATS_ROW_FORMAT
Class Method Summary collapse
-
.browser_opener ⇒ Object
Returns the argv for the platform's "open this file" command, or nil if the host OS isn't recognized.
- .parse(args) ⇒ Object
- .run(args, stderr:) ⇒ Object
Methods included from CommandHelpers
command_name, common_options, error, parse_common, stats_row
Class Method Details
.browser_opener ⇒ Object
Returns 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 (not an executable), so route 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.
39 40 41 42 43 44 45 |
# File 'lib/simplecov/cli/open.rb', line 39 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 |
.parse(args) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/simplecov/cli/open.rb', line 26 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:) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/simplecov/cli/open.rb', line 16 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 |