Class: Kalipso::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/kalipso/cli.rb

Instance Method Summary collapse

Instance Method Details

#base_urlObject



56
57
58
# File 'lib/kalipso/cli.rb', line 56

def base_url
  puts Jaysus::Remote.base_url
end

#create(name = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/kalipso/cli.rb', line 5

def create(name = nil)
  path = Dir.pwd
  if name.present?
    puts "Creating #{name} linked to #{path}"
  else
    puts "Creating a new site linked to #{path}"
  end
  begin
    Site::Remote.create(:name => name)
    
  rescue RestClient::UnprocessableEntity
    puts "There was an error uploading your site"
  end
end


36
37
38
39
40
41
# File 'lib/kalipso/cli.rb', line 36

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)
  puts "#{site.name} linked to #{path}"
end

#sitesObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/kalipso/cli.rb', line 21

def sites
  if Site::Local.all.empty?
    sync
  else
    Site::Local.all.each do |site|
      out = "".tap do |out|
        out << site.name
        out << " -> #{site.path}" if site.path.present?
      end
      puts out
    end
  end
end

#store_dirObject



51
52
53
# File 'lib/kalipso/cli.rb', line 51

def store_dir
  puts Jaysus::Local.store_dir
end

#syncObject



61
62
63
64
65
66
67
68
# File 'lib/kalipso/cli.rb', line 61

def sync
  puts "fetching remote sites"
  Site::Remote.all.each do |site|
    puts "syncing #{site.name}"
    local_site = Site::Local.find_or_create_by_id(site.id)
    local_site.update_attributes(site.attributes)
  end
end


44
45
46
47
48
# File 'lib/kalipso/cli.rb', line 44

def unlink(site)
  site = Site::Local.find_by_name(site)
  site.update_attributes(:path => "")
  puts "Site #{site.name} unlinked"
end

#upload(name = nil) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/kalipso/cli.rb', line 71

def upload(name = nil)
  if name.present?
    puts "uploading #{name}"
    site = Site::Local.find_by_name(name)
    path = site.path
  else
    path = File.expand_path(Dir.pwd)
    site = Site::Local.find_by_path(path)
  end
  if site.present?
    puts "uploading #{name} from #{path}"
    if site.path.present?
      puts "uploading #{site.path} to #{site.name}.oncalypso.com"
      `rsync -arvH #{site.path.gsub(/\/+$/, '')}/ [email protected]:/home/sites/#{site.name}`
      puts "#{site.path} uploaded to http://#{site.name}.oncalypso.com"
    else
      puts "You need to link this site first"
    end
  else
    puts "site not found with path #{path}"
  end
end