pulsar 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format
3
+ nested
data/Rakefile CHANGED
@@ -1 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ task "default" => "spec"
5
+
6
+ RSpec::Core::RakeTask.new do |t|
7
+ t.pattern = 'spec/**/*_spec.rb'
8
+ end
data/bin/pulsar CHANGED
@@ -2,51 +2,4 @@
2
2
 
3
3
  require 'pulsar'
4
4
 
5
- class PulsarCommand < Clamp::Command
6
- include Pulsar::Helpers::Clamp
7
-
8
- option [ "-v", "--verbose" ], :flag,
9
- "Print out all the things!!!",
10
- :default => false
11
-
12
- option [ "-k", "--keep-capfile" ], :flag,
13
- "Dont't remove the generated capfile in the /tmp/ directory.",
14
- :default => false
15
-
16
- option [ "-l", "--log-level" ], "LOG LEVEL",
17
- "How much output will Capistrano spit out. Can be any of: important, info, debug.",
18
- :default => "important"
19
-
20
- option [ "-c", "--conf-repo" ], "REPO URL",
21
- "A git repository with deploy configurations, mainly apps and recipes.",
22
- :required => true
23
-
24
- option [ "-b", "--conf-branch" ], "REPO BRANCH",
25
- "Specify a branch for the configuration repository.",
26
- :default => "master"
27
-
28
- parameter "APPLICATION", "The application which you would like to deploy. For example: nebulab"
29
- parameter "ENVIRONMENT", "The environment on which you would like to deploy. For example: production" do |env|
30
- %w(production staging development).include?(env) ? env : raise(ArgumentError)
31
- end
32
- parameter "[TASKS] ...", "The tasks that will be passed to the final `cap` command. For example: --tasks, deploy, deploy:check", :default => "deploy"
33
-
34
- def execute
35
- target = "#{application}:#{environment}"
36
-
37
- ::Bundler.with_clean_env do
38
- fetch_repo
39
- bundle_install
40
- create_capfile
41
- build_capfile(target)
42
-
43
- cap_args = [tasks_list].flatten.join(" ")
44
- run_capistrano(cap_args)
45
-
46
- remove_capfile unless keep_capfile?
47
- remove_repo
48
- end
49
- end
50
- end
51
-
52
- PulsarCommand.run
5
+ Pulsar::MainCommand.run
data/lib/pulsar.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  require "pulsar/version"
2
2
 
3
3
  module Pulsar
4
+ require 'bundler'
4
5
  require "clamp"
5
6
  require "pulsar/helpers/clamp"
6
7
  require "pulsar/helpers/capistrano"
8
+ require "pulsar/commands/all"
7
9
  end
