Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
lasseebert committed Nov 13, 2014
1 parent 91f3ef6 commit 45e6395
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/sunzi/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,8 @@ def do_compile(role)
get value, "compiled/recipes/#{key}.sh"
end

# Copy local files
@attributes = OpenStruct.new(@config['attributes'])
copy_or_template = (@config['preferences'] && @config['preferences']['eval_erb']) ? :template : :copy_file
Dir['recipes/*'].each {|file| send copy_or_template, File.expand_path(file), "compiled/recipes/#{File.basename(file)}" }
Dir['roles/*'].each {|file| send copy_or_template, File.expand_path(file), "compiled/roles/#{File.basename(file)}" }
Dir['files/**/*'].select { |file| File.file?(file) }.each {|file| send copy_or_template, File.expand_path(file), "compiled/#{file}" }
(@config['files'] || []).each {|file| send copy_or_template, File.expand_path(file), "compiled/files/#{File.basename(file)}" }
copy_local_files(@config, copy_or_template)

# Build install.sh
if role
Expand All @@ -156,6 +151,14 @@ def parse_target(target)
config[:host_name] || $2,
($3 && $3.delete(':') || config[:port] && config[:port].to_s || '22') ]
end

def copy_local_files(config, copy_or_template)
@attributes = OpenStruct.new(config['attributes'])
files = Dir['{recipes,roles,files}/**/*'].select { |file| File.file?(file) }
files.each { |file| send copy_or_template, File.expand_path(file), "compiled/#{file}" }

(config['files'] || []).each {|file| send copy_or_template, File.expand_path(file), "compiled/files/#{File.basename(file)}" }
end
end
end
end

0 comments on commit 45e6395

Please sign in to comment.