Class: Terraspace::CLI::Clean::Logs
- Inherits:
-
Base
- Object
- Base
- Terraspace::CLI::Clean::Logs
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?
#logger
Instance Method Details
#are_you_sure?(action) ⇒ 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) end
|
#log_files ⇒ Object
22
23
24
|
# File 'lib/terraspace/cli/clean/logs.rb', line 22
def log_files
Dir.glob("#{log_root}/**/*.log")
end
|
#log_root ⇒ Object
30
31
32
|
# File 'lib/terraspace/cli/clean/logs.rb', line 30
def log_root
Terraspace.config.log.root
end
|
#pretty_log_root ⇒ Object
#remove ⇒ Object
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
|
#run ⇒ Object
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
|
#truncate ⇒ Object
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 end
end
|