Class: Pupcap::CLI

Inherits:
Thor
  • Object
show all
Includes:
Capistrano, Thor::Actions
Defined in:
lib/pupcap/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Capistrano

#cap_create_instance, #cap_execute_tasks, #cap_use_rsync!

Class Method Details

.revert_argv_and_start(argv = ARGV) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/pupcap/cli.rb', line 72

def self.revert_argv_and_start(argv = ARGV)
  need_to_revert = %w{ noop apply init prepare ssh }
  if need_to_revert.include?(argv.last) && argv.size > 1
    last = argv.pop
    argv = [last] + argv
  end
  begin
    start(argv)
  rescue Exception => e
    if ENV['THOR_DEBUG'] == '1'
      raise e
    else
      $stderr.puts e.message
      exit 1
    end
  end
end

.source_rootObject



68
69
70
# File 'lib/pupcap/cli.rb', line 68

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#apply(*tasks) ⇒ Object



49
50
51
# File 'lib/pupcap/cli.rb', line 49

def apply(*tasks)
  cap_execute_tasks(capfile("apply"), tasks << "apply")
end

#init(dir) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pupcap/cli.rb', line 13

def init(dir)
  directory("action/init", dir)
  inside(dir) do
    unless File.exists?(".gitignore")
      create_file ".gitignore"
    end
    append_to_file(".gitignore", ".vagrant\n", :verbose => false)
    append_to_file(".gitignore", "*.swp\n", :verbose => false)
    run("librarian-puppet init")
  end
end

#noop(*tasks) ⇒ Object



56
57
58
59
# File 'lib/pupcap/cli.rb', line 56

def noop(*tasks)
  ENV['NOOP'] = '1'
  apply(*tasks)
end

#prepare(*tasks) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/pupcap/cli.rb', line 30

def prepare(*tasks)
  error "#{options[:file]} does not exists"   unless File.exists?(options[:file])
  error "#{options[:script]} does not exists" unless File.exists?(options[:script])

  unless File.exists?(provision_key)
    inside pupcap_root do
      empty_directory(".keys")
      chmod(".keys", 0700)
      run("ssh-keygen -q -b 1024 -t rsa -C \"#{application} provision key\" -f #{provision_key}")
      chmod(provision_key, 0600)
      chmod(provision_key_pub, 0600)
    end
  end
  cap_execute_tasks(capfile("prepare"), tasks << "prepare")
end

#ssh(*tasks) ⇒ Object



64
65
66
# File 'lib/pupcap/cli.rb', line 64

def ssh(*tasks)
  cap_execute_tasks(capfile("ssh"), tasks << "ssh")
end