Sha256: c602f27e782b028be90062828b078195bbbae9b7a8381123abb8569b16be62eb

Contents?: true

Size: 956 Bytes

Versions: 53

Compression:

Stored size: 956 Bytes

Contents

class Terraspace::CLI::Clean
  class Logs < Base
    def run
      action = @options[:truncate] ? "truncate" : "remove"
      are_you_sure?(action)
      @options[:truncate] ? truncate : remove
    end

    def truncate
      log_files.each do |path|
        File.open(path, "w").close # truncates files
      end
    end

    def remove
      return unless File.exist?(log_root)
      puts "Removing all files in #{pretty_log_root}/" unless @options[:mute]
      FileUtils.rm_rf(log_root)
      FileUtils.mkdir_p(log_root)
    end

    def log_files
      Dir.glob("#{log_root}/**/*.log")
    end

    def pretty_log_root
      Terraspace::Util.pretty_path(log_root)
    end

    def log_root
      Terraspace.config.log.root
    end

    def are_you_sure?(action)
      message = <<~EOL.chomp
        Will #{action} all the log files in #{pretty_log_root}/ folder
        Are you sure?
      EOL
      sure?(message) # from Util::Sure
    end
  end
end

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
terraspace-2.2.17 lib/terraspace/cli/clean/logs.rb
terraspace-2.2.16 lib/terraspace/cli/clean/logs.rb
terraspace-2.2.15 lib/terraspace/cli/clean/logs.rb
terraspace-2.2.14 lib/terraspace/cli/clean/logs.rb
terraspace-2.2.13 lib/terraspace/cli/clean/logs.rb
terraspace-2.2.12 lib/terraspace/cli/clean/logs.rb
terraspace-2.2.11 lib/terraspace/cli/clean/logs.rb
terraspace-2.2.10 lib/terraspace/cli/clean/logs.rb
terraspace-2.2.9 lib/terraspace/cli/clean/logs.rb
terraspace-2.2.8 lib/terraspace/cli/clean/logs.rb
terraspace-2.2.7 lib/terraspace/cli/clean/logs.rb
terraspace-2.2.6 lib/terraspace/cli/clean/logs.rb
terraspace-2.2.5 lib/terraspace/cli/clean/logs.rb
terraspace-2.2.4 lib/terraspace/cli/clean/logs.rb
terraspace-2.2.3 lib/terraspace/cli/clean/logs.rb
terraspace-2.2.2 lib/terraspace/cli/clean/logs.rb
terraspace-2.2.1 lib/terraspace/cli/clean/logs.rb
terraspace-2.2.0 lib/terraspace/cli/clean/logs.rb
terraspace-2.1.7 lib/terraspace/cli/clean/logs.rb
terraspace-2.1.6 lib/terraspace/cli/clean/logs.rb