Class: Dandelion::Command::Deploy

Inherits:
Base
  • Object
show all
Defined in:
lib/dandelion/command/deploy.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

command, commands, create, #initialize, require_commands

Constructor Details

This class inherits a constructor from Dandelion::Command::Base

Class Method Details

.parser(options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/dandelion/command/deploy.rb', line 7

def parser(options)
  OptionParser.new do |opts|
    opts.banner = 'Usage: deploy [options] [<revision>]'
      
    options[:force] = false
    opts.on('-f', '--force', 'Force deployment') do
      options[:force] = true
    end
    
    options[:dry] = false
    opts.on('--dry-run', 'Show what would have been deployed') do
      options[:dry] = true
    end
  end
end

Instance Method Details

#executeObject



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
# File 'lib/dandelion/command/deploy.rb', line 28

def execute
  begin
    @deployment = deployment(@revision)
  rescue Git::RevisionError
    log.fatal("Invalid revision: #{@revision}")
    exit 1
  end
  
  log.info("Remote revision:      #{@deployment.remote_revision || '---'}")
  log.info("Deploying revision:   #{@deployment.local_revision}")
  
  begin
    @deployment.validate
  rescue Deployment::FastForwardError
    if !@options[:force]
      log.warn('Warning: you are trying to deploy unpushed commits')
      log.warn('This could potentially prevent others from being able to deploy')
      log.warn('If you are sure you want to do this, use the -f option to force deployment')
      exit 1
    end
  end
  
  @deployment.deploy
  log.info("Deployment complete")
end

#setup(args) ⇒ Object



24
25
26
# File 'lib/dandelion/command/deploy.rb', line 24

def setup(args)
  @revision = args.shift || 'HEAD'
end