@@ -0,0 +1,5 @@
1
+ module Pulsar
2
+ autoload :MainCommand, "pulsar/commands/main"
3
+ autoload :CapCommand, "pulsar/commands/cap"
4
+ autoload :ListCommand, "pulsar/commands/list"
5
+ end
@@ -0,0 +1,42 @@
1
+ module Pulsar
2
+ class CapCommand < MainCommand
3
+ option [ "-k", "--keep-capfile" ], :flag,
4
+ "don't remove the generated capfile in the /tmp/ directory",
5
+ :default => false
6
+
7
+ option [ "-l", "--log-level" ], "LOG LEVEL",
8
+ "how much output will Capistrano print out. Can be any of: important, info, debug",
9
+ :default => "important"
10
+
11
+ option [ "-c", "--conf-repo" ], "REPO URL",
12
+ "a git repository with deploy configurations, mainly apps and recipes",
13
+ :required => true
14
+
15
+ option [ "-b", "--conf-branch" ], "REPO BRANCH",
16
+ "specify a branch for the configuration repository",
17
+ :default => "master"
18
+
19
+ parameter "APPLICATION", "the application which you would like to deploy"
20
+ parameter "ENVIRONMENT", "the environment on which you would like to deploy" do |env|
21
+ %w(production staging development).include?(env) ? env : raise(ArgumentError)
22
+ end
23
+ parameter "[TASKS] ...", "the tasks/args that will be passed to the final `cap` command", :default => "deploy"
24
+
25
+ def execute
26
+ target = "#{application}:#{environment}"
27
+
28
+ Bundler.with_clean_env do
29
+ fetch_repo
30
+ bundle_install
31
+ create_capfile
32
+ build_capfile(target)
33
+
34
+ cap_args = [tasks_list].flatten.join(" ")
35
+ run_capistrano(cap_args)
36
+
37
+ remove_capfile unless keep_capfile?
38
+ remove_repo
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,26 @@
1
+ module Pulsar
2
+ class ListCommand < MainCommand
3
+ option [ "-k", "--keep-capfile" ], :flag,
4
+ "don't remove the generated capfile in the /tmp/ directory",
5
+ :default => false
6
+
7
+ option [ "-c", "--conf-repo" ], "REPO URL",
8
+ "a git repository with deploy configurations, mainly apps and recipes",
9
+ :required => true
10
+
11
+ option [ "-b", "--conf-branch" ], "REPO BRANCH",
12
+ "specify a branch for the configuration repository",
13
+ :default => "master"
14
+
15
+ def execute
16
+ Bundler.with_clean_env do
17
+ fetch_repo
18
+
19
+ list_apps
20
+
21
+ remove_capfile unless keep_capfile?
22
+ remove_repo
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ module Pulsar
2
+ class MainCommand < Clamp::Command
3
+ include Pulsar::Helpers::Clamp
4
+
5
+ #
6
+ # Global options
7
+ #
8
+ option [ "-V", "--version" ], :flag, "print out pulsar version" do
9
+ puts(VERSION)
10
+ exit(0)
11
+ end
12
+
13
+ option [ "-v", "--verbose" ], :flag, "print out what pulsar is doing", :default => false
14
+
15
+ #
16
+ # Sub commands
17
+ #
18
+ subcommand "cap", "build a capfile from configuration repo and execute the cap command on it", CapCommand
19
+ subcommand "list", "list all available apps and environments which you can deploy", ListCommand
20
+ end
21
+ end
@@ -36,8 +36,9 @@ module Pulsar
36
36
  end
37
37
 
38
38
  def fetch_repo
39
+ repo = !conf_repo.include?(':') ? "git@github.com:#{conf_repo}.git" : conf_repo
39
40
  git_options = "--quiet --depth=1 --branch #{conf_branch}"
40
- run_cmd("git clone #{git_options} #{conf_repo} #{config_path}", :verbose => verbose?)
41
+ run_cmd("git clone #{git_options} #{repo} #{config_path}", :verbose => verbose?)
41
42
  end
42
43
 
43
44
  def include_app(app, stage=nil)
@@ -71,6 +72,26 @@ module Pulsar
71
72
  run_cmd("cat #{config_path}/apps/base.rb >> #{capfile_path}", :verbose => verbose?)
72
73
  end
73
74
 
75
+ def list_apps
76
+ apps = Dir["#{config_path}/apps/*"].each do |app|
77
+ if File.directory?(app)
78
+ app_name = File.basename(app)
79
+ app_envs = []
80
+
81
+ Dir["#{app}/*"].each do |env|
82
+ environments = %w(development staging production)
83
+ env_name = File.basename(env, '.rb')
84
+
85
+ if environments.include?(env_name)
86
+ app_envs << env_name
87
+ end
88
+ end
89
+
90
+ puts "#{app_name}: #{app_envs.join(', ')}"
91
+ end
92
+ end
93
+ end
94
+
74
95
  def remove_capfile
75
96
  rm_rf(capfile_path, :verbose => verbose?)
76
97
  end
@@ -1,3 +1,3 @@
1
1
  module Pulsar
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/pulsar.gemspec CHANGED
@@ -22,4 +22,9 @@ Gem::Specification.new do |gem|
22
22
  gem.require_paths = ["lib"]
23
23
 
24
24
  gem.add_dependency "clamp", "~> 0.5"
25
+ gem.add_dependency "bundler", "~> 1.2"
26
+
27
+ gem.add_development_dependency "rake"
28
+ gem.add_development_dependency "rspec", "~> 2.12"
29
+ gem.add_development_dependency "rr", "~> 1.0"
25
30
  end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pulsar::MainCommand do
