Module: Formatron::CLI::Deploy

Defined in:
lib/formatron/cli/deploy.rb

Overview

CLI command for deploy

Instance Method Summary collapse

Instance Method Details

#deploy_action(c) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/formatron/cli/deploy.rb', line 34

def deploy_action(c)
  c.action do |args, options|
    directory = deploy_directory options
    target = deploy_target args[0], directory
    formatron = Formatron.new(
      credentials: deploy_credentials(options),
      directory: directory,
      target: target
    )
    formatron.deploy if deploy_ok options, formatron, target
  end
end

#deploy_credentials(options) ⇒ Object



12
13
14
15
16
17
# File 'lib/formatron/cli/deploy.rb', line 12

def deploy_credentials(options)
  options.credentials ||
    Generators::Credentials.default_credentials(
      deploy_directory(options)
    )
end

#deploy_directory(options) ⇒ Object



8
9
10
# File 'lib/formatron/cli/deploy.rb', line 8

def deploy_directory(options)
  options.directory || Dir.pwd
end

#deploy_formatron_commandObject



47
48
49
50
51
52
53
54
# File 'lib/formatron/cli/deploy.rb', line 47

def deploy_formatron_command
  command :deploy do |c|
    c.syntax = 'formatron deploy [options] [TARGET]'
    c.summary = 'Deploy or update a Formatron stack'
    c.description = 'Deploy or update a Formatron stack'
    deploy_action c
  end
end

#deploy_ok(options, formatron, target) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/formatron/cli/deploy.rb', line 26

def deploy_ok(options, formatron, target)
  options.yes || !formatron.protected? || agree(
    "Are you sure you wish to deploy protected target: #{target}?"
  ) do |q|
    q.default = 'no'
  end
end

#deploy_target(target, directory) ⇒ Object



19
20
21
22
23
24
# File 'lib/formatron/cli/deploy.rb', line 19

def deploy_target(target, directory)
  target || choose(
    'Target?',
    *Config.targets(directory: directory)
  )
end