From b664f4979cf1433f23e15449bebcfa02d891f409 Mon Sep 17 00:00:00 2001 From: John Britton Date: Mon, 3 Dec 2012 20:13:23 +0800 Subject: [PATCH 1/3] Create "add" task for adding new domains to Swot --- Rakefile | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Rakefile b/Rakefile index 9a330a5acd..06fde60933 100644 --- a/Rakefile +++ b/Rakefile @@ -43,3 +43,15 @@ Rake::RDocTask.new do |rdoc| rdoc.rdoc_files.include('README*') rdoc.rdoc_files.include('lib/**/*.rb') end + +task :add, :sld, :tld, :name do |t, args| + file_path = "#{File.expand_path(__FILE__+'/..')}/lib/domains/#{args.tld}/#{args.sld}" + unless File.exists?(file_path) + FileUtils.mkdir_p(File.dirname(file_path)) + File.open( file_path, "w" ) do |contents| + contents.print args.name + end + `git add #{file_path}` + `git commit -m "Add #{args.name}"` + end +end \ No newline at end of file From 4c1700429f07b55535b90eefdb8eaae98430dc44 Mon Sep 17 00:00:00 2001 From: John Britton Date: Mon, 3 Dec 2012 20:18:37 +0800 Subject: [PATCH 2/3] Add Google School --- lib/domains/edus/mit | 1 + 1 file changed, 1 insertion(+) create mode 100644 lib/domains/edus/mit diff --git a/lib/domains/edus/mit b/lib/domains/edus/mit new file mode 100644 index 0000000000..21ff62dbf2 --- /dev/null +++ b/lib/domains/edus/mit @@ -0,0 +1 @@ +Google School \ No newline at end of file From c0b22e1a336b7f3b1c3704a3710dbd8117039a8e Mon Sep 17 00:00:00 2001 From: John Britton Date: Tue, 4 Dec 2012 03:03:58 +0800 Subject: [PATCH 3/3] add error handling and some output for the user --- Rakefile | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Rakefile b/Rakefile index 06fde60933..9fdf50fee7 100644 --- a/Rakefile +++ b/Rakefile @@ -46,12 +46,19 @@ end task :add, :sld, :tld, :name do |t, args| file_path = "#{File.expand_path(__FILE__+'/..')}/lib/domains/#{args.tld}/#{args.sld}" - unless File.exists?(file_path) - FileUtils.mkdir_p(File.dirname(file_path)) - File.open( file_path, "w" ) do |contents| - contents.print args.name + if File.exists?(file_path) + puts "already exists" + elsif + begin + FileUtils.mkdir_p(File.dirname(file_path)) + File.open( file_path, "w" ) do |contents| + contents.print args.name + end + `git add #{file_path}` + `git commit -m "Add #{args.name}"` + puts "commit successful" + rescue + puts "commit failed" end - `git add #{file_path}` - `git commit -m "Add #{args.name}"` end end \ No newline at end of file