Class: Capistrano::Releases::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/releases/cli.rb

Overview

Command line interface class for Manager class.

Instance Method Summary collapse

Instance Method Details

#runObject



5
6
7
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
# File 'lib/capistrano/releases/cli.rb', line 5

def run
  options = {}

  parser = OptionParser.new do |opts|
    opts.banner = 'Usage: manager [options]'

    opts.on('-bBUCKET', '--bucket=BUCKET',
            'S3 bucket to pull/push releases.') do |v|
      options[:bucket] = v
    end

    opts.on('-dDEPLOY_TO', '--deploy-to=DEPLOY_TO',
            'App directory to deploy to.') do |v|
      options[:deploy_to] = v
    end

    opts.on('-mMODE', '--mode=MODE',
            "Mode to run: 'push' or 'pull'") do |v|
      options[:mode] = v
    end
  end

  parser.parse!

  unless options[:bucket]
    puts('-b or --bucket is a required option.') && exit(1)
  end

  unless options[:deploy_to]
    puts('-d or --deploy-to is a required option.') && exit(1)
  end

  puts('-m or --mode is a required option.') && exit(1) unless options[:mode]

  manager = ::Capistrano::Releases::Manager.new(options)

  case options[:mode]
  when 'push'
    manager.push
  when 'pull'
    manager.pull
  else
    puts 'Invalid mode.'
    exit(1)
  end
end