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

Class Method Details

.revert_argv_and_start(argv = ARGV) ⇒ Object



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

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



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

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#apply(*tasks) ⇒ Object



46
47
48
# File 'lib/pupcap/cli.rb', line 46

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

#init(dir) ⇒ Object



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

def init(dir)
  directory("action/init", dir)
  inside(dir) do
    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



53
54
55
56
# File 'lib/pupcap/cli.rb', line 53

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

#prepare(*tasks) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pupcap/cli.rb', line 27

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



61
62
63
# File 'lib/pupcap/cli.rb', line 61

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