Permalink
Browse files

Merge pull request #433 from frvi/master

Possible to skip overwrites when installing widget.
  • Loading branch information...
2 parents 203abd6 + 8fe3a7e commit 1582eb981d529580c2cc632dfe2dbb9a57f67e3a @pushmatrix pushmatrix committed Jun 8, 2015
Showing with 10 additions and 10 deletions.
  1. +6 −6 lib/dashing/cli.rb
  2. +4 −4 test/cli_test.rb
View
@@ -38,12 +38,12 @@ def generate(type, name)
puts "Invalid generator. Either use widget, dashboard, or job"
end
- desc "install GIST_ID", "Installs a new widget from a gist."
- def install(gist_id)
+ desc "install GIST_ID [--skip]", "Installs a new widget from a gist (skip overwrite)."
+ def install(gist_id, *args)
gist = Downloader.get_gist(gist_id)
public_url = "https://gist.github.com/#{gist_id}"
- install_widget_from_gist(gist)
+ install_widget_from_gist(gist, args.include?('--skip'))
print set_color("Don't forget to edit the ", :yellow)
print set_color("Gemfile ", :yellow, :bold)
@@ -89,15 +89,15 @@ def run_command(command)
system(command)
end
- def install_widget_from_gist(gist)
+ def install_widget_from_gist(gist, skip_overwrite)
gist['files'].each do |file, details|
if file =~ /\.(html|coffee|scss)\z/
widget_name = File.basename(file, '.*')
new_path = File.join(Dir.pwd, 'widgets', widget_name, file)
- create_file(new_path, details['content'])
+ create_file(new_path, details['content'], :skip => skip_overwrite)
elsif file.end_with?('.rb')
new_path = File.join(Dir.pwd, 'jobs', file)
- create_file(new_path, details['content'])
+ create_file(new_path, details['content'], :skip => skip_overwrite)
end
end
end
View
@@ -68,10 +68,10 @@ def test_install_task_calls_create_file_for_each_valid_file_in_gist
Dir.stubs(:pwd).returns('')
Dashing::Downloader.stubs(:get_gist).returns(JSON.parse(json_response))
- @cli.stubs(:create_file).with('/jobs/ruby_job.rb', 'some job content').once
- @cli.stubs(:create_file).with('/widgets/num/num.html', 'some html content').once
- @cli.stubs(:create_file).with('/widgets/num/num.scss', 'some sass content').once
- @cli.stubs(:create_file).with('/widgets/num/num.coffee', 'some coffee content').once
+ @cli.stubs(:create_file).with('/jobs/ruby_job.rb', 'some job content', {:skip => false}).once
+ @cli.stubs(:create_file).with('/widgets/num/num.html', 'some html content', {:skip => false}).once
+ @cli.stubs(:create_file).with('/widgets/num/num.scss', 'some sass content', {:skip => false}).once
+ @cli.stubs(:create_file).with('/widgets/num/num.coffee', 'some coffee content', {:skip => false}).once
capture_io { @cli.install(123) }
end

0 comments on commit 1582eb9

Please sign in to comment.