lib/kalipso/cli.rb in kalipso-0.1.6 vs lib/kalipso/cli.rb in kalipso-0.1.7
- old
+ new
@@ -1,18 +1,39 @@
module Kalipso
class CLI < Thor
+ desc "path", "print linked path for a site"
+ def path(name)
+ site = Site::Local.find_by_name(name)
+ if site.present?
+ if site.path.present?
+ puts site.path
+ else
+ puts "Path not present. You need to link this site to a path."
+ end
+ else
+ puts "Could not find site #{name}"
+ end
+ end
+
desc "create", "add a site"
- def create(name = nil)
- path = Dir.pwd
+ def create(name = nil, path = nil)
if name.present?
- puts "Creating #{name} linked to #{path}"
+ puts "Creating #{name}"
else
- puts "Creating a new site linked to #{path}"
+ puts "Creating a new site"
end
begin
- Site::Remote.create(:name => name)
+ remote_site = Site::Remote.create(:name => name)
+ path = path || File.expand_path("~/Sites/oncalypso/#{remote_site.name}")
+ Site::Local.create({
+ :name => remote_site.name,
+ :id => remote_site.id,
+ :path => path
+ })
+ Pathname.new(path).mkpath unless Pathname.new(path).exist?
+ puts "Site #{remote_site.name} site created and linked to #{path}"
rescue RestClient::UnprocessableEntity
puts "There was an error uploading your site"
end
end
@@ -30,10 +51,24 @@
puts out
end
end
end
+ desc "open", "open a site in browser"
+ def open(site = nil)
+ if site.present?
+ site = Site::Local.find_by_name(site)
+ else
+ site = Site::Local.find_by_path(Dir.pwd)
+ end
+ if site.present?
+ `open http://#{site.name}.oncalypso.com`
+ else
+ puts "Could not find site"
+ end
+ end
+
desc "link", "link a local path to a site"
def link(site, path = nil)
site = Site::Local.find_by_name(site)
path = path.present? ? File.expand_path(path) : Dir.pwd
site.update_attributes(:path => path)
@@ -74,11 +109,13 @@
puts "fetching #{site.name}"
local_site = Site::Local.find_or_create_by_id(site.id)
path = File.expand_path("~/Sites/oncalypso/#{name}")
pathname = Pathname.new(path)
pathname.mkpath unless pathname.exist?
- local_site.update_attributes(site.attributes.merge(:path => path))
+ local_site.name = site.name
+ local_site.path = path
+ local_site.save
`rsync -arvH -e "ssh -i #{Jaysus::Local.store_dir.join('keys', 'id_rsa')}" sites@diddlydum.com:/home/sites/#{site.name}/ #{path.gsub(/\/+$/, '')}/`
puts "Site #{name} downloaded to #{path.gsub(/\/+$/, '')}"
else
"Site #{name} not found. Maybe try 'kalipso sync'"
end
@@ -105,8 +142,13 @@
puts "You need to link this site first"
end
else
puts "site not found with path #{path}"
end
+ end
+
+ desc "version", "print the version of the kalipso gem"
+ def version
+ puts File.read(File.expand_path('../../../VERSION', __FILE__))
end
end
end
\ No newline at end of file