lib/sunzi/cli.rb in sunzi-0.1.0 vs lib/sunzi/cli.rb in sunzi-0.2.0
- old
+ new
@@ -13,40 +13,32 @@
def source_root
File.expand_path('../../',__FILE__)
end
end
- map "c" => :create
- map "d" => :deploy
+ # map "cr" => :create
+ # map "d" => :deploy
- desc "create [PROJECT]", "Create sunzi project (Shortcut: c)"
+ desc "create [PROJECT]", "Create sunzi project"
def create(project = 'sunzi')
empty_directory project
empty_directory "#{project}/remote"
empty_directory "#{project}/remote/recipes"
template "templates/attributes.yml", "#{project}/attributes.yml"
+ template "templates/recipes.yml", "#{project}/recipes.yml"
template "templates/remote/install.sh", "#{project}/remote/install.sh"
template "templates/remote/recipes/ssh_key.sh", "#{project}/remote/recipes/ssh_key.sh"
end
- desc "deploy [USER@HOST] [PORT]", "Deploy sunzi project (Shortcut: d)"
+ desc "deploy [USER@HOST] [PORT]", "Deploy sunzi project"
def deploy(*target)
if target.empty? or !target.first.match(/@/)
- puts "Usage: sunzi deploy root@example.com"
+ say shell.set_color("Usage: sunzi deploy root@example.com", :red, true)
abort
end
- # Compile attributes.yml
- unless File.exists?('attributes.yml')
- puts "You must be in the sunzi folder"
- abort
- end
- hash = YAML.load(File.read('attributes.yml'))
- FileUtils.mkdir_p('remote/attributes')
- hash.each do |key, value|
- File.open("remote/attributes/#{key}", 'w'){|file| file.write(value) }
- end
+ compile
host, port = target
port ||= 22
user, domain = host.split('@')
@@ -73,7 +65,29 @@
end
t.join
end
end
+ desc "compile", "Compile sunzi project"
+ def compile
+ # Check if you're in the sunzi directory
+ unless File.exists?('attributes.yml')
+ say shell.set_color("You must be in the sunzi folder", :red, true)
+ abort
+ end
+
+ # Compile attributes.yml
+ hash = YAML.load(File.read('attributes.yml'))
+ empty_directory 'remote/attributes'
+ hash.each do |key, value|
+ File.open("remote/attributes/#{key}", 'w'){|file| file.write(value) }
+ end
+
+ # Compile recipes.yml
+ hash = YAML.load(File.read('recipes.yml'))
+ empty_directory 'remote/recipes'
+ hash.each do |key, value|
+ get value, "remote/recipes/#{key}.sh"
+ end
+ end
end
end