Icarus-Mod-Tools 1.8.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -1
- data/Gemfile.lock +6 -6
- data/lib/icarus/mod/cli/add.rb +8 -0
- data/lib/icarus/mod/cli/list.rb +55 -43
- data/lib/icarus/mod/cli/sync.rb +64 -130
- data/lib/icarus/mod/cli/validate.rb +32 -21
- data/lib/icarus/mod/tools/baseinfo.rb +26 -6
- data/lib/icarus/mod/tools/mod_sync.rb +5 -5
- data/lib/icarus/mod/tools/modinfo_sync.rb +1 -1
- data/lib/icarus/mod/tools/prog_sync.rb +5 -5
- data/lib/icarus/mod/tools/proginfo.rb +6 -0
- data/lib/icarus/mod/tools/proginfo_sync.rb +1 -1
- data/lib/icarus/mod/tools/validator.rb +23 -0
- data/lib/icarus/mod/version.rb +1 -1
- metadata +3 -3
- data/lib/icarus/mod/tools/modinfo_validate.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d70aff1f7ed368044b414fdca605fa438e0fbfe68c2af436d534a233fc6bff17
|
4
|
+
data.tar.gz: e4467d443894344c50a2c3c663e262afd7e54cc806da308ecd16d732bcd2c844
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26c83360237ab149e6738e60966df113f8ede55460f85b0b2de29dd690cea238cdfda8af0ffc70f288ca58765b535d18b2cfcb21e0619b0a8226bfe099e7fecc
|
7
|
+
data.tar.gz: 278435526ede69d45383920bee07fc3fc094924d022ed55c54141d00e9b53ef003d7688fb26bc4f251e3b13705b743013875583d553ca8c22198a7daeb590238
|
data/.rubocop.yml
CHANGED
@@ -38,11 +38,17 @@ Metrics/AbcSize:
|
|
38
38
|
Exclude:
|
39
39
|
- lib/icarus/mod/cli/*.rb # Thor command files
|
40
40
|
|
41
|
+
Metrics/BlockLength:
|
42
|
+
Enabled: false
|
43
|
+
|
41
44
|
Metrics/ClassLength:
|
42
45
|
Enabled: false
|
43
46
|
|
44
47
|
Metrics/MethodLength:
|
45
|
-
|
48
|
+
Enabled: false
|
49
|
+
|
50
|
+
Naming/BlockForwarding:
|
51
|
+
EnforcedStyle: explicit
|
46
52
|
|
47
53
|
RSpec/MultipleMemoizedHelpers:
|
48
54
|
Enabled: false
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
Icarus-Mod-Tools (1.8.
|
4
|
+
Icarus-Mod-Tools (1.8.1)
|
5
5
|
google-cloud-firestore (~> 2.7)
|
6
6
|
octokit (~> 6.0)
|
7
7
|
paint (~> 2.3)
|
@@ -14,7 +14,7 @@ GEM
|
|
14
14
|
public_suffix (>= 2.0.2, < 6.0)
|
15
15
|
ast (2.4.2)
|
16
16
|
coderay (1.1.3)
|
17
|
-
concurrent-ruby (1.
|
17
|
+
concurrent-ruby (1.2.0)
|
18
18
|
diff-lcs (1.5.0)
|
19
19
|
faraday (2.7.4)
|
20
20
|
faraday-net_http (>= 2.0, < 3.1)
|
@@ -38,7 +38,7 @@ GEM
|
|
38
38
|
google-cloud-env (1.6.0)
|
39
39
|
faraday (>= 0.17.3, < 3.0)
|
40
40
|
google-cloud-errors (1.3.0)
|
41
|
-
google-cloud-firestore (2.
|
41
|
+
google-cloud-firestore (2.9.0)
|
42
42
|
concurrent-ruby (~> 1.0)
|
43
43
|
google-cloud-core (~> 1.5)
|
44
44
|
google-cloud-firestore-v1 (~> 0.0)
|
@@ -65,10 +65,10 @@ GEM
|
|
65
65
|
multi_json (~> 1.11)
|
66
66
|
os (>= 0.9, < 2.0)
|
67
67
|
signet (>= 0.16, < 2.a)
|
68
|
-
grpc (1.
|
68
|
+
grpc (1.51.0-x86_64-darwin)
|
69
69
|
google-protobuf (~> 3.21)
|
70
70
|
googleapis-common-protos-types (~> 1.0)
|
71
|
-
grpc (1.
|
71
|
+
grpc (1.51.0-x86_64-linux)
|
72
72
|
google-protobuf (~> 3.21)
|
73
73
|
googleapis-common-protos-types (~> 1.0)
|
74
74
|
guard (2.18.0)
|
@@ -131,7 +131,7 @@ GEM
|
|
131
131
|
diff-lcs (>= 1.2.0, < 2.0)
|
132
132
|
rspec-support (~> 3.12.0)
|
133
133
|
rspec-support (3.12.0)
|
134
|
-
rubocop (1.
|
134
|
+
rubocop (1.44.1)
|
135
135
|
json (~> 2.3)
|
136
136
|
parallel (~> 1.10)
|
137
137
|
parser (>= 3.2.0.0)
|
data/lib/icarus/mod/cli/add.rb
CHANGED
@@ -15,6 +15,14 @@ module Icarus
|
|
15
15
|
puts firestore.update(:modinfo, payload, merge: true) ? "Success" : "Failure"
|
16
16
|
end
|
17
17
|
|
18
|
+
desc "proginfo", "Adds an entry to 'meta/proginfo/list'"
|
19
|
+
def proginfo(item)
|
20
|
+
firestore = Firestore.new
|
21
|
+
payload = [firestore.list(:proginfo), item].flatten.compact
|
22
|
+
|
23
|
+
puts firestore.update(:proginfo, payload, merge: true) ? "Success" : "Failure"
|
24
|
+
end
|
25
|
+
|
18
26
|
desc "repos", "Adds an entry to 'meta/repos/list'"
|
19
27
|
def repos(item)
|
20
28
|
firestore = Firestore.new
|
data/lib/icarus/mod/cli/list.rb
CHANGED
@@ -33,63 +33,75 @@ module Icarus
|
|
33
33
|
method_option :sort, type: :string, default: "name", desc: "Sort by field (name, author, etc.)"
|
34
34
|
method_option :filter, type: :array, default: [], desc: "Filter by field (name, author, etc.)"
|
35
35
|
def mods
|
36
|
-
|
36
|
+
list_for_type(:mods)
|
37
|
+
end
|
37
38
|
|
38
|
-
|
39
|
+
desc "progs", "Displays data from 'progs'"
|
40
|
+
method_option :sort, type: :string, default: "name", desc: "Sort by field (name, author, etc.)"
|
41
|
+
method_option :filter, type: :array, default: [], desc: "Filter by field (name, author, etc.)"
|
42
|
+
def progs
|
43
|
+
list_for_type(:progs)
|
44
|
+
end
|
39
45
|
|
40
|
-
|
46
|
+
no_commands do
|
47
|
+
def list_for_type(type)
|
48
|
+
klass = type == :mods ? Icarus::Mod::Tools::Modinfo : Icarus::Mod::Tools::Proginfo
|
49
|
+
valid_keys = klass::HASHKEYS + [:updated_at]
|
50
|
+
sort_field = options[:sort]&.to_sym
|
51
|
+
filter = !options[:filter].empty?
|
41
52
|
|
42
|
-
|
43
|
-
|
44
|
-
|
53
|
+
if filter
|
54
|
+
filter_field = options[:filter].first&.to_sym
|
55
|
+
filter_value = options[:filter].last&.to_s
|
45
56
|
|
46
|
-
|
57
|
+
raise Icarus::Mod::Tools::Error, "Invalid filter option #{options[:filter]}" unless options[:filter].empty? || options[:filter]&.count == 2
|
47
58
|
|
48
|
-
|
49
|
-
|
59
|
+
raise Icarus::Mod::Tools::Error, "Invalid filter field '#{filter_field}'" unless filter_field && valid_keys.include?(filter_field)
|
60
|
+
end
|
50
61
|
|
51
|
-
|
62
|
+
raise Icarus::Mod::Tools::Error, "Invalid sort field '#{sort_field}'" unless valid_keys.include?(sort_field)
|
52
63
|
|
53
|
-
|
54
|
-
|
64
|
+
puts "Sorted by #{sort_field}" if sort_field && verbose > 2
|
65
|
+
puts "Filtered by #{filter_field} = #{filter_value}" if filter_field && verbose > 2
|
55
66
|
|
56
|
-
|
67
|
+
items = Firestore.new.list(type)
|
57
68
|
|
58
|
-
|
59
|
-
|
69
|
+
# Filter by field
|
70
|
+
items.select! { |item| item.send(filter_field).downcase =~ /#{filter_value&.downcase}/ } if filter_field
|
60
71
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
72
|
+
if items.empty?
|
73
|
+
puts "no entries found" if verbose?
|
74
|
+
return
|
75
|
+
end
|
65
76
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
if verbose?
|
70
|
-
puts format(
|
71
|
-
header_format,
|
72
|
-
name: "NAME",
|
73
|
-
author: "AUTHOR",
|
74
|
-
version: "VERSION",
|
75
|
-
updated_at: "LAST UPDATED",
|
76
|
-
id: "ID",
|
77
|
-
description: "DESCRIPTION"
|
78
|
-
)
|
79
|
-
end
|
77
|
+
header_format = "%-<name>50s %-<author>20s %-<version>10s %-<updated_at>20s"
|
78
|
+
header_format += " %-<id>20s %<description>s" if verbose > 1
|
80
79
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
80
|
+
if verbose?
|
81
|
+
puts format(
|
82
|
+
header_format,
|
83
|
+
name: "NAME",
|
84
|
+
author: "AUTHOR",
|
85
|
+
version: "VERSION",
|
86
|
+
updated_at: "LAST UPDATED",
|
87
|
+
id: "ID",
|
88
|
+
description: "DESCRIPTION"
|
89
|
+
)
|
90
|
+
end
|
85
91
|
|
86
|
-
|
87
|
-
|
92
|
+
# Sort by field, optionally subsorting by name
|
93
|
+
(sort_field == :name ? items.sort_by(&:name) : items.sort_by { |item| [item.send(sort_field), item.name] }).each do |item|
|
94
|
+
data_format = "%-<name>50s %-<author>20s v%-<version>10s%-<updated_at>20s"
|
95
|
+
data_format += " %-<id>20s %<description>s" if verbose > 1
|
88
96
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
97
|
+
puts format(data_format, item.to_h.merge(id: item.id, updated_at: item.updated_at.strftime("%Y-%m-%d %H:%M:%S")))
|
98
|
+
end
|
99
|
+
|
100
|
+
puts "Total: #{items.count}" if verbose?
|
101
|
+
rescue Icarus::Mod::Tools::Error => e
|
102
|
+
puts e.message
|
103
|
+
exit 1
|
104
|
+
end
|
93
105
|
end
|
94
106
|
end
|
95
107
|
end
|
data/lib/icarus/mod/cli/sync.rb
CHANGED
@@ -22,176 +22,110 @@ module Icarus
|
|
22
22
|
|
23
23
|
desc "modinfo", "Reads from 'meta/repos/list' and Syncs any modinfo files we find (github only for now)"
|
24
24
|
def modinfo
|
25
|
-
|
26
|
-
|
27
|
-
puts "Retrieving repository Data..." if verbose?
|
28
|
-
repositories = modinfo_sync.repositories
|
29
|
-
|
30
|
-
raise Icarus::Mod::Tools::Error, "Unable to find any repositories!" unless repositories.any?
|
31
|
-
|
32
|
-
puts "Retrieving modinfo Array..." if verbose?
|
33
|
-
modinfo_array = modinfo_sync.modinfo_data(repositories, verbose: verbose > 1)&.map(&:download_url)&.compact
|
34
|
-
|
35
|
-
raise Icarus::Mod::Tools::Error, "No modinfo.json files found" unless modinfo_array&.any?
|
36
|
-
|
37
|
-
if options[:dry_run]
|
38
|
-
puts "Dry run; no changes will be made"
|
39
|
-
return
|
40
|
-
end
|
41
|
-
|
42
|
-
puts "Saving to Firestore..." if verbose?
|
43
|
-
response = modinfo_sync.update(modinfo_array)
|
44
|
-
puts response ? "Success" : "Failure (may be no changes)" if verbose?
|
45
|
-
rescue Icarus::Mod::Tools::Error => e
|
46
|
-
warn e.message
|
25
|
+
sync_info(:modinfo)
|
47
26
|
end
|
48
27
|
|
49
28
|
desc "proginfo", "Reads from 'meta/repos/list' and Syncs any proginfo files we find (github only for now)"
|
50
29
|
def proginfo
|
51
|
-
|
52
|
-
|
53
|
-
puts "Retrieving repository Data..." if verbose?
|
54
|
-
repositories = proginfo_sync.repositories
|
55
|
-
|
56
|
-
raise Icarus::Mod::Tools::Error, "Unable to find any repositories!" unless repositories.any?
|
57
|
-
|
58
|
-
puts "Retrieving proginfo Array..." if verbose?
|
59
|
-
proginfo_array = proginfo_sync.proginfo_data(repositories, verbose: verbose > 1)&.map(&:download_url)&.compact
|
60
|
-
|
61
|
-
raise Icarus::Mod::Tools::Error, "no proginfo.json files found" unless proginfo_array&.any?
|
62
|
-
|
63
|
-
if options[:dry_run]
|
64
|
-
puts "Dry run; no changes will be made"
|
65
|
-
return
|
66
|
-
end
|
67
|
-
|
68
|
-
puts "Saving to Firestore..." if verbose?
|
69
|
-
response = proginfo_sync.update(proginfo_array)
|
70
|
-
puts response ? "Success" : "Failure (may be no changes)" if verbose?
|
71
|
-
rescue Icarus::Mod::Tools::Error => e
|
72
|
-
warn e.message
|
30
|
+
sync_info(:proginfo)
|
73
31
|
end
|
74
32
|
|
75
33
|
desc "mods", "Reads from 'meta/modinfo/list' and updates the 'mods' database accordingly"
|
76
34
|
method_option :check, type: :boolean, default: false, desc: "Validate modinfo without applying changes"
|
77
35
|
def mods
|
78
|
-
|
79
|
-
|
80
|
-
puts "Retrieving modinfo Data..." if verbose?
|
81
|
-
modinfo_array = modsync.modinfo_array
|
36
|
+
sync_list(:mods)
|
37
|
+
end
|
82
38
|
|
83
|
-
|
84
|
-
|
39
|
+
desc "progs", "Reads from 'meta/proginfo/list' and updates the 'progs' database accordingly"
|
40
|
+
method_option :check, type: :boolean, default: false, desc: "Validate proginfo without applying changes"
|
41
|
+
def progs
|
42
|
+
sync_list(:progs)
|
43
|
+
end
|
85
44
|
|
86
|
-
|
45
|
+
no_commands do
|
46
|
+
def sync_info(type)
|
47
|
+
sync = (type == :modinfo ? Icarus::Mod::Tools::ModinfoSync : Icarus::Mod::Tools::ProginfoSync).new
|
87
48
|
|
88
|
-
|
89
|
-
|
90
|
-
verb = "Creating"
|
49
|
+
puts "Retrieving repository Data..." if verbose?
|
50
|
+
repositories = sync.repositories
|
91
51
|
|
92
|
-
|
93
|
-
warn "Skipping mod #{mod.uniq_name} due to validation errors" && next unless mod.validate
|
52
|
+
raise Icarus::Mod::Tools::Error, "Unable to find any repositories!" unless repositories.any?
|
94
53
|
|
95
|
-
|
96
|
-
|
97
|
-
puts "Found existing mod #{mod.name} at #{doc_id}" if verbose > 2
|
98
|
-
mod.id = doc_id
|
99
|
-
verb = "Updating"
|
100
|
-
end
|
54
|
+
puts "Retrieving Info Array..." if verbose?
|
55
|
+
info_array = sync.data(repositories, verbose: verbose > 1)&.map(&:download_url)&.compact
|
101
56
|
|
102
|
-
|
57
|
+
raise Icarus::Mod::Tools::Error, "no .json files found for #{type}" unless info_array&.any?
|
103
58
|
|
104
59
|
if options[:dry_run]
|
105
|
-
puts "Dry run; no changes will be made"
|
106
|
-
|
60
|
+
puts "Dry run; no changes will be made"
|
61
|
+
return
|
107
62
|
end
|
108
63
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
puts "Dry run; no changes will be made" if verbose?
|
115
|
-
return
|
64
|
+
puts "Saving to Firestore..." if verbose?
|
65
|
+
response = sync.update(info_array)
|
66
|
+
puts response ? "Success" : "Failure (may be no changes)" if verbose?
|
67
|
+
rescue Icarus::Mod::Tools::Error => e
|
68
|
+
warn e.message
|
116
69
|
end
|
117
70
|
|
118
|
-
|
71
|
+
def sync_list(type)
|
72
|
+
sync = (type == :mods ? Icarus::Mod::Tools::ModSync : Icarus::Mod::Tools::ProgSync).new
|
119
73
|
|
120
|
-
|
74
|
+
puts "Retrieving Info Data..." if verbose?
|
75
|
+
info_array = sync.info_array
|
121
76
|
|
122
|
-
|
123
|
-
|
124
|
-
puts "Deleting outdated mods..." if verbose?
|
125
|
-
delete_array.each do |mod|
|
126
|
-
print format("Deleting %-<name>60s", name: "'#{mod.author || "NoOne"}/#{mod.name || "Unnamed'"}") if verbose > 1
|
127
|
-
response = modsync.delete(mod)
|
128
|
-
puts format("%<status>10s", status: response ? "Success" : "Failure") if verbose > 1
|
129
|
-
end
|
130
|
-
|
131
|
-
puts "Deleted #{delete_array.count} outdated mods" if verbose?
|
132
|
-
rescue Icarus::Mod::Tools::Error => e
|
133
|
-
warn e.message
|
134
|
-
end
|
77
|
+
puts "Retrieving List Data..." if verbose?
|
78
|
+
list_array = sync.send(type)
|
135
79
|
|
136
|
-
|
137
|
-
method_option :check, type: :boolean, default: false, desc: "Validate proginfo without applying changes"
|
138
|
-
def progs
|
139
|
-
progsync = Icarus::Mod::Tools::ProgSync.new
|
80
|
+
return if options[:check]
|
140
81
|
|
141
|
-
|
142
|
-
|
82
|
+
puts "Updating List Data..." if verbose?
|
83
|
+
info_array.each do |list|
|
84
|
+
verb = "Creating"
|
143
85
|
|
144
|
-
|
145
|
-
|
86
|
+
puts "Validating Info Data for #{list.uniq_name}..." if verbose > 2
|
87
|
+
warn "Skipping List #{list.uniq_name} due to validation errors" && next unless list.valid?
|
146
88
|
|
147
|
-
|
89
|
+
doc_id = sync.find(list)
|
90
|
+
if doc_id
|
91
|
+
puts "Found existing list #{list.name} at #{doc_id}" if verbose > 2
|
92
|
+
list.id = doc_id
|
93
|
+
verb = "Updating"
|
94
|
+
end
|
148
95
|
|
149
|
-
|
150
|
-
proginfo_array.each do |prog|
|
151
|
-
verb = "Creating"
|
96
|
+
print format("#{verb} %-<name>60s", name: "'#{list.author || "NoOne"}/#{list.name || "Unnamed"}'") if verbose > 1
|
152
97
|
|
153
|
-
|
154
|
-
|
98
|
+
if options[:dry_run]
|
99
|
+
puts "Dry run; no changes will be made" if verbose > 1
|
100
|
+
next
|
101
|
+
end
|
155
102
|
|
156
|
-
|
157
|
-
|
158
|
-
puts "Found existing program #{prog.name} at #{doc_id}" if verbose > 2
|
159
|
-
prog.id = doc_id
|
160
|
-
verb = "Updating"
|
103
|
+
response = sync.update(list)
|
104
|
+
puts format("%<status>10s", status: response ? "Success" : "Failure") if verbose > 1
|
161
105
|
end
|
162
106
|
|
163
|
-
print format("#{verb} %-<name>60s", name: "'#{prog.author || "NoOne"}/#{prog.name || "Unnamed"}'") if verbose > 1
|
164
|
-
|
165
107
|
if options[:dry_run]
|
166
|
-
puts "Dry run; no changes will be made" if verbose
|
167
|
-
|
108
|
+
puts "Dry run; no changes will be made" if verbose?
|
109
|
+
return
|
168
110
|
end
|
169
111
|
|
170
|
-
|
171
|
-
puts format("%<status>10s", status: response ? "Success" : "Failure") if verbose > 1
|
172
|
-
end
|
112
|
+
puts "Created/Updated #{info_array.count} Items" if verbose?
|
173
113
|
|
174
|
-
|
175
|
-
puts "Dry run; no changes will be made" if verbose?
|
176
|
-
return
|
177
|
-
end
|
178
|
-
|
179
|
-
puts "Created/Updated #{proginfo_array.count} Programs" if verbose?
|
114
|
+
delete_array = list_array.filter { |list| sync.find_info(list).nil? }
|
180
115
|
|
181
|
-
|
116
|
+
return unless delete_array.any?
|
182
117
|
|
183
|
-
|
118
|
+
puts "Deleting outdated items..." if verbose?
|
119
|
+
delete_array.each do |list|
|
120
|
+
print format("Deleting %-<name>60s", name: "'#{list.author || "NoOne"}/#{list.name || "Unnamed'"}") if verbose > 1
|
121
|
+
response = sync.delete(list)
|
122
|
+
puts format("%<status>10s", status: response ? "Success" : "Failure") if verbose > 1
|
123
|
+
end
|
184
124
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
response = progsync.delete(prog)
|
189
|
-
puts format("%<status>10s", status: response ? "Success" : "Failure") if verbose > 1
|
125
|
+
puts "Deleted #{delete_array.count} outdated items" if verbose?
|
126
|
+
rescue Icarus::Mod::Tools::Error => e
|
127
|
+
warn e.message
|
190
128
|
end
|
191
|
-
|
192
|
-
puts "Deleted #{delete_array.count} outdated programs" if verbose?
|
193
|
-
rescue Icarus::Mod::Tools::Error => e
|
194
|
-
warn e.message
|
195
129
|
end
|
196
130
|
end
|
197
131
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "tools/
|
3
|
+
require "tools/validator"
|
4
4
|
|
5
5
|
module Icarus
|
6
6
|
module Mod
|
@@ -9,35 +9,46 @@ module Icarus
|
|
9
9
|
class Validate < SubcommandBase
|
10
10
|
desc "modinfo", "Reads modinfo data from 'meta/modinfo/list' and Validates syntax of modfiles"
|
11
11
|
def modinfo
|
12
|
-
|
13
|
-
|
12
|
+
validate(:modinfo)
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "proginfo", "Reads proginfo data from 'meta/proginfo/list' and Validates syntax of progfiles"
|
16
|
+
def proginfo
|
17
|
+
validate(:proginfo)
|
18
|
+
end
|
14
19
|
|
15
|
-
|
16
|
-
|
20
|
+
no_commands do
|
21
|
+
def validate(type)
|
22
|
+
exit_code = 0
|
23
|
+
validator = Icarus::Mod::Tools::Validator.new(type)
|
17
24
|
|
18
|
-
|
19
|
-
|
25
|
+
puts "Validating Entries..." if verbose?
|
26
|
+
max_length = validator.array.map { |info| info.uniq_name.length }.max + 1
|
20
27
|
|
21
|
-
|
28
|
+
validator.array.each do |info|
|
29
|
+
print Paint[format("%s %-#{max_length}s", "Running validation steps on", info.uniq_name), :cyan, :bright] if verbose > 1
|
22
30
|
|
23
|
-
|
24
|
-
puts Paint["SUCCESS", :green, :bright] if verbose > 1
|
25
|
-
next
|
26
|
-
end
|
31
|
+
info.valid?
|
27
32
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
33
|
+
unless info.errors? || info.warnings?
|
34
|
+
puts Paint["SUCCESS", :green, :bright] if verbose > 1
|
35
|
+
next
|
36
|
+
end
|
37
|
+
|
38
|
+
if info.errors?
|
39
|
+
exit_code = 1
|
40
|
+
puts Paint["ERROR", :red, :bright] if verbose? && verbose > 1
|
41
|
+
puts info.errors.map { |error| Paint["#{error} in #{info.uniq_name}", :red] }.join("\n")
|
42
|
+
puts "\n" if verbose > 1
|
43
|
+
end
|
44
|
+
|
45
|
+
puts Paint["WARNING", :yellow, :bright] if info.warnings.any? && verbose > 1
|
46
|
+
puts info.warnings.map { |warning| Paint["#{warning} in #{info.uniq_name}", :yellow] }.join("\n")
|
32
47
|
puts "\n" if verbose > 1
|
33
48
|
end
|
34
49
|
|
35
|
-
|
36
|
-
puts modinfo.warnings.map { |warning| Paint["#{warning} in #{modinfo.uniq_name}", :yellow] }.join("\n")
|
37
|
-
puts "\n" if verbose > 1
|
50
|
+
exit exit_code
|
38
51
|
end
|
39
|
-
|
40
|
-
exit exit_code
|
41
52
|
end
|
42
53
|
end
|
43
54
|
end
|
@@ -5,7 +5,7 @@ module Icarus
|
|
5
5
|
module Tools
|
6
6
|
# Base class for Modinfo and Proginfo
|
7
7
|
class Baseinfo
|
8
|
-
attr_reader :data, :
|
8
|
+
attr_reader :data, :id, :created_at, :updated_at
|
9
9
|
|
10
10
|
HASHKEYS = %i[name author version compatibility description fileType fileURL imageURL readmeURL].freeze
|
11
11
|
|
@@ -23,8 +23,24 @@ module Icarus
|
|
23
23
|
@data = data.is_a?(String) ? JSON.parse(data, symbolize_names: true) : data
|
24
24
|
end
|
25
25
|
|
26
|
+
def errors
|
27
|
+
@errors.compact.uniq
|
28
|
+
end
|
29
|
+
|
30
|
+
def errors?
|
31
|
+
@errors.compact.any?
|
32
|
+
end
|
33
|
+
|
34
|
+
def warnings
|
35
|
+
@warnings.compact.uniq
|
36
|
+
end
|
37
|
+
|
38
|
+
def warnings?
|
39
|
+
@warnings.compact.any?
|
40
|
+
end
|
41
|
+
|
26
42
|
def uniq_name
|
27
|
-
"#{author}/#{name}"
|
43
|
+
"#{author.strip}/#{name.strip}"
|
28
44
|
end
|
29
45
|
|
30
46
|
def to_json(*args)
|
@@ -35,7 +51,7 @@ module Icarus
|
|
35
51
|
HASHKEYS.each_with_object({}) { |key, hash| hash[key] = @data[key] }
|
36
52
|
end
|
37
53
|
|
38
|
-
def
|
54
|
+
def valid?
|
39
55
|
@warnings << "Version should be a version string" unless validate_version(version)
|
40
56
|
|
41
57
|
%w[name author description].each do |key|
|
@@ -48,10 +64,10 @@ module Icarus
|
|
48
64
|
@errors << "Invalid URL #{key.capitalize}: #{@data[key.to_sym] || "blank"}" unless validate_url(@data[key.to_sym])
|
49
65
|
end
|
50
66
|
|
51
|
-
|
67
|
+
!errors?
|
52
68
|
end
|
53
69
|
|
54
|
-
def method_missing(method_name, *_args, &)
|
70
|
+
def method_missing(method_name, *_args, &_block)
|
55
71
|
@data[method_name.to_sym]&.strip
|
56
72
|
end
|
57
73
|
|
@@ -61,6 +77,10 @@ module Icarus
|
|
61
77
|
|
62
78
|
private
|
63
79
|
|
80
|
+
def filetype_pattern
|
81
|
+
/(zip|pak|exmodz?)/i
|
82
|
+
end
|
83
|
+
|
64
84
|
def validate_url(url)
|
65
85
|
return true if url.nil? || url.empty?
|
66
86
|
|
@@ -68,7 +88,7 @@ module Icarus
|
|
68
88
|
end
|
69
89
|
|
70
90
|
def validate_filetype(filetype)
|
71
|
-
|
91
|
+
filetype.match?(filetype_pattern)
|
72
92
|
end
|
73
93
|
|
74
94
|
def validate_string(string)
|
@@ -18,8 +18,8 @@ module Icarus
|
|
18
18
|
@firestore.mods
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
@
|
21
|
+
def info_array
|
22
|
+
@info_array ||= @firestore.modinfo_list.map do |url|
|
23
23
|
retrieve_from_url(url)[:mods].map { |mod| Modinfo.new(mod) if mod[:name] =~ /[a-z0-9]+/i }
|
24
24
|
rescue Icarus::Mod::Tools::RequestFailed
|
25
25
|
warn "Skipped; Failed to retrieve #{url}"
|
@@ -30,12 +30,12 @@ module Icarus
|
|
30
30
|
end.flatten.compact
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
33
|
+
def find(modinfo)
|
34
34
|
@firestore.find_by_type(type: "mods", name: modinfo.name, author: modinfo.author)&.id
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
38
|
-
@
|
37
|
+
def find_info(modinfo)
|
38
|
+
@info_array.find { |mod| mod.name == modinfo.name }
|
39
39
|
end
|
40
40
|
|
41
41
|
def update(modinfo)
|
@@ -18,8 +18,8 @@ module Icarus
|
|
18
18
|
@firestore.progs
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
@
|
21
|
+
def info_array
|
22
|
+
@info_array ||= @firestore.proginfo_list.map do |url|
|
23
23
|
retrieve_from_url(url)[:programs].map { |prog| Proginfo.new(prog) if prog[:name] =~ /[a-z0-9]+/i }
|
24
24
|
rescue Icarus::Mod::Tools::RequestFailed
|
25
25
|
warn "Skipped; Failed to retrieve #{url}"
|
@@ -30,12 +30,12 @@ module Icarus
|
|
30
30
|
end.flatten.compact
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
33
|
+
def find(proginfo)
|
34
34
|
@firestore.find_by_type(type: "progs", name: proginfo.name, author: proginfo.author)&.id
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
38
|
-
@
|
37
|
+
def find_info(proginfo)
|
38
|
+
@info_array.find { |prog| prog.name == proginfo.name }
|
39
39
|
end
|
40
40
|
|
41
41
|
def update(proginfo)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Icarus
|
4
|
+
module Mod
|
5
|
+
module Tools
|
6
|
+
# Validate Methods
|
7
|
+
class Validator
|
8
|
+
attr_reader :array
|
9
|
+
|
10
|
+
def initialize(type)
|
11
|
+
@array = case type
|
12
|
+
when :modinfo
|
13
|
+
ModSync.new.info_array
|
14
|
+
when :proginfo
|
15
|
+
ProgSync.new.info_array
|
16
|
+
else
|
17
|
+
raise ArgumentError, "Invalid type: #{type}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/icarus/mod/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Icarus-Mod-Tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Donovan Young
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-cloud-firestore
|
@@ -101,11 +101,11 @@ files:
|
|
101
101
|
- lib/icarus/mod/tools/mod_sync.rb
|
102
102
|
- lib/icarus/mod/tools/modinfo.rb
|
103
103
|
- lib/icarus/mod/tools/modinfo_sync.rb
|
104
|
-
- lib/icarus/mod/tools/modinfo_validate.rb
|
105
104
|
- lib/icarus/mod/tools/prog_sync.rb
|
106
105
|
- lib/icarus/mod/tools/proginfo.rb
|
107
106
|
- lib/icarus/mod/tools/proginfo_sync.rb
|
108
107
|
- lib/icarus/mod/tools/sync_helpers.rb
|
108
|
+
- lib/icarus/mod/tools/validator.rb
|
109
109
|
- lib/icarus/mod/version.rb
|
110
110
|
- sig/database/sync/sync.rbs
|
111
111
|
homepage: https://github.com/DonovanMods/icarus-mod-tools
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Icarus
|
4
|
-
module Mod
|
5
|
-
module Tools
|
6
|
-
# Validate Methods
|
7
|
-
class ModinfoValidate
|
8
|
-
attr_reader :modinfo_array
|
9
|
-
|
10
|
-
def initialize
|
11
|
-
@modinfo_array = ModSync.new.modinfo_array
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|