Skip to content

Commit

Permalink
Merge pull request #56 from mgrecar/feature/html_using_launchy
Browse files Browse the repository at this point in the history
Changed CLI to utilize Launchy to open the graph
  • Loading branch information
makaroni4 committed Aug 18, 2014
2 parents faa5557 + df375c0 commit 0321b08
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
.bundle
pkg
Gemfile.lock
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ source 'https://rubygems.org'

gemspec

gem 'mixlib-cli'

group :test do
gem 'rspec'
end
32 changes: 0 additions & 32 deletions Gemfile.lock

This file was deleted.

7 changes: 6 additions & 1 deletion lib/sandi_meter/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require 'sandi_meter/html_generator'
require 'yaml'
require 'json'
require 'launchy'

module SandiMeter
class CommandParser
Expand Down Expand Up @@ -111,7 +112,7 @@ def execute
html_generator.generate_details!(cli.config[:path], data)

index_html_path = File.join(cli.config[:path], 'sandi_meter/index.html')
system "open #{index_html_path}"
open_in_browser(index_html_path)
else
puts "WARNING!!! HTML mode works only if you scan folder."
end
Expand Down Expand Up @@ -154,6 +155,10 @@ def version_info
# stolen from gem 'bubs' :)
"SandiMeter ".tr('A-Za-z1-90', 'Ⓐ-Ⓩⓐ-ⓩ①-⑨⓪').split('').join(' ') + SandiMeter::VERSION
end

def open_in_browser(url)
Launchy.open(url)
end
end
end
end
2 changes: 2 additions & 0 deletions sandi_meter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec", "~> 2.13"

spec.add_runtime_dependency "mixlib-cli"
spec.add_runtime_dependency "json"
spec.add_runtime_dependency "launchy"
end
28 changes: 28 additions & 0 deletions spec/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'test_helper'
require_relative '../lib/sandi_meter/cli'

describe SandiMeter::CLI do
let(:cli) { SandiMeter::CLI }

describe '#execute' do
before do
@original_argv = ARGV
ARGV.clear
end

after do
ARGV.clear
ARGV.concat(@original_argv)
end

context 'with the graph flag passed in' do
before { ARGV.push('-g') }
after { ARGV.pop }

it 'opens the graph in a web browser' do
cli.should_receive(:open_in_browser)
expect { cli.execute }.to raise_error(SystemExit)
end
end
end
end

0 comments on commit 0321b08

Please sign in to comment.