Class: Terraspace::CLI::Clean::Logs

Inherits:
Base
  • Object
show all
Defined in:
lib/terraspace/cli/clean/logs.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, #pretty

Methods included from Util::Sure

#sure?

Methods included from Util::Logging

#logger

Constructor Details

This class inherits a constructor from Terraspace::CLI::Clean::Base

Instance Method Details

#are_you_sure?(action) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
# File 'lib/terraspace/cli/clean/logs.rb', line 34

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

#log_filesObject



22
23
24
# File 'lib/terraspace/cli/clean/logs.rb', line 22

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

#log_rootObject



30
31
32
# File 'lib/terraspace/cli/clean/logs.rb', line 30

def log_root
  Terraspace.config.log.root
end

#pretty_log_rootObject



26
27
28
# File 'lib/terraspace/cli/clean/logs.rb', line 26

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

#removeObject



15
16
17
18
19
20
# File 'lib/terraspace/cli/clean/logs.rb', line 15

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

#runObject



3
4
5
6
7
# File 'lib/terraspace/cli/clean/logs.rb', line 3

def run
  action = @options[:truncate] ? "truncate" : "remove"
  are_you_sure?(action)
  @options[:truncate] ? truncate : remove
end

#truncateObject



9
10
11
12
13
# File 'lib/terraspace/cli/clean/logs.rb', line 9

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