Sha256: a85230c3db5fe28db5dc4a47c1b4aa936eb1916890434e5f469a41e5b7434d8d
Contents?: true
Size: 1.42 KB
Versions: 6
Compression:
Stored size: 1.42 KB
Contents
# frozen_string_literal: true require 'rake' require 'yaml' module KubsCLI # Used for copying files within kubs_cli class FileHelper # Copies a file or directory from one spot to another # @param from [Dir, File] Where to copy from # @param to [Dir, File] Where to copy to # @return void def copy(from:, to:) return if file_does_not_exist(from) to_dir = File.dirname(File.expand_path(to)) Rake.mkdir_p(to_dir) unless Dir.exist?(to_dir) return Rake.cp(from, to) unless File.directory?(from) Rake.mkdir_p(to) Dir["#{from}/*"].each do |dir| Rake.cp_r(dir, to) # next if File.directory?(dir) # Rake.cp(dir, to) end end # Creates dirs using Rake.mkdir_p if it does not exist # @param dirs [Array<String>] The names of the dirs to create # @return void def mkdirs(*dirs) dirs.flatten.each { |dir| Rake.mkdir_p(dir) unless Dir.exist?(dir) } end # Loads a YAML file # @param file [File] Yaml formatted file # @return [Hash] Returns a hash from a yaml document def load_yaml(file) YAML.load_file(file) rescue StandardError => e KubsCLI.add_error(e: e, msg: "Unable to parse your YAML file - #{file}") end private #:nodoc: def file_does_not_exist(file) return false if File.exist?(file) KubsCLI.add_error(e: KubsCLI::Error, msg: "#{file} does not exist") true end end end
Version data entries
6 entries across 6 versions & 1 rubygems