Class: Command::Log
Defined Under Namespace
Classes: Tail
Constant Summary
collapse
- NUM =
20
Instance Attribute Summary
Attributes inherited from CommandBase
#stream_io
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from CommandBase
#disable_logging, #display_help!, execute!, #execute!, #force_change_settings_function, help, #hook_call, #load_local_settings, #tagname_to_ids
Constructor Details
#initialize ⇒ Log
Returns a new instance of Log.
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/command/log.rb', line 17
def initialize
super("[options] [<path>]")
@opt.separator <<~HELP
|
Class Method Details
.oneline_help ⇒ Object
13
14
15
|
# File 'lib/command/log.rb', line 13
def self.oneline_help
"保存したログを表示します"
end
|
Instance Method Details
#execute(argv) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/command/log.rb', line 53
def execute(argv)
disable_logging
super
path = resolve_path(argv.first) || latest_log_path
unless path
error "表示できるログファイルが一つも見つかりませんでした"
exit Narou::EXIT_ERROR_CODE
end
stream_io.puts "<cyan>#{path}</cyan>".termcolor
tail = Tail.new(path, @options["num"] || NUM)
tail.stream_io = stream_io
if @options["tail"]
tail.stream
else
tail.display
end
rescue Interrupt
stream_io.puts
end
|
#latest_log_path ⇒ Object
73
74
75
76
77
|
# File 'lib/command/log.rb', line 73
def latest_log_path
Narou.log_dir.glob("*").sort_by(&:mtime).reverse.find do |path|
path_matches_source?(path)
end
end
|
#path_matches_source?(path) ⇒ Boolean
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/command/log.rb', line 79
def path_matches_source?(path)
ext = path.extname
base = path.basename(ext)
ended_with_convert = base.to_s.end_with?("_convert")
if @options["source-convert"]
ended_with_convert
else
!ended_with_convert
end
end
|
#resolve_path(path) ⇒ Object
90
91
92
93
94
95
96
97
98
|
# File 'lib/command/log.rb', line 90
def resolve_path(path)
return nil if path.blank?
fullpath = Pathname(path).expand_path
unless fullpath.exist?
error "#{path} が存在しません"
exit Narou::EXIT_ERROR_CODE
end
fullpath
end
|