capo 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/capo CHANGED
@@ -8,14 +8,23 @@ option_parser = OptionParser.new do |option|
8
8
  option.banner = 'Usage: capo COMMAND [OPTIONS]'
9
9
  option.separator ''
10
10
  option.separator 'Commands'
11
- option.separator ' init: Clones and pulls the repository that contains the recipes'
11
+ option.separator ' init: Clones and pulls the repository that contains the recipes'
12
+ option.separator ' list: Lists all available recipes'
13
+ option.separator ' begin: Sets up capistrano for your project'
14
+ option.separator ' add: Adds recipe to your deploy setup'
15
+ option.separator ' added: Lists installed recipes of your deploy setup'
12
16
  option.separator ''
13
17
  option.separator 'Options'
14
18
 
15
19
  option.on('-h', '--help', 'help') do
16
- @help = true
20
+ @usage_shown = true
17
21
  puts option_parser
18
22
  end
23
+
24
+ option.on('-v', '--version', 'version') do
25
+ @usage_shown = true
26
+ puts Capo::VERSION
27
+ end
19
28
  end
20
29
 
21
30
  option_parser.parse!
@@ -23,6 +32,14 @@ option_parser.parse!
23
32
  case ARGV[0]
24
33
  when 'init'
25
34
  Capo::Init.fetch_repository
35
+ when 'begin'
36
+ Capo::Capfile.generate
37
+ when 'list'
38
+ Capo::Recipes.list
39
+ when 'add'
40
+ Capo::Recipes.add ARGV[1]
41
+ when 'added'
42
+ Capo::Recipes.added
26
43
  else
27
- puts option_parser unless @help
44
+ puts option_parser unless @usage_shown
28
45
  end
data/capo.gemspec CHANGED
@@ -17,5 +17,6 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ['lib']
19
19
 
20
+ gem.add_dependency 'capistrano', '>= 2.6.0'
20
21
  gem.add_dependency 'git'
21
22
  end
@@ -0,0 +1,57 @@
1
+ module Capo
2
+ module Capfile
3
+ class << self
4
+ def generate
5
+ files.each do |file, content|
6
+ file = File.join Capo.app_path, file
7
+ if File.exists?(file)
8
+ warn "[skip] '#{file}' already exists"
9
+ elsif File.exists?(file.downcase)
10
+ warn "[skip] '#{file.downcase}' exists, which could conflict with '#{file}'"
11
+ else
12
+ unless File.exists?(File.dirname(file))
13
+ puts "[add] making directory '#{File.dirname file}'"
14
+ FileUtils.mkdir File.dirname(file)
15
+ end
16
+ puts "[add] writing '#{file}'"
17
+ File.open(file, 'w'){|f| f.write content}
18
+ end
19
+ end
20
+ end
21
+
22
+ private
23
+ def capfile
24
+ <<-FILE
25
+ load 'deploy'
26
+
27
+ load 'config/deploy'
28
+ FILE
29
+ end
30
+
31
+ def config_deploy
32
+ <<-FILE
33
+ set :application, "set your application name here"
34
+ set :repository, "set your repository location here"
35
+ set :branch, "set your branch here"
36
+
37
+ role :web, "your web-server here" # Your HTTP server, Apache/etc
38
+ role :app, "your app-server here" # This may be the same as your `Web` server
39
+ role :db, "your primary db-server here", :primary => true # This is where Rails migrations will run
40
+ role :db, "your slave db-server here"
41
+ FILE
42
+ end
43
+
44
+ def files
45
+ {
46
+ "Capfile" => unindent(capfile),
47
+ "config/deploy.rb" => unindent(config_deploy)
48
+ }
49
+ end
50
+
51
+ def unindent string
52
+ indentation = string[/\A\s*/]
53
+ string.strip.gsub /^#{indentation}/, ''
54
+ end
55
+ end
56
+ end
57
+ end
data/lib/capo/init.rb CHANGED
@@ -4,17 +4,16 @@ module Capo
4
4
  module Init
5
5
  class << self
6
6
  def fetch_repository
7
- repository_path = File.expand_path '~/.capo'
8
7
  repository_url = 'git://github.com/capoio/capo.git'
9
8
 
10
9
  puts "Pulling changes from remote repository"
11
10
  begin
12
- repo = Git.open repository_path
11
+ repo = Git.open Capo.repository_path
13
12
  puts repo.lib.send :command, 'pull' # repo.pull is broken in git-1.2.5, see: https://github.com/schacon/ruby-git/issues/32
14
13
  rescue
15
- puts "Reposito doesn't seem to exist yet..."
16
- puts "Cloning repository from #{repository_url} to #{repository_path}"
17
- Git.clone repository_url, repository_path
14
+ puts "Repository doesn't seem to exist yet..."
15
+ puts "Cloning repository from #{repository_url} to #{Capo.repository_path}"
16
+ Git.clone repository_url, Capo.repository_path
18
17
  retry
19
18
  end
20
19
  end
@@ -0,0 +1,47 @@
1
+ module Capo
2
+ module Recipes
3
+ class << self
4
+ def list
5
+ longest_name_size = recipes.sort_by{|recipe| recipe[:name].size}.last[:name].size
6
+ recipes.each do |recipe|
7
+ name = recipe[:name]
8
+ puts "#{name}#{' ' * (longest_name_size - name.size)} #{recipe[:description]}"
9
+ end
10
+ end
11
+
12
+ def add name
13
+ raise "Recipe '#{name}' not found" unless recipes.map{|recipe| recipe[:name]}.include? name
14
+
15
+ app_recipe_path = File.join app_deploy_path, "#{name}.rb"
16
+
17
+ Dir.mkdir(app_deploy_path) unless Dir.exists?(app_deploy_path)
18
+
19
+ puts "Copying recipe '#{name}' to #{app_recipe_path}"
20
+ FileUtils.copy File.join(Capo.repository_path, 'recipes', name, "#{name}.rb"), app_recipe_path
21
+
22
+ puts "Adding line to Capfile"
23
+ capfile = File.join Capo.app_path, 'Capfile'
24
+ File.open(capfile, 'a+'){|f| f.puts "load 'config/deploy/#{name}'"}
25
+
26
+ puts "Recipe #{name} added"
27
+ end
28
+
29
+ def added
30
+ puts "Installed recipes:"
31
+ Dir[File.join(app_deploy_path, '*')].each do |recipe|
32
+ puts " * #{recipe.match(/config\/deploy\/(\w+).rb$/)[1]}"
33
+ end
34
+ end
35
+
36
+ private
37
+ def recipes
38
+ require File.join(Capo.repository_path, 'lib/raw_recipe')
39
+ RawRecipe.load_all
40
+ end
41
+
42
+ def app_deploy_path
43
+ File.join Capo.app_path, 'config/deploy'
44
+ end
45
+ end
46
+ end
47
+ end
data/lib/capo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Capo
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
data/lib/capo.rb CHANGED
@@ -3,7 +3,17 @@
3
3
  require 'capo/version'
4
4
 
5
5
  require 'capo/init'
6
+ require 'capo/recipes'
7
+ require 'capo/capfile'
6
8
 
7
9
  module Capo
8
- # Your code goes here...
10
+ class << self
11
+ def repository_path
12
+ File.expand_path '~/.capo'
13
+ end
14
+
15
+ def app_path
16
+ Dir.pwd
17
+ end
18
+ end
9
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,6 +14,22 @@ bindir: bin
14
14
  cert_chain: []
15
15
  date: 2012-10-14 00:00:00.000000000 Z
16
16
  dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: capistrano
19
+ requirement: !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ! '>='
23
+ - !ruby/object:Gem::Version
24
+ version: 2.6.0
25
+ type: :runtime
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 2.6.0
17
33
  - !ruby/object:Gem::Dependency
18
34
  name: git
19
35
  requirement: !ruby/object:Gem::Requirement
@@ -46,7 +62,9 @@ files:
46
62
  - bin/capo
47
63
  - capo.gemspec
48
64
  - lib/capo.rb
65
+ - lib/capo/capfile.rb
49
66
  - lib/capo/init.rb
67
+ - lib/capo/recipes.rb
50
68
  - lib/capo/version.rb
51
69
  homepage: http://capo.io
52
70
  licenses: []