summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorRyan Davis <ryand@zenspider.com>2011-01-11 19:35:06 -0800
committerRyan Davis <ryand@zenspider.com>2011-01-11 19:35:06 -0800
commit1b5844b36da0bb3de84dea95eebb51bcbdf4eb8f (patch)
tree4ca91f28d0bc9348eca10f43d20f22ea84e2ead3 /bin
parenta7a2093eee8500845415416d7f4cc21614d3c707 (diff)
downloadhoe-1b5844b36da0bb3de84dea95eebb51bcbdf4eb8f.tar.gz
+ Added support for multiple template dirs for sow.
[git-p4: depot-paths = "//src/hoe/dev/": change = 6124]
Diffstat (limited to 'bin')
-rwxr-xr-xbin/sow65
1 files changed, 52 insertions, 13 deletions
diff --git a/bin/sow b/bin/sow
index 3cb98fd..32783ab 100755
--- a/bin/sow
+++ b/bin/sow
@@ -1,21 +1,48 @@
-#!/usr/bin/env ruby -ws
-
-$h ||= false
-$t ||= false
-$d ||= false
+#!/usr/bin/env ruby -w
+require 'optparse'
require 'rubygems'
require 'hoe'
require 'fileutils'
require 'erb'
-if $h || ARGV.empty? || ($t && $d) then
- puts "usage: #{File.basename $0} [-d|-t] project"
- puts " -t = add project to subdir under 'trunk'"
- puts " -d = add project to subdir under 'dev'"
- exit
+option = {
+ :style => "default",
+ :subdir => nil,
+}
+
+def check_subdir
+ if option[:subdir] then
+ warn "ERROR: you can't specify multiple subdirs"
+ abort opts.to_s
+ end
end
+OptionParser.new do |opts|
+ opts.separator "Standard options:"
+
+ opts.on("-t", "--trunk", "Add project to subdir under 'trunk'.") do
+ check_subdir
+ option[:subdir] = "trunk"
+ end
+
+ opts.on("-d", "--dev", "Add project to subdir under 'dev'.") do
+ check_subdir
+ option[:subdir] = "dev"
+ end
+
+ opts.on("-s style", "--style style", String, "Use template <style>.") do |s|
+ option[:style] = s
+ end
+
+ opts.on("-h", "--help", "Show this message.") do
+ puts opts
+ exit
+ end
+end.parse!
+
+# TODO: fail if both dev and trunk
+
include FileUtils::Verbose
project = ARGV.shift
@@ -25,11 +52,23 @@ abort "Project #{project} seems to exist" if test ?d, project
# variables for erb:
XIF = 'FI' + 'X' # prevents extra hits on my TAG reporter
project, file_name, klass = Hoe.normalize_names project
-template_path = File.expand_path("~/.hoe_template")
+template_dir = File.expand_path("~/.hoe_template")
+template_path = File.join template_dir, option[:style]
source_path = File.join(File.dirname(File.dirname(__FILE__)),
"template")
+default_dir = File.join template_dir, "default"
+if File.directory? template_dir and not File.directory? default_dir then
+ warn "Detected old #{template_dir}"
+ warn "Moving to #{default_dir}"
+ tmp = "#{template_dir}.#{$$}"
+ File.rename template_dir, tmp
+ FileUtils.mkdir template_dir
+ File.rename tmp, default_dir
+end
+
unless File.directory? template_path then
+ warn "Creating missing #{option[:style]} template."
FileUtils.cp_r source_path, template_path
paths = (Dir["#{template_path}/**/*"] +
Dir["#{template_path}/**/.*"]).select { |f| File.file? f }
@@ -62,11 +101,11 @@ Dir.chdir project do
end
end
-if $d || $t then
+if option[:dev] || option[:trunk] then
temp_dir = "#{project}.#{$$}"
FileUtils.mv project, temp_dir
FileUtils.mkdir project
- FileUtils.mv temp_dir, "#{project}/#{$d ? 'dev' : 'trunk'}"
+ FileUtils.mv temp_dir, "#{project}/#{option[:dev] ? 'dev' : 'trunk'}"
end
puts