Module: SimpleCov::CLI::Open
- 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.
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.
- .error(stderr, message) ⇒ Object
- .parse(args) ⇒ Object
- .run(args, stderr:) ⇒ Object
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.
41 42 43 44 45 46 47 |
# 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) ⇒ Object
23 24 25 26 |
# File 'lib/simplecov/cli/open.rb', line 23 def error(stderr, ) stderr.puts("simplecov open: #{}") 1 end |
.parse(args) ⇒ Object
28 29 30 31 32 33 34 |
# 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:) ⇒ 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['host_os']}") unless opener system(*opener, path) ? 0 : 1 end |