auto_tagger 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +4 -1
  2. data/CHANGELOG +26 -2
  3. data/Gemfile +4 -4
  4. data/Gemfile.lock +60 -0
  5. data/README.md +90 -36
  6. data/Rakefile +1 -26
  7. data/VERSION +1 -1
  8. data/auto_tagger.gemspec +24 -14
  9. data/bin/autotag +14 -29
  10. data/features/autotag.feature +43 -2
  11. data/features/deployment.feature +4 -0
  12. data/features/step_definitions/autotag_steps.rb +27 -22
  13. data/features/step_definitions/deployment_steps.rb +41 -33
  14. data/features/support/env.rb +45 -2
  15. data/features/support/step_helpers.rb +36 -12
  16. data/features/templates/deploy.erb +1 -1
  17. data/lib/auto_tagger/base.rb +150 -19
  18. data/lib/auto_tagger/capistrano_helper.rb +38 -17
  19. data/lib/auto_tagger/command_line.rb +65 -0
  20. data/lib/auto_tagger/commander.rb +22 -11
  21. data/lib/auto_tagger/configuration.rb +88 -0
  22. data/lib/auto_tagger/deprecator.rb +11 -0
  23. data/lib/auto_tagger/git/ref.rb +34 -0
  24. data/lib/auto_tagger/git/ref_set.rb +35 -0
  25. data/lib/auto_tagger/git/repo.rb +76 -0
  26. data/lib/auto_tagger/options.rb +170 -0
  27. data/lib/auto_tagger/recipes.rb +67 -27
  28. data/lib/auto_tagger.rb +9 -4
  29. data/spec/auto_tagger/base_spec.rb +236 -52
  30. data/spec/auto_tagger/capistrano_helper_spec.rb +82 -112
  31. data/spec/auto_tagger/command_line_spec.rb +110 -0
  32. data/spec/auto_tagger/commander_spec.rb +33 -7
  33. data/spec/auto_tagger/configuration_spec.rb +275 -0
  34. data/spec/auto_tagger/git/ref_set_spec.rb +61 -0
  35. data/spec/auto_tagger/git/ref_spec.rb +46 -0
  36. data/spec/auto_tagger/git/repo_spec.rb +108 -0
  37. data/spec/auto_tagger/options_spec.rb +157 -0
  38. data/spec/spec_helper.rb +1 -6
  39. metadata +32 -15
  40. data/geminstaller.yml +0 -7
  41. data/lib/auto_tagger/repository.rb +0 -43
  42. data/lib/auto_tagger/stage_manager.rb +0 -23
  43. data/lib/auto_tagger/tag.rb +0 -43
  44. data/spec/auto_tagger/repository_spec.rb +0 -72
  45. data/spec/auto_tagger/stage_manager_spec.rb +0 -34
  46. data/spec/auto_tagger/tag_spec.rb +0 -66
@@ -1,28 +1,28 @@
1
1
  Given /^a repo$/ do
2
- puts
3
- helpers = StepHelpers.new
4
- helpers.create_git_repo
5
- helpers.create_app
6
- @tags = helpers.tags
7
- puts
2
+ with_or_without_debugging do
3
+ helpers = StepHelpers.new
4
+ helpers.create_git_repo
5
+ helpers.create_app
6
+ @refs = helpers.refs
7
+ end
8
8
  end
9
9
 
10
10
  When /^I run autotag with no arguments$/ do
11
- puts
12
- helpers = StepHelpers.new
13
- @output, @exit_code = helpers.run_autotag
14
- @tags = helpers.tags
15
- @exit_code = helpers.exit_code
16
- puts
11
+ with_or_without_debugging do
12
+ helpers = StepHelpers.new
13
+ @output, @exit_code = helpers.run_autotag
14
+ @refs = helpers.refs
15
+ @exit_code = helpers.exit_code
16
+ end
17
17
  end
18
18
 
19
19
  When /^I run autotag with "([^\"]*)"$/ do |args|
20
- puts
21
- helpers = StepHelpers.new
22
- @output, @exit_code = helpers.run_autotag(args)
23
- @tags = helpers.tags
24
- @exit_code = helpers.exit_code
25
- puts
20
+ with_or_without_debugging do
21
+ helpers = StepHelpers.new
22
+ @output = helpers.run_autotag(args)
23
+ @refs = helpers.refs
24
+ @exit_code = helpers.exit_code
25
+ end
26
26
  end
27
27
 
28
28
  Then /^I should see "([^\"]*)"$/ do |text|
@@ -34,18 +34,23 @@ Then /^the exit code should be "(\d+)"$/ do |code|
34
34
  end
35
35
 
36
36
  Then /^no tags should be created$/ do
37
- @tags.strip.should == ""
37
+ @refs.strip.should == ""
38
38
  end
39
39
 
40
40
  Then /^a "([^\"]*)" tag should be added to git$/ do |stage|
41
41
  helpers = StepHelpers.new
42
- helpers.tags.starts_with?(stage).should be_true
42
+ helpers.refs.split("\n").last.should match(/\/#{stage}\//)
43
43
  end
44
44
 
45
45
  Then /^a "([^\"]*)" tag should be created$/ do |prefix|
46
- @tags.strip.split("\n").any?{|tag| tag.starts_with?("demo")}.should be_true
46
+ @refs.strip.split("\n").any? { |ref| ref =~ /\/demo\// }.should be_true
47
+ end
48
+
49
+ Then /^a hyphen-delimited "([^\"]*)" tag should be created$/ do |prefix|
50
+ tag = @refs.strip.split("\n").detect { |ref| ref =~ /\/demo\// }
51
+ tag.split(" ").last.split("/").last.split("-").first.should == Date.today.year.to_s
47
52
  end
48
53
 
49
- Then /^exit code should be (\d*)$/ do |exit_code|
54
+ Then /^(?:the )?exit code should be (\d*)$/ do |exit_code|
50
55
  @exit_code.should == exit_code.to_i
51
56
  end
@@ -1,53 +1,61 @@
1
1
  Given /^a three-stage app using single deploy file$/ do
2
- puts
3
- helpers = StepHelpers.new
4
- helpers.create_app_with_single_deploy_file([:ci, :staging, :production])
5
- puts
6
- @tags = helpers.tags
2
+ with_or_without_debugging do
3
+ helpers = StepHelpers.new
4
+ helpers.create_app_with_single_deploy_file([:ci, :staging, :production])
5
+ @refs = helpers.refs
6
+ end
7
7
  end
8
8
 
9
9
  Given /^a one\-stage app using single deploy file with the following environments:$/ do |table|
10
- puts
11
- helpers = StepHelpers.new
12
- helpers.create_app_with_single_deploy_file table.raw.map(&:first)
13
- puts
14
- @tags = helpers.tags
10
+ with_or_without_debugging do
11
+ helpers = StepHelpers.new
12
+ helpers.create_app_with_single_deploy_file table.raw.map(&:first)
13
+ @refs = helpers.refs
14
+ end
15
15
  end
16
16
 
17
17
  Given /^a three-stage app using cap-multistage$/ do
18
- puts
19
- helpers = StepHelpers.new
20
- helpers.create_app_with_cap_ext_multistage
21
- puts
22
- @tags = helpers.tags
18
+ with_or_without_debugging do
19
+ helpers = StepHelpers.new
20
+ helpers.create_app_with_cap_ext_multistage
21
+ @refs = helpers.refs
22
+ end
23
+ end
24
+
25
+ Given /^an app with deploy file that uses the dsl$/ do
26
+ with_or_without_debugging do
27
+ helpers = StepHelpers.new
28
+ helpers.create_app_with_dsl
29
+ @refs = helpers.refs
30
+ end
23
31
  end
24
32
 
25
33
  Given /^a ci tag$/ do
26
- puts
27
- helpers = StepHelpers.new
28
- helpers.autotag("ci")
29
- @tags = helpers.tags
30
- puts
34
+ with_or_without_debugging do
35
+ helpers = StepHelpers.new
36
+ helpers.autotag("ci")
37
+ @refs = helpers.refs
38
+ end
31
39
  end
32
40
 
33
41
  When /^I deploy to (.*)$/ do |environment|
34
- puts
35
- helpers = StepHelpers.new
36
- helpers.deploy(environment)
37
- puts
42
+ with_or_without_debugging do
43
+ helpers = StepHelpers.new
44
+ helpers.deploy(environment)
45
+ end
38
46
  end
39
47
 
40
48
  When /^I deploy$/ do
41
- puts
42
- helpers = StepHelpers.new
43
- helpers.deploy
44
- puts
49
+ with_or_without_debugging do
50
+ helpers = StepHelpers.new
51
+ helpers.deploy
52
+ end
45
53
  end
46
54
 
47
55
  Then /^a tag should be added to git$/ do
48
- puts
49
- helpers = StepHelpers.new
50
- new_tags = helpers.tags
51
- @tags.length.should < new_tags.length
52
- puts
56
+ with_or_without_debugging do
57
+ helpers = StepHelpers.new
58
+ new_tags = helpers.refs
59
+ @refs.length.should < new_tags.length
60
+ end
53
61
  end
@@ -1,7 +1,50 @@
1
- require 'spec'
1
+ require 'rspec'
2
2
  require 'erb'
3
3
  require 'etc'
4
- require 'activesupport'
4
+
5
+ class String
6
+ def starts_with?(prefix)
7
+ self[0, prefix.length] == prefix
8
+ end
9
+ end
10
+
11
+ module Silencers
12
+
13
+ def with_or_without_debugging
14
+ if ENV['AUTO_TAGGER_DEBUG'] == "true"
15
+ puts
16
+ yield
17
+ puts
18
+ else
19
+ silence_stream(STDOUT) do
20
+ silence_stream(STDERR) do
21
+ silence_warnings do
22
+ yield
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ def silence_stream(stream)
30
+ old_stream = stream.dup
31
+ stream.reopen(RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'NUL:' : '/dev/null')
32
+ stream.sync = true
33
+ yield
34
+ ensure
35
+ stream.reopen(old_stream)
36
+ end
37
+
38
+ def silence_warnings
39
+ old_verbose, $VERBOSE = $VERBOSE, nil
40
+ yield
41
+ ensure
42
+ $VERBOSE = old_verbose
43
+ end
44
+
45
+ end
46
+
47
+ World(Silencers)
5
48
 
6
49
  Before do
7
50
  StepHelpers.new.reset
@@ -24,10 +24,19 @@ class StepHelpers
24
24
  create_single_deploy_file(environments)
25
25
  end
26
26
 
27
+ def create_app_with_dsl
28
+ create_git_repo
29
+ create_app
30
+ capify_app
31
+ create_dsl_deploy_file
32
+ end
33
+
27
34
  def run_autotag(args = nil)
28
35
  cmd = "cd #{app_dir} && ../../bin/autotag"
29
36
  cmd += " #{args}" if args
37
+ cmd += " 2>&1"
30
38
  output = `#{cmd}`
39
+ puts output
31
40
  @exit_code = $?.exitstatus
32
41
  return output
33
42
  end
@@ -55,11 +64,11 @@ class StepHelpers
55
64
  system "cd #{app_dir} && git tag #{stage}/#{Time.now.utc.strftime('%Y%m%d%H%M%S')} && git push origin --tags"
56
65
  end
57
66
 
58
- def tags
59
- system "cd #{app_dir} && git fetch origin --tags"
60
- tags = `cd #{app_dir} && git tag`
61
- puts tags
62
- tags
67
+ def refs(namespace = "tags")
68
+ system "cd #{app_dir} && git fetch origin refs/#{namespace}/*:refs/#{namespace}/*"
69
+ refs = `cd #{app_dir} && git show-ref | grep #{namespace}`
70
+ puts refs
71
+ refs
63
72
  end
64
73
 
65
74
  def create_app
@@ -86,22 +95,41 @@ class StepHelpers
86
95
  end
87
96
 
88
97
  def create_single_deploy_file(environments)
98
+
99
+ # ERB variables
89
100
  repository = repo_dir
90
101
  deploy_to = File.join(test_files_dir, "deployed")
91
102
  git_location = `which git`.strip
92
103
  user = Etc.getlogin
93
104
 
94
105
  path = File.expand_path(File.join(__FILE__, "..", "..", "templates", "deploy.erb"))
95
- #puts "TRACE %s:%s" % [__FILE__, __LINE__]
96
- #puts path
97
- #puts File.exists?(path)
106
+ template = ERB.new File.read(path)
107
+ output = template.result(binding)
108
+ File.open(File.join(app_dir, "config", "deploy.rb"), 'w') {|f| f.write(output) }
109
+ end
110
+
111
+ def create_dsl_deploy_file
98
112
 
113
+ # ERB variables
114
+ repository = repo_dir
115
+ deploy_to = File.join(test_files_dir, "deployed")
116
+ git_location = `which git`.strip
117
+ user = Etc.getlogin
118
+ environments = ["ci", "staging"]
119
+
120
+ path = File.expand_path(File.join(__FILE__, "..", "..", "templates", "deploy_dsl.erb"))
99
121
  template = ERB.new File.read(path)
100
122
  output = template.result(binding)
123
+
124
+ puts "#{__FILE__}:#{__LINE__}"
125
+ p output
126
+
101
127
  File.open(File.join(app_dir, "config", "deploy.rb"), 'w') {|f| f.write(output) }
102
128
  end
103
129
 
104
130
  def create_cap_ext_multistage_deploy_files
131
+
132
+ # ERB variables
105
133
  repository = repo_dir
106
134
  deploy_to = File.join(test_files_dir, "deployed")
107
135
  git_location = `which git`.strip
@@ -109,11 +137,9 @@ class StepHelpers
109
137
  environments = [:ci, :staging, :production]
110
138
 
111
139
  path = File.expand_path(File.join(__FILE__, "..", "..", "templates", "cap_ext_deploy.erb"))
112
-
113
140
  template = ERB.new File.read(path)
114
141
  output = template.result(binding)
115
142
  File.open(File.join(app_dir, "config", "deploy.rb"), 'w') {|f| f.write(output) }
116
-
117
143
  %w(staging production).each do |stage|
118
144
  create_cap_ext_multistage_deploy_stage_file(stage)
119
145
  end
@@ -122,11 +148,9 @@ class StepHelpers
122
148
  def create_cap_ext_multistage_deploy_stage_file(stage)
123
149
  deploy_subdir = File.join(app_dir, "config", "deploy")
124
150
  FileUtils.mkdir_p deploy_subdir
125
-
126
151
  template_path = File.expand_path(File.join(__FILE__, "..", "..", "templates", "stage.erb"))
127
152
  template = ERB.new File.read(template_path)
128
153
  output = template.result(binding)
129
-
130
154
  File.open(File.join(deploy_subdir, "#{stage}.rb"), 'w') {|f| f.write(output) }
131
155
  end
132
156
 
@@ -31,4 +31,4 @@ end
31
31
  before "deploy:update_code", "release_tagger:set_branch"
32
32
  after "deploy", "release_tagger:create_tag"
33
33
  after "deploy", "release_tagger:write_tag_to_shared"
34
- after "deploy", "release_tagger:print_latest_tags"
34
+ after "deploy", "release_tagger:print_latest_tag"
@@ -1,26 +1,157 @@
1
1
  module AutoTagger
2
- class EnvironmentCannotBeBlankError < StandardError; end
3
-
4
- class Runner
5
- attr_reader :stage, :repository, :working_directory
6
-
7
- def initialize(stage, path = nil)
8
- raise EnvironmentCannotBeBlankError if stage.to_s.strip == ""
9
- @working_directory = File.expand_path(path ||= Dir.pwd)
10
- @repository = Repository.new(@working_directory)
11
- @stage = stage
12
- end
13
-
14
- def create_tag(commit = nil)
15
- repository.tags.fetch
16
- new_tag = repository.tags.create(stage, commit)
17
- repository.tags.push
2
+
3
+ def self.version
4
+ File.read(File.expand_path(File.join(__FILE__, "/../../../VERSION")))
5
+ end
6
+
7
+ class Base
8
+ class StageCannotBeBlankError < StandardError;
9
+ end
10
+
11
+ def self.items_to_remove(array, keep)
12
+ max = array.length - keep
13
+ max = 0 if max <= 0
14
+ array[0...max]
15
+ end
16
+
17
+ attr_reader :options
18
+
19
+ def initialize(options)
20
+ @options = options
21
+ end
22
+
23
+ def repo
24
+ @repo ||= AutoTagger::Git::Repo.new configuration.working_directory,
25
+ :execute_commands => !configuration.dry_run?,
26
+ :verbose => configuration.verbose?,
27
+ :executable => configuration.executable
28
+ end
29
+
30
+ def last_ref_from_previous_stage
31
+ return unless previous_stage
32
+ refs_for_stage(previous_stage).last
33
+ end
34
+
35
+ def create_ref(commit = nil)
36
+ ensure_stage
37
+ fetch
38
+ new_tag = repo.refs.create(commit || repo.latest_commit_sha, ref_name)
39
+ push
18
40
  new_tag
19
41
  end
20
42
 
21
- def latest_tag
22
- repository.tags.fetch
23
- repository.tags.latest_from(stage)
43
+ def pattern
44
+ "refs/#{configuration.ref_path}/*"
45
+ end
46
+
47
+ private :pattern
48
+
49
+ def fetch
50
+ repo.refs.fetch(pattern, configuration.remote) if configuration.fetch_refs?
51
+ end
52
+
53
+ private :fetch
54
+
55
+ def push
56
+ repo.refs.push(pattern, configuration.remote) if configuration.push_refs?
57
+ end
58
+
59
+ private :push
60
+
61
+ def cleanup
62
+ refs = refs_to_remove
63
+ delete_local_refs(refs)
64
+ delete_remote_refs(refs) if configuration.push_refs?
65
+ refs.length
66
+ end
67
+
68
+ def delete_locally
69
+ refs = refs_to_remove
70
+ refs.each { |ref| ref.delete_locally }
71
+ refs.length
72
+ end
73
+
74
+ def delete_local_refs(refs)
75
+ refs.each { |ref| ref.delete_locally }
76
+ end
77
+
78
+ private :delete_local_refs
79
+
80
+ def delete_on_remote
81
+ refs = refs_to_remove
82
+ delete_remote_refs(refs)
83
+ refs.length
84
+ end
85
+
86
+ def delete_remote_refs(refs)
87
+ if refs.any?
88
+ cmd = ["push #{configuration.remote}"]
89
+ cmd += refs.map { |ref| ":#{ref.name}" }
90
+ repo.exec cmd.join(" ")
91
+ end
92
+ end
93
+
94
+ private :delete_remote_refs
95
+
96
+ def list
97
+ ensure_stage
98
+ fetch
99
+ refs_for_stage(configuration.stage)
100
+ end
101
+
102
+ def release_tag_entries
103
+ configuration.stages.map do |stage|
104
+ refs_for_stage(stage).last
105
+ end
106
+ end
107
+
108
+ def refs_for_stage(stage)
109
+ raise StageCannotBeBlankError if stage.to_s.strip == ""
110
+ ref_path = Regexp.escape(configuration.ref_path)
111
+ matcher = /refs\/#{ref_path}\/#{Regexp.escape(stage)}\/.*/
112
+ repo.refs.all.select do |ref|
113
+ (ref.name =~ matcher) ? ref : nil
114
+ end
115
+ end
116
+
117
+ private
118
+
119
+ def refs_to_remove
120
+ self.class.items_to_remove(refs_for_stage(configuration.stage), configuration.refs_to_keep)
121
+ end
122
+
123
+ def previous_stage
124
+ return unless configuration.stage
125
+ index = configuration.stages.index(configuration.stage).to_i - 1
126
+ configuration.stages[index] if index > -1
127
+ end
128
+
129
+ def configuration
130
+ @configuration ||= begin
131
+ config = AutoTagger::Configuration.new(@options)
132
+ # raise "Stage must be included in stages" unless config.stages.include?(config.stage)
133
+ config
134
+ end
135
+ end
136
+
137
+ def ref_name
138
+ "refs/#{configuration.ref_path}/#{configuration.stage}/#{timestamp}"
139
+ end
140
+
141
+ def timestamp
142
+ time = Time.now.utc
143
+ [
144
+ time.strftime("%Y"),
145
+ time.strftime("%m"),
146
+ time.strftime("%d"),
147
+ time.strftime("%H"),
148
+ time.strftime("%M"),
149
+ time.strftime("%S")
150
+ ].join(configuration.date_separator)
151
+ end
152
+
153
+ def ensure_stage
154
+ raise StageCannotBeBlankError if configuration.stage.to_s.strip == ""
24
155
  end
25
156
  end
26
157
  end
@@ -1,40 +1,61 @@
1
1
  module AutoTagger
2
2
  class CapistranoHelper
3
3
 
4
- attr_reader :variables, :stage, :working_directory
4
+ attr_reader :variables
5
+ private :variables
5
6
 
6
7
  def initialize(variables)
7
- @stage_manager = StageManager.new(variables[:autotagger_stages])
8
8
  @variables = variables
9
- @stage = variables[:stage]
10
- @working_directory = variables[:working_directory] || Dir.pwd
11
9
  end
12
10
 
13
- def previous_stage
14
- @stage_manager.previous_stage(stage)
11
+ def auto_tagger
12
+ @auto_tagger ||= AutoTagger::Base.new(auto_tagger_options)
15
13
  end
16
14
 
17
- def branch
15
+ def ref
18
16
  if variables.has_key?(:head)
19
17
  variables[:branch]
20
18
  elsif variables.has_key?(:tag)
21
19
  variables[:tag]
22
- elsif previous_stage && (latest = Runner.new(previous_stage, working_directory).latest_tag)
23
- latest
20
+ elsif variables.has_key?(:ref)
21
+ variables[:ref]
22
+ elsif auto_tagger.last_ref_from_previous_stage
23
+ auto_tagger.last_ref_from_previous_stage.sha
24
24
  else
25
25
  variables[:branch]
26
26
  end
27
27
  end
28
28
 
29
- def release_tag_entries
30
- entries = []
31
- @stage_manager.stages.each do |stage|
32
- tagger = Runner.new(stage, working_directory)
33
- tag = tagger.latest_tag
34
- commit = tagger.repository.commit_for(tag)
35
- entries << "#{stage.to_s.ljust(10, " ")} #{tag.to_s.ljust(30, " ")} #{commit.to_s}"
29
+ def auto_tagger_options
30
+ options = {}
31
+ options[:stage] = variables[:auto_tagger_stage] || variables[:stage]
32
+ options[:stages] = stages
33
+
34
+ if variables[:working_directory]
35
+ AutoTagger::Deprecator.warn(":working_directory is deprecated. Please use :auto_tagger_working_directory.")
36
+ options[:path] = variables[:working_directory]
37
+ else
38
+ options[:path] = variables[:auto_tagger_working_directory]
39
+ end
40
+
41
+ [
42
+ :date_separator, :push_refs, :fetch_refs, :remote, :ref_path, :offline,
43
+ :dry_run, :verbose, :refs_to_keep, :executable, :opts_file
44
+ ].each do |key|
45
+ options[key] = variables[:"auto_tagger_#{key}"]
46
+ end
47
+
48
+ options
49
+ end
50
+
51
+ def stages
52
+ if variables[:autotagger_stages]
53
+ AutoTagger::Deprecator.warn(":autotagger_stages is deprecated. Please use :auto_tagger_stages.")
54
+ stages = variables[:autotagger_stages]
55
+ else
56
+ stages = variables[:auto_tagger_stages] || variables[:stages] || []
36
57
  end
37
- entries
58
+ stages.map { |stage| stage.to_s }
38
59
  end
39
60
 
40
61
  end
@@ -0,0 +1,65 @@
1
+ module AutoTagger
2
+ class CommandLine
3
+
4
+ def initialize(args)
5
+ @args = args
6
+ end
7
+
8
+ def execute
9
+ case options[:command]
10
+ when :version
11
+ [true, "AutoTagger version #{AutoTagger.version}"]
12
+ when :help
13
+ [true, options[:help_text]]
14
+ when :cleanup
15
+ begin
16
+ purged = AutoTagger::Base.new(options).cleanup
17
+ [true, "Deleted: #{purged}"]
18
+ rescue AutoTagger::Base::StageCannotBeBlankError
19
+ [false, "You must provide a stage"]
20
+ end
21
+ when :delete_locally
22
+ begin
23
+ purged = AutoTagger::Base.new(options).delete_locally
24
+ [true, "Deleted: #{purged}"]
25
+ rescue AutoTagger::Base::StageCannotBeBlankError
26
+ [false, "You must provide a stage"]
27
+ end
28
+ when :delete_on_remote
29
+ begin
30
+ purged = AutoTagger::Base.new(options).delete_on_remote
31
+ [true, "Deleted: #{purged}"]
32
+ rescue AutoTagger::Base::StageCannotBeBlankError
33
+ [false, "You must provide a stage"]
34
+ end
35
+ when :list
36
+ begin
37
+ [true, AutoTagger::Base.new(options).list.join("\n")]
38
+ rescue AutoTagger::Base::StageCannotBeBlankError
39
+ [false, "You must provide a stage"]
40
+ end
41
+ when :config
42
+ [true, AutoTagger::Configuration.new(options).settings.map { |key, value| "#{key} : #{value}" }.join("\n")]
43
+ else
44
+ begin
45
+ create_message = []
46
+ if options[:deprecated]
47
+ create_message << AutoTagger::Deprecator.string("Please use `autotag create #{options[:stage]}` instead")
48
+ end
49
+ ref = AutoTagger::Base.new(options).create_ref
50
+ create_message << "Created ref #{ref.name}"
51
+ [true, create_message.join("\n")]
52
+ rescue AutoTagger::Base::StageCannotBeBlankError
53
+ [false, "You must provide a stage"]
54
+ end
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def options
61
+ @options ||= AutoTagger::Options.from_command_line(@args)
62
+ end
63
+
64
+ end
65
+ end