Class: AutoTagger::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/auto_tagger/command_line.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CommandLine

Returns a new instance of CommandLine.



4
5
6
# File 'lib/auto_tagger/command_line.rb', line 4

def initialize(args)
  @args = args
end

Instance Method Details

#executeObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/auto_tagger/command_line.rb', line 8

def execute
  case options[:command]
    when :version
      [true, "AutoTagger version #{AutoTagger::VERSION}"]
    when :help
      [true, options[:help_text]]
    when :cleanup
      begin
        purged = AutoTagger::Base.new(options).cleanup
        [true, "Deleted: #{purged}"]
      rescue AutoTagger::Base::StageCannotBeBlankError
        [false, "You must provide a stage"]
      end
    when :delete_locally
      begin
        purged = AutoTagger::Base.new(options).delete_locally
        [true, "Deleted: #{purged}"]
      rescue AutoTagger::Base::StageCannotBeBlankError
        [false, "You must provide a stage"]
      end
    when :delete_on_remote
      begin
        purged = AutoTagger::Base.new(options).delete_on_remote
        [true, "Deleted: #{purged}"]
      rescue AutoTagger::Base::StageCannotBeBlankError
        [false, "You must provide a stage"]
      end
    when :list
      begin
        [true, AutoTagger::Base.new(options).list.join("\n")]
      rescue AutoTagger::Base::StageCannotBeBlankError
        [false, "You must provide a stage"]
      end
    when :config
      [true, AutoTagger::Configuration.new(options).settings.map { |key, value| "#{key} : #{value}" }.join("\n")]
    else
      begin
        create_message = []
        if options[:deprecated]
          create_message << AutoTagger::Deprecator.string("Please use `autotag create #{options[:stage]}` instead")
        end
        ref = AutoTagger::Base.new(options).create_ref
        create_message << "Created ref #{ref.name}"
        [true, create_message.join("\n")]
      rescue AutoTagger::Base::StageCannotBeBlankError
        [false, "You must provide a stage"]
      end
  end
end