4
+ include OutputCapture
5
+
6
+ context "with required arguments" do
7
+ before do
8
+ @pulsar = Pulsar::CapCommand.new("cap")
9
+ @pulsar.parse(%w(-c repo.com project development))
10
+ end
11
+
12
+ it "should set variables correctly" do
13
+ @pulsar.conf_repo.should == "repo.com"
14
+ @pulsar.application.should == "project"
15
+ @pulsar.environment.should == "development"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ require "rspec"
2
+ require "pulsar"
3
+ require 'stringio'
4
+
5
+ RSpec.configure do |config|
6
+ config.mock_with :rr
7
+ end
8
+
9
+ module OutputCapture
10
+ def self.included(target)
11
+ target.before do
12
+ $stdout = @out = StringIO.new
13
+ $stderr = @err = StringIO.new
14
+ end
15
+
16
+ target.after do
17
+ $stdout = STDOUT
18
+ $stderr = STDERR
19
+ end
20
+ end
21
+
22
+ def stdout
23
+ @out.string
24
+ end
25
+
26
+ def stderr
27
+ @err.string
28
+ end
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pulsar
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:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-12-25 00:00:00.000000000 Z
13
+ date: 2012-12-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: clamp
@@ -28,6 +28,70 @@ dependencies:
28
28
  - - ~>
29
29
  - !ruby/object:Gem::Version
30
30
  version: '0.5'
31
+ - !ruby/object:Gem::Dependency
32
+ name: bundler
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: '1.2'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '1.2'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: rspec
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: '2.12'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: '2.12'
79
+ - !ruby/object:Gem::Dependency
80
+ name: rr
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ~>
85
+ - !ruby/object:Gem::Version
86
+ version: '1.0'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: '1.0'
31
95
  description: NebuLab's central capistrano deploy resource.
32
96
  email:
33
97
  - info@nebulab.it
@@ -37,6 +101,7 @@ extensions: []
37
101
  extra_rdoc_files: []
38
102
  files:
39
103
  - .gitignore
104
+ - .rspec
40
105
  - .rvmrc
41
106
  - Gemfile
42
107
  - LICENSE.txt
@@ -44,11 +109,17 @@ files:
44
109
  - Rakefile
45
110
  - bin/pulsar
46
111
  - lib/pulsar.rb
112
+ - lib/pulsar/commands/all.rb
113
+ - lib/pulsar/commands/cap.rb
114
+ - lib/pulsar/commands/list.rb
115
+ - lib/pulsar/commands/main.rb
47
116
  - lib/pulsar/helpers/capistrano.rb
48
117
  - lib/pulsar/helpers/clamp.rb
49
118
  - lib/pulsar/tasks/.gitkeep
50
119
  - lib/pulsar/version.rb
51
120
  - pulsar.gemspec
121
+ - spec/pulsar/commands_spec.rb
122
+ - spec/spec_helper.rb
52
123
  homepage: https://github.com/nebulab/pulsar
53
124
  licenses: []
54
125
  post_install_message:
@@ -61,12 +132,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
61
132
  - - ! '>='
62
133
  - !ruby/object:Gem::Version
63
134
  version: '0'
135
+ segments:
136
+ - 0
137
+ hash: 1849999196866319529
64
138
  required_rubygems_version: !ruby/object:Gem::Requirement
65
139
  none: false
66
140
  requirements:
67
141
  - - ! '>='
68
142
  - !ruby/object:Gem::Version
69
143
  version: '0'
144
+ segments:
145
+ - 0
146
+ hash: 1849999196866319529
70
147
  requirements: []
71
148
  rubyforge_project:
72
149
  rubygems_version: 1.8.24
@@ -75,4 +152,6 @@ specification_version: 3
75
152
  summary: A simple gem that parses capistrano configuration froma another (private)
76
153
  repository providing a simple solution to managing multiple systems without installing
77
154
  capistrano configurations in each app.
78
- test_files: []
155
+ test_files:
156
+ - spec/pulsar/commands_spec.rb
157
+ - spec/spec_helper.rb