-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
spaceship_logs.rb
135 lines (119 loc) 路 4.19 KB
/
spaceship_logs.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
module Fastlane
module Actions
class SpaceshipLogsAction < Action
def self.run(params)
latest = params[:latest]
print_contents = params[:print_contents]
print_paths = params[:print_paths]
copy_to_path = params[:copy_to_path]
copy_to_clipboard = params[:copy_to_clipboard]
# Get log files
files = Dir.glob("/tmp/spaceship*.log").sort_by { |f| File.mtime(f) }.reverse
if files.size == 0
UI.message("No Spaceship log files found")
return []
end
# Filter to latest
if latest
files = [files.first]
end
# Print contents
if print_contents
files.each do |file|
data = File.read(file)
puts("-----------------------------------------------------------------------------------")
puts(" Spaceship Log Content - #{file}")
puts("-----------------------------------------------------------------------------------")
puts(data)
puts("\n")
end
end
# Print paths
if print_paths
puts("-----------------------------------------------------------------------------------")
puts(" Spaceship Log Paths")
puts("-----------------------------------------------------------------------------------")
files.each do |file|
puts(file)
end
puts("\n")
end
# Copy to a directory
if copy_to_path
require 'fileutils'
FileUtils.mkdir_p(copy_to_path)
files.each do |file|
FileUtils.cp(file, copy_to_path)
end
end
# Copy contents to clipboard
if copy_to_clipboard
string = files.map { |file| File.read(file) }.join("\n")
ClipboardAction.run(value: string)
end
return files
end
def self.description
"Find, print, and copy Spaceship logs"
end
def self.available_options
[
FastlaneCore::ConfigItem.new(key: :latest,
description: "Finds only the latest Spaceshop log file if set to true, otherwise returns all",
default_value: true,
type: Boolean),
FastlaneCore::ConfigItem.new(key: :print_contents,
description: "Prints the contents of the found Spaceship log file(s)",
default_value: false,
type: Boolean),
FastlaneCore::ConfigItem.new(key: :print_paths,
description: "Prints the paths of the found Spaceship log file(s)",
default_value: false,
type: Boolean),
FastlaneCore::ConfigItem.new(key: :copy_to_path,
description: "Copies the found Spaceship log file(s) to a directory",
optional: true),
FastlaneCore::ConfigItem.new(key: :copy_to_clipboard,
description: "Copies the contents of the found Spaceship log file(s) to the clipboard",
default_value: false,
type: Boolean)
]
end
def self.is_supported?(platform)
true
end
def self.example_code
[
'spaceship_logs',
'spaceship_logs(
copy_to_path: "/tmp/artifacts"
)',
'spaceship_logs(
copy_to_clipboard: true
)',
'spaceship_logs(
print_contents: true,
print_paths: true
)',
'spaceship_logs(
latest: false,
print_contents: true,
print_paths: true
)'
]
end
def self.category
:misc
end
def self.return_value
"The array of Spaceship logs"
end
def self.return_type
:array_of_strings
end
def self.author
"joshdholtz"
end
end
end
end