Class: Chef::Knife::ParatrooperInit
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::ParatrooperInit
- Includes:
- FileUtils
- Defined in:
- lib/chef/knife/paratrooper_init.rb
Instance Method Summary collapse
- #create_conffiles ⇒ Object
- #create_ignorefiles ⇒ Object
- #create_kitchen ⇒ Object
- #mkdir_p(*args) ⇒ Object
- #run ⇒ Object
- #validate! ⇒ Object
Instance Method Details
#create_conffiles ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/chef/knife/paratrooper_init.rb', line 62 def create_conffiles conffiles = %w[Gemfile Capfile config/deploy.rb Cheffile config/solo.json] extra_path = nil if config[:multistage] conffiles.insert(3, 'config/deploy/develop.rb') extra_path = 'multistage' end conffiles.each do |conffile| path = File.join(@base, conffile) unless File.exist?(path) ui.msg "creating %s" % path cp Paratrooper::Chef.resource(File.basename(conffile), extra_path), path end end end |
#create_ignorefiles ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/chef/knife/paratrooper_init.rb', line 80 def create_ignorefiles %w[.gitignore .hgignore].each do |ignore| path = File.join(@base, ignore) unless File.exist?(path) ui.msg "creating %s" % path File.open(path, 'w') do |f| f.puts("vendor/bundle/") f.puts("config/cookbooks/") f.puts("tmp/librarian/") end end end end |
#create_kitchen ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/chef/knife/paratrooper_init.rb', line 52 def create_kitchen mkdir_p @base mkdir_p @base, "config" mkdir_p @base, "config", "deploy" if config[:multistage] %w[nodes roles environments data_bags cookbooks site-cookbooks].each do |subdir| mkdir_p @base, 'config', subdir, :keep => true end end |
#mkdir_p(*args) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/chef/knife/paratrooper_init.rb', line 38 def mkdir_p(*args) = args.last.kind_of?(Hash) ? args.pop : {} path = File.join(*args) if not File.exist? path ui.msg "creating %s/" % path FileUtils.mkdir_p(path) if [:keep] touch File.join(path, '.keep') end end end |
#run ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/chef/knife/paratrooper_init.rb', line 21 def run @base = @name_args.first validate! mkdir_p @base create_kitchen create_conffiles create_ignorefiles end |
#validate! ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/chef/knife/paratrooper_init.rb', line 30 def validate! if @base.nil? show_usage ui.fatal "You must specify a directory. Use '.' to initialize the current directory." exit 1 end end |