gamerom 0.2.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +1 -1
- data/.rubocop.yml +35 -2
- data/.ruby-version +1 -1
- data/CHANGELOG.md +27 -1
- data/Dockerfile +7 -2
- data/Gemfile +4 -4
- data/Gemfile.lock +5 -5
- data/Makefile +1 -1
- data/README.md +117 -71
- data/Rakefile +3 -3
- data/bin/console +3 -3
- data/entrypoint.sh +6 -0
- data/exe/gamerom +2 -1
- data/gamerom.gemspec +22 -22
- data/lib/gamerom.rb +6 -5
- data/lib/gamerom/cli.rb +93 -77
- data/lib/gamerom/config.rb +2 -2
- data/lib/gamerom/game.rb +20 -14
- data/lib/gamerom/game_info.rb +93 -0
- data/lib/gamerom/repo.rb +24 -25
- data/lib/gamerom/repo_adapter.rb +26 -0
- data/lib/gamerom/repo_adapters/coolrom.rb +29 -25
- data/lib/gamerom/repo_adapters/romnation.rb +110 -0
- data/lib/gamerom/repo_adapters/vimm.rb +33 -29
- data/lib/gamerom/version.rb +1 -1
- data/lib/mechanizeprogress.rb +14 -10
- metadata +8 -4
data/Rakefile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
5
|
|
6
6
|
RSpec::Core::RakeTask.new(:spec)
|
7
7
|
|
8
|
-
require
|
8
|
+
require 'rubocop/rake_task'
|
9
9
|
|
10
10
|
RuboCop::RakeTask.new
|
11
11
|
|
data/bin/console
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'gamerom'
|
6
6
|
|
7
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
8
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -11,5 +11,5 @@ require "gamerom"
|
|
11
11
|
# require "pry"
|
12
12
|
# Pry.start
|
13
13
|
|
14
|
-
require
|
14
|
+
require 'irb'
|
15
15
|
IRB.start(__FILE__)
|
data/entrypoint.sh
ADDED
data/exe/gamerom
CHANGED
data/gamerom.gemspec
CHANGED
@@ -1,40 +1,40 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative 'lib/gamerom/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name =
|
6
|
+
spec.name = 'gamerom'
|
7
7
|
spec.version = Gamerom::VERSION
|
8
|
-
spec.authors = [
|
9
|
-
spec.email = [
|
8
|
+
spec.authors = ['Lucas Mundim']
|
9
|
+
spec.email = ['lucas.mundim@gmail.com']
|
10
10
|
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
15
|
-
spec.required_ruby_version = Gem::Requirement.new(
|
11
|
+
spec.summary = 'The Video Game ROM downloader'
|
12
|
+
spec.description = 'A command-line installer for game ROMs from many repositories.'
|
13
|
+
spec.homepage = 'https://github.com/lucasmundim/gamerom'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 3.0.1')
|
16
16
|
|
17
|
-
spec.metadata[
|
17
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
18
18
|
|
19
|
-
spec.metadata[
|
20
|
-
spec.metadata[
|
21
|
-
spec.metadata[
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
20
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
21
|
+
spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/CHANGELOG.md"
|
22
22
|
|
23
23
|
# Specify which files should be added to the gem when it is released.
|
24
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
25
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
26
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
27
27
|
end
|
28
|
-
spec.bindir =
|
28
|
+
spec.bindir = 'exe'
|
29
29
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
-
spec.require_paths = [
|
31
|
-
|
32
|
-
spec.add_runtime_dependency
|
33
|
-
spec.add_runtime_dependency
|
34
|
-
spec.add_runtime_dependency
|
35
|
-
spec.add_runtime_dependency
|
36
|
-
spec.add_runtime_dependency
|
37
|
-
spec.add_runtime_dependency
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
spec.add_runtime_dependency 'mechanize', '~> 2.8.0'
|
33
|
+
spec.add_runtime_dependency 'mechanize-progressbar', '~> 0.2.0'
|
34
|
+
spec.add_runtime_dependency 'nokogiri', '~> 1.11.3'
|
35
|
+
spec.add_runtime_dependency 'progressbar', '~> 0.9.0'
|
36
|
+
spec.add_runtime_dependency 'rest-client', '~> 2.1.0'
|
37
|
+
spec.add_runtime_dependency 'thor', '~> 1.1.0'
|
38
38
|
|
39
39
|
# For more information and examples about making a new gem, checkout our
|
40
40
|
# guide at: https://bundler.io/guides/creating_gem.html
|
data/lib/gamerom.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
require_relative
|
7
|
-
require_relative
|
3
|
+
require_relative 'gamerom/config'
|
4
|
+
require_relative 'gamerom/game'
|
5
|
+
require_relative 'gamerom/game_info'
|
6
|
+
require_relative 'gamerom/repo'
|
7
|
+
require_relative 'gamerom/cli'
|
8
|
+
require_relative 'gamerom/version'
|
8
9
|
|
9
10
|
module Gamerom
|
10
11
|
class Error < StandardError; end
|
data/lib/gamerom/cli.rb
CHANGED
@@ -3,8 +3,9 @@
|
|
3
3
|
require 'thor'
|
4
4
|
|
5
5
|
module Gamerom
|
6
|
+
# Cli - Main cli commands
|
6
7
|
class Cli < Thor
|
7
|
-
class_option :verbose, :
|
8
|
+
class_option :verbose, aliases: ['-v'], type: :boolean, default: false, desc: 'Show verbose backtrace'
|
8
9
|
|
9
10
|
def self.exit_on_failure?
|
10
11
|
true
|
@@ -22,27 +23,30 @@ module Gamerom
|
|
22
23
|
end
|
23
24
|
|
24
25
|
desc 'info GAME_IDENTIFIER', 'Info for game GAME_IDENTIFIER (id/name)'
|
25
|
-
option :repo, :
|
26
|
-
option :platform, :
|
27
|
-
def info(
|
26
|
+
option :repo, aliases: ['-r'], type: :string, required: true, desc: 'Which repo to use', enum: Gamerom::Repo.list.map(&:to_s)
|
27
|
+
option :platform, aliases: ['-p'], type: :string, required: true, desc: 'Which platform to use'
|
28
|
+
def info(*args)
|
29
|
+
game_identifier = args.join(' ')
|
28
30
|
repo = Repo.new(options[:repo])
|
29
31
|
validate_platform repo, options[:platform]
|
30
32
|
puts "showing info for game #{game_identifier} on #{options[:platform]} platform on #{options[:repo]} repo..."
|
31
33
|
game = repo.find(options[:platform], game_identifier)
|
32
|
-
if game.nil?
|
34
|
+
if !game.nil?
|
35
|
+
puts game
|
36
|
+
puts game.filenames if game.installed?
|
37
|
+
else
|
33
38
|
shell.say "Game #{game_identifier} not found", :red
|
34
39
|
end
|
35
|
-
|
36
|
-
puts game.filenames if game.installed?
|
37
|
-
rescue => e
|
40
|
+
rescue StandardError => e
|
38
41
|
render_error e, options
|
39
42
|
exit 1
|
40
43
|
end
|
41
44
|
|
42
45
|
desc 'install GAME_IDENTIFIER', 'Install game GAME_IDENTIFIER (id/name)'
|
43
|
-
option :repo, :
|
44
|
-
option :platform, :
|
45
|
-
def install(
|
46
|
+
option :repo, aliases: ['-r'], type: :string, required: true, desc: 'Which repo to use', enum: Gamerom::Repo.list.map(&:to_s)
|
47
|
+
option :platform, aliases: ['-p'], type: :string, required: true, desc: 'Which platform to use'
|
48
|
+
def install(*args)
|
49
|
+
game_identifier = args.join(' ')
|
46
50
|
repo = Repo.new(options[:repo])
|
47
51
|
validate_platform repo, options[:platform]
|
48
52
|
game = repo.find(options[:platform], game_identifier)
|
@@ -52,20 +56,20 @@ module Gamerom
|
|
52
56
|
end
|
53
57
|
puts "installing game #{game.id} - #{game.name} - #{game.region} on #{options[:platform]} platform on #{options[:repo]} repo..."
|
54
58
|
if game.installed?
|
55
|
-
shell.say
|
59
|
+
shell.say 'Game already installed', :yellow
|
56
60
|
return
|
57
61
|
end
|
58
62
|
game.install
|
59
|
-
shell.say
|
60
|
-
rescue => e
|
63
|
+
shell.say 'Game installed', :green
|
64
|
+
rescue StandardError => e
|
61
65
|
render_error e, options
|
62
66
|
exit 1
|
63
67
|
end
|
64
68
|
|
65
69
|
desc 'install_all', 'Install all games'
|
66
|
-
option :repo, :
|
67
|
-
option :platform, :
|
68
|
-
option :region, :
|
70
|
+
option :repo, aliases: ['-r'], type: :string, required: true, desc: 'Which repo to use', enum: Gamerom::Repo.list.map(&:to_s)
|
71
|
+
option :platform, aliases: ['-p'], type: :string, required: true, desc: 'Which platform to use'
|
72
|
+
option :region, aliases: ['-g'], type: :string, required: false, desc: 'Only from specified region'
|
69
73
|
def install_all
|
70
74
|
repo = Repo.new(options[:repo])
|
71
75
|
validate_platform repo, options[:platform]
|
@@ -73,40 +77,40 @@ module Gamerom
|
|
73
77
|
games.each do |game|
|
74
78
|
install(game.id) unless game.installed?
|
75
79
|
end
|
76
|
-
rescue => e
|
80
|
+
rescue StandardError => e
|
77
81
|
render_error e, options
|
78
82
|
exit 1
|
79
83
|
end
|
80
84
|
|
81
85
|
desc 'list', 'List available games'
|
82
|
-
option :repo, :
|
83
|
-
option :platform, :
|
84
|
-
option :region, :
|
86
|
+
option :repo, aliases: ['-r'], type: :string, required: true, desc: 'Which repo to use', enum: Gamerom::Repo.list.map(&:to_s)
|
87
|
+
option :platform, aliases: ['-p'], type: :string, required: true, desc: 'Which platform to use'
|
88
|
+
option :region, aliases: ['-g'], type: :string, required: false, desc: 'Only from specified region'
|
85
89
|
def list
|
86
90
|
repo = Repo.new(options[:repo])
|
87
91
|
validate_platform repo, options[:platform]
|
88
92
|
puts "listing available games for #{options[:platform]} platform on #{options[:repo]} repo..."
|
89
93
|
games = repo.games options[:platform], region: options[:region]
|
90
94
|
print_game_table(games)
|
91
|
-
rescue => e
|
95
|
+
rescue StandardError => e
|
92
96
|
render_error e, options
|
93
97
|
exit 1
|
94
98
|
end
|
95
99
|
|
96
100
|
desc 'platforms', 'List available platforms'
|
97
|
-
option :repo, :
|
101
|
+
option :repo, aliases: ['-r'], type: :string, required: true, desc: 'Which repo to use', enum: Gamerom::Repo.list.map(&:to_s)
|
98
102
|
def platforms
|
99
103
|
puts "listing available platforms for #{options[:repo]} repo..."
|
100
104
|
platforms = { platforms: Repo.new(options[:repo]).platforms }
|
101
105
|
puts platforms.to_yaml
|
102
|
-
rescue => e
|
106
|
+
rescue StandardError => e
|
103
107
|
render_error e, options
|
104
108
|
exit 1
|
105
109
|
end
|
106
110
|
|
107
111
|
desc 'recover', 'Try to recover state from already downloaded roms'
|
108
|
-
option :repo, :
|
109
|
-
option :platform, :
|
112
|
+
option :repo, aliases: ['-r'], type: :string, required: true, desc: 'Which repo to use', enum: Gamerom::Repo.list.map(&:to_s)
|
113
|
+
option :platform, aliases: ['-p'], type: :string, required: true, desc: 'Which platform to use'
|
110
114
|
def recover
|
111
115
|
repo = Repo.new(options[:repo])
|
112
116
|
validate_platform repo, options[:platform]
|
@@ -116,10 +120,9 @@ module Gamerom
|
|
116
120
|
games.each do |game|
|
117
121
|
filename = nil
|
118
122
|
basename = "#{Gamerom::GAME_DIR}/#{repo.name}/#{options[:platform]}/#{game[:region]}/#{game[:name]}"
|
119
|
-
[
|
120
|
-
|
121
|
-
|
122
|
-
end
|
123
|
+
%w[zip 7z rar].each do |ext|
|
124
|
+
fullname = "#{basename}.#{ext}"
|
125
|
+
filename = fullname if File.exist? fullname
|
123
126
|
end
|
124
127
|
|
125
128
|
if filename
|
@@ -129,101 +132,110 @@ module Gamerom
|
|
129
132
|
games_not_found << game[:name]
|
130
133
|
end
|
131
134
|
end
|
132
|
-
if games_not_found.count
|
133
|
-
puts
|
135
|
+
if games_not_found.count.positive?
|
136
|
+
puts 'Games not found:'
|
134
137
|
puts games_not_found
|
135
138
|
end
|
136
|
-
rescue => e
|
139
|
+
rescue StandardError => e
|
137
140
|
puts e.message
|
138
141
|
exit 1
|
139
142
|
end
|
140
143
|
|
141
144
|
desc 'regions', 'List available regions'
|
142
|
-
option :repo, :
|
143
|
-
option :platform, :
|
145
|
+
option :repo, aliases: ['-r'], type: :string, required: true, desc: 'Which repo to use', enum: Gamerom::Repo.list.map(&:to_s)
|
146
|
+
option :platform, aliases: ['-p'], type: :string, required: true, desc: 'Which platform to use'
|
144
147
|
def regions
|
145
148
|
repo = Repo.new(options[:repo])
|
146
149
|
validate_platform repo, options[:platform]
|
147
150
|
puts "listing available regions for #{options[:platform]} platform on #{options[:repo]} repo..."
|
148
151
|
puts repo.regions options[:platform]
|
149
|
-
rescue => e
|
152
|
+
rescue StandardError => e
|
150
153
|
render_error e, options
|
151
154
|
exit 1
|
152
155
|
end
|
153
156
|
|
154
157
|
desc 'repo', 'List available repo'
|
155
158
|
def repo
|
156
|
-
puts
|
159
|
+
puts 'listing available repo...'
|
157
160
|
puts Repo.list
|
158
|
-
rescue => e
|
161
|
+
rescue StandardError => e
|
159
162
|
render_error e, options
|
160
163
|
exit 1
|
161
164
|
end
|
162
165
|
|
163
166
|
desc 'search KEYWORD', 'Search games by KEYWORD'
|
164
|
-
option :repo, :
|
165
|
-
option :platform, :
|
166
|
-
option :region, :
|
167
|
-
|
167
|
+
option :repo, aliases: ['-r'], type: :string, required: true, desc: 'Which repo to use', enum: Gamerom::Repo.list.map(&:to_s)
|
168
|
+
option :platform, aliases: ['-p'], type: :string, required: true, desc: 'Which platform to use'
|
169
|
+
option :region, aliases: ['-g'], type: :string, required: false, desc: 'Only from specified region'
|
170
|
+
option :install, aliases: ['-I'], type: :boolean, required: false, desc: 'Install search results'
|
171
|
+
def search(*args)
|
172
|
+
keyword = args.join(' ')
|
168
173
|
repo = Repo.new(options[:repo])
|
169
174
|
validate_platform repo, options[:platform]
|
170
175
|
puts "searching available games for #{options[:platform]} platform on #{options[:repo]} repo..."
|
171
176
|
games = repo.games options[:platform], region: options[:region], keyword: keyword
|
172
|
-
|
173
|
-
|
177
|
+
if options[:install]
|
178
|
+
games.each do |game|
|
179
|
+
install(game.id) unless game.installed?
|
180
|
+
end
|
181
|
+
else
|
182
|
+
print_game_table(games)
|
183
|
+
end
|
184
|
+
rescue StandardError => e
|
174
185
|
render_error e, options
|
175
186
|
exit 1
|
176
187
|
end
|
177
188
|
|
178
189
|
desc 'stats', 'Show platform stats'
|
179
|
-
option :repo, :
|
180
|
-
option :platform, :
|
190
|
+
option :repo, aliases: ['-r'], type: :string, required: true, desc: 'Which repo to use', enum: Gamerom::Repo.list.map(&:to_s)
|
191
|
+
option :platform, aliases: ['-p'], type: :string, required: true, desc: 'Which platform to use'
|
181
192
|
def stats
|
182
193
|
repo = Repo.new(options[:repo])
|
183
194
|
validate_platform repo, options[:platform]
|
184
195
|
puts "stats for #{options[:platform]} platform on #{options[:repo]} repo..."
|
185
196
|
games = repo.games options[:platform]
|
186
197
|
total = games.count
|
187
|
-
installed = games.select
|
198
|
+
installed = games.select(&:installed?).count
|
188
199
|
size = 0
|
189
|
-
if File.
|
200
|
+
if File.exist? "#{Gamerom::GAME_DIR}/#{repo.name}/#{options[:platform]}"
|
190
201
|
size = `du -hs "#{Gamerom::GAME_DIR}/#{repo.name}/#{options[:platform]}/"|awk '{ print $1 }'`
|
191
202
|
end
|
192
203
|
puts " All: #{installed}/#{total} - size: #{size}"
|
193
204
|
repo.regions(options[:platform]).each do |region|
|
194
205
|
games = repo.games(options[:platform], region: region)
|
195
206
|
total = games.count
|
196
|
-
installed = games.select
|
207
|
+
installed = games.select(&:installed?).count
|
197
208
|
size = 0
|
198
|
-
if File.
|
209
|
+
if File.exist? "#{Gamerom::GAME_DIR}/#{repo.name}/#{options[:platform]}/#{region}"
|
199
210
|
size = `du -hs "#{Gamerom::GAME_DIR}/#{repo.name}/#{options[:platform]}/#{region}/"|awk '{ print $1 }'`
|
200
211
|
end
|
201
212
|
puts " #{region}: #{installed}/#{total} - size: #{size}"
|
202
213
|
end
|
203
214
|
puts
|
204
|
-
rescue => e
|
215
|
+
rescue StandardError => e
|
205
216
|
render_error e, options
|
206
217
|
exit 1
|
207
218
|
end
|
208
219
|
|
209
220
|
desc 'stats_all', 'Show stats for all platforms'
|
210
|
-
option :repo, :
|
221
|
+
option :repo, aliases: ['-r'], type: :string, required: true, desc: 'Which repo to use', enum: Gamerom::Repo.list.map(&:to_s)
|
211
222
|
def stats_all
|
212
223
|
repo = Repo.new(options[:repo])
|
213
|
-
repo.platforms.
|
224
|
+
repo.platforms.each_key do |platform|
|
214
225
|
a = Gamerom::Cli.new
|
215
226
|
a.options = { platform: platform, repo: options[:repo] }
|
216
227
|
a.stats
|
217
228
|
end
|
218
|
-
rescue => e
|
229
|
+
rescue StandardError => e
|
219
230
|
render_error e, options
|
220
231
|
exit 1
|
221
232
|
end
|
222
233
|
|
223
234
|
desc 'uninstall GAME_IDENTIFIER', 'Uninstall game GAME_IDENTIFIER (id/name)'
|
224
|
-
option :repo, :
|
225
|
-
option :platform, :
|
226
|
-
def uninstall(
|
235
|
+
option :repo, aliases: ['-r'], type: :string, required: true, desc: 'Which repo to use', enum: Gamerom::Repo.list.map(&:to_s)
|
236
|
+
option :platform, aliases: ['-p'], type: :string, required: true, desc: 'Which platform to use'
|
237
|
+
def uninstall(*args)
|
238
|
+
game_identifier = args.join(' ')
|
227
239
|
repo = Repo.new(options[:repo])
|
228
240
|
validate_platform repo, options[:platform]
|
229
241
|
game = repo.find(options[:platform], game_identifier)
|
@@ -232,21 +244,21 @@ module Gamerom
|
|
232
244
|
return
|
233
245
|
end
|
234
246
|
puts "uninstalling game #{game.id} - #{game.name} - #{game.region} on #{options[:platform]} platform..."
|
235
|
-
|
236
|
-
shell.say
|
247
|
+
unless game.installed?
|
248
|
+
shell.say 'Game is not installed', :yellow
|
237
249
|
return
|
238
250
|
end
|
239
251
|
game.uninstall
|
240
|
-
shell.say
|
241
|
-
rescue => e
|
252
|
+
shell.say 'Game uninstalled', :green
|
253
|
+
rescue StandardError => e
|
242
254
|
render_error e, options
|
243
255
|
exit 1
|
244
256
|
end
|
245
257
|
|
246
258
|
desc 'uninstall_all', 'Uninstall all games'
|
247
|
-
option :repo, :
|
248
|
-
option :platform, :
|
249
|
-
option :region, :
|
259
|
+
option :repo, aliases: ['-r'], type: :string, required: true, desc: 'Which repo to use', enum: Gamerom::Repo.list.map(&:to_s)
|
260
|
+
option :platform, aliases: ['-p'], type: :string, required: true, desc: 'Which platform to use'
|
261
|
+
option :region, aliases: ['-g'], type: :string, required: false, desc: 'Only from specified region'
|
250
262
|
def uninstall_all
|
251
263
|
repo = Repo.new(options[:repo])
|
252
264
|
validate_platform repo, options[:platform]
|
@@ -254,36 +266,36 @@ module Gamerom
|
|
254
266
|
games.each do |game|
|
255
267
|
uninstall(game.id) if game.installed?
|
256
268
|
end
|
257
|
-
rescue => e
|
269
|
+
rescue StandardError => e
|
258
270
|
render_error e, options
|
259
271
|
exit 1
|
260
272
|
end
|
261
273
|
|
262
274
|
desc 'update_all_databases', 'Update all local databases'
|
263
|
-
option :repo, :
|
275
|
+
option :repo, aliases: ['-r'], type: :string, required: true, desc: 'Which repo to use', enum: Gamerom::Repo.list.map(&:to_s)
|
264
276
|
def update_all_databases
|
277
|
+
puts "updating all databases on #{options[:repo]} repo..."
|
265
278
|
repo = Repo.new(options[:repo])
|
266
|
-
repo.platforms.
|
267
|
-
|
268
|
-
|
269
|
-
a.update_database
|
279
|
+
repo.platforms.each_key do |platform|
|
280
|
+
repo = Repo.new(options[:repo])
|
281
|
+
repo.update_database platform
|
270
282
|
end
|
271
283
|
shell.say 'All game databases updated', :green
|
272
|
-
rescue => e
|
284
|
+
rescue StandardError => e
|
273
285
|
render_error e, options
|
274
286
|
exit 1
|
275
287
|
end
|
276
288
|
|
277
289
|
desc 'update_database', 'Update local database'
|
278
|
-
option :repo, :
|
279
|
-
option :platform, :
|
290
|
+
option :repo, aliases: ['-r'], type: :string, required: true, desc: 'Which repo to use', enum: Gamerom::Repo.list.map(&:to_s)
|
291
|
+
option :platform, aliases: ['-p'], type: :string, required: true, desc: 'Which platform to use'
|
280
292
|
def update_database
|
281
293
|
repo = Repo.new(options[:repo])
|
282
294
|
validate_platform repo, options[:platform]
|
283
295
|
puts "updating #{options[:platform]} platform on #{options[:repo]} repo..."
|
284
296
|
repo.update_database options[:platform]
|
285
297
|
shell.say "Game database updated for platform #{options[:platform]} on #{options[:repo]} repo", :green
|
286
|
-
rescue => e
|
298
|
+
rescue StandardError => e
|
287
299
|
render_error e, options
|
288
300
|
exit 1
|
289
301
|
end
|
@@ -294,6 +306,7 @@ module Gamerom
|
|
294
306
|
end
|
295
307
|
|
296
308
|
private
|
309
|
+
|
297
310
|
def print_game_table(games)
|
298
311
|
results = []
|
299
312
|
|
@@ -303,20 +316,23 @@ module Gamerom
|
|
303
316
|
game.name,
|
304
317
|
game.region,
|
305
318
|
game.installed? ? shell.set_color('installed', :green) : '-',
|
319
|
+
game.respond_to?(:tags) ? game.tags.join(', ') : '-'
|
306
320
|
]
|
307
321
|
end
|
308
322
|
results.sort_by! { |columns| columns[1] }
|
309
|
-
results.unshift [
|
323
|
+
results.unshift %w[ID NAME REGION INSTALLED TAGS]
|
310
324
|
shell.print_table(results)
|
311
325
|
end
|
312
326
|
|
313
|
-
def render_error
|
327
|
+
def render_error(exception, options)
|
314
328
|
shell.say exception.message, :red
|
315
329
|
shell.say exception.full_message.force_encoding('utf-8'), :red if options[:verbose]
|
316
330
|
end
|
317
331
|
|
318
332
|
def validate_platform(repo, platform)
|
319
|
-
|
333
|
+
return if repo.platforms.keys.include? options[:platform]
|
334
|
+
|
335
|
+
raise "Expected '--platform' to be one of #{repo.platforms.keys.join(", ")}; got #{platform}"
|
320
336
|
end
|
321
337
|
end
|
322
338
|
end
|