lib/faastruby/cli/template.rb in faastruby-0.4.18 vs lib/faastruby/cli/template.rb in faastruby-0.5.0
- old
+ new
@@ -10,11 +10,12 @@
FaaStRuby::CLI.error(["Unknown template type: '#{type}'. Valid types are:", TYPES], color: nil) unless TYPES.include?(type)
@type = type
@source = source
end
- def install(to:, force: false)
+ def install(to:, force: false, print_base_dir: false)
+ @output_prefix = print_base_dir ? "#{print_base_dir}/" : ""
@target = to
@force = force
FaaStRuby::CLI.error("Could not determine the target path for template '#{type}:#{source}'. Please report this bug at https://github.com/FaaStRuby/faastruby-cli/issues", color: nil) unless target
return install_from_folder(source) if local?
return install_from_git(source) if git?
@@ -38,16 +39,15 @@
FaaStRuby::CLI.error("Could not clone repository #{repo} into #{local_dir}") unless
system("git clone #{repo} #{local_dir}")
end
def install_from_folder(folder)
- # puts "installing from folder #{folder}"
if File.directory?(target)
- puts "! d #{target}".yellow
+ puts "! d #{@output_prefix}#{target}".yellow
else
FileUtils.mkdir_p(target)
- puts "+ d #{target}".green
+ puts "+ d #{@output_prefix}#{target}".green
end
Dir.glob("**/*", base: folder).each do |entry|
full_source_path = "#{folder}/#{entry}"
full_target_path = "#{target}/#{entry}"
create_dir(full_target_path) if File.directory?(full_source_path)
@@ -56,24 +56,24 @@
end
def create_dir(dir)
if File.directory?(dir)
- puts "! d #{dir}".yellow
+ puts "! d #{@output_prefix}#{dir}".yellow
else
FileUtils.mkdir_p(dir)
- puts "+ d #{dir}".green
+ puts "+ d #{@output_prefix}#{dir}".green
end
end
def copy_file(source:, destination:)
if File.file?(destination) && !@force
print "File '#{destination}' already exists. Overwrite? [y/N] "
answer = STDIN.gets.chomp
return(puts "[skipped] #{destination}") unless ['y', 'Y'].include?(answer)
end
FileUtils.cp(source, destination)
- puts "+ f #{destination}".green
+ puts "+ f #{@output_prefix}#{destination}".green
end
def local?
type == 'local'
end
\ No newline at end of file