gamerom 0.2.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
- require "rubocop/rake_task"
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 "bundler/setup"
5
- require "gamerom"
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 "irb"
14
+ require 'irb'
15
15
  IRB.start(__FILE__)
data/entrypoint.sh ADDED
@@ -0,0 +1,6 @@
1
+ #!/bin/sh
2
+ delgroup dialout
3
+ addgroup -g "$GROUP_ID" rungroup
4
+ adduser -u $UID -D -s /bin/sh -G rungroup runuser
5
+ command="cd /app && GEM_HOME="/bundle" PATH=$GEM_HOME/bin:$GEM_HOME/gems/bin:$PATH bundle exec ./exe/gamerom ${@}"
6
+ su - runuser -c "$command"
data/exe/gamerom CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "gamerom"
4
+ require 'gamerom'
4
5
 
5
6
  Gamerom::Cli.start(ARGV)
data/gamerom.gemspec CHANGED
@@ -1,40 +1,40 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/gamerom/version"
3
+ require_relative 'lib/gamerom/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "gamerom"
6
+ spec.name = 'gamerom'
7
7
  spec.version = Gamerom::VERSION
8
- spec.authors = ["Lucas Mundim"]
9
- spec.email = ["lucas.mundim@gmail.com"]
8
+ spec.authors = ['Lucas Mundim']
9
+ spec.email = ['lucas.mundim@gmail.com']
10
10
 
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.0")
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["allowed_push_host"] = "https://rubygems.org"
17
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
18
 
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"
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 = "exe"
28
+ spec.bindir = 'exe'
29
29
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
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"
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 "gamerom/config"
4
- require_relative "gamerom/game"
5
- require_relative "gamerom/repo"
6
- require_relative "gamerom/cli"
7
- require_relative "gamerom/version"
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, :aliases => ['-v'], :type => :boolean, default: false, desc: "Show verbose backtrace"
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, :aliases => ['-r'], type: :string, required: true, desc: "Which repo to use", enum: Gamerom::Repo.list.map(&:to_s)
26
- option :platform, :aliases => ['-p'], type: :string, required: true, desc: "Which platform to use"
27
- def info(game_identifier)
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
- puts game
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, :aliases => ['-r'], type: :string, required: true, desc: "Which repo to use", enum: Gamerom::Repo.list.map(&:to_s)
44
- option :platform, :aliases => ['-p'], type: :string, required: true, desc: "Which platform to use"
45
- def install(game_identifier)
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 "Game already installed", :yellow
59
+ shell.say 'Game already installed', :yellow
56
60
  return
57
61
  end
58
62
  game.install
59
- shell.say "Game installed", :green
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, :aliases => ['-r'], type: :string, required: true, desc: "Which repo to use", enum: Gamerom::Repo.list.map(&:to_s)
67
- option :platform, :aliases => ['-p'], type: :string, required: true, desc: "Which platform to use"
68
- option :region, :aliases => ['-g'], type: :string, required: false, desc: "Only from specified 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, :aliases => ['-r'], type: :string, required: true, desc: "Which repo to use", enum: Gamerom::Repo.list.map(&:to_s)
83
- option :platform, :aliases => ['-p'], type: :string, required: true, desc: "Which platform to use"
84
- option :region, :aliases => ['-g'], type: :string, required: false, desc: "Only from specified 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, :aliases => ['-r'], type: :string, required: true, desc: "Which repo to use", enum: Gamerom::Repo.list.map(&:to_s)
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, :aliases => ['-r'], type: :string, required: true, desc: "Which repo to use", enum: Gamerom::Repo.list.map(&:to_s)
109
- option :platform, :aliases => ['-p'], type: :string, required: true, desc: "Which platform to use"
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
- ['zip', '7z', 'rar'].each do |ext|
120
- if File.exists? "#{basename}.#{ext}"
121
- filename = "#{basename}.#{ext}"
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 > 0
133
- puts "Games not found:"
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, :aliases => ['-r'], type: :string, required: true, desc: "Which repo to use", enum: Gamerom::Repo.list.map(&:to_s)
143
- option :platform, :aliases => ['-p'], type: :string, required: true, desc: "Which platform to use"
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 "listing available repo..."
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, :aliases => ['-r'], type: :string, required: true, desc: "Which repo to use", enum: Gamerom::Repo.list.map(&:to_s)
165
- option :platform, :aliases => ['-p'], type: :string, required: true, desc: "Which platform to use"
166
- option :region, :aliases => ['-g'], type: :string, required: false, desc: "Only from specified region"
167
- def search(keyword)
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
- print_game_table(games)
173
- rescue => e
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, :aliases => ['-r'], type: :string, required: true, desc: "Which repo to use", enum: Gamerom::Repo.list.map(&:to_s)
180
- option :platform, :aliases => ['-p'], type: :string, required: true, desc: "Which platform to use"
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 { |game| game.installed? }.count
198
+ installed = games.select(&:installed?).count
188
199
  size = 0
189
- if File.exists? "#{Gamerom::GAME_DIR}/#{repo.name}/#{options[:platform]}"
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 { |game| game.installed? }.count
207
+ installed = games.select(&:installed?).count
197
208
  size = 0
198
- if File.exists? "#{Gamerom::GAME_DIR}/#{repo.name}/#{options[:platform]}/#{region}"
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, :aliases => ['-r'], type: :string, required: true, desc: "Which repo to use", enum: Gamerom::Repo.list.map(&:to_s)
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.keys.each do |platform|
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, :aliases => ['-r'], type: :string, required: true, desc: "Which repo to use", enum: Gamerom::Repo.list.map(&:to_s)
225
- option :platform, :aliases => ['-p'], type: :string, required: true, desc: "Which platform to use"
226
- def uninstall(game_identifier)
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
- if !game.installed?
236
- shell.say "Game is not installed", :yellow
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 "Game uninstalled", :green
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, :aliases => ['-r'], type: :string, required: true, desc: "Which repo to use", enum: Gamerom::Repo.list.map(&:to_s)
248
- option :platform, :aliases => ['-p'], type: :string, required: true, desc: "Which platform to use"
249
- option :region, :aliases => ['-g'], type: :string, required: false, desc: "Only from specified 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, :aliases => ['-r'], type: :string, required: true, desc: "Which repo to use", enum: Gamerom::Repo.list.map(&:to_s)
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.keys.each do |platform|
267
- a = Gamerom::Cli.new
268
- a.options = { platform: platform, repo: options[:repo] }
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, :aliases => ['-r'], type: :string, required: true, desc: "Which repo to use", enum: Gamerom::Repo.list.map(&:to_s)
279
- option :platform, :aliases => ['-p'], type: :string, required: true, desc: "Which platform to use"
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 ['ID', 'NAME', 'REGION', 'INSTALLED']
323
+ results.unshift %w[ID NAME REGION INSTALLED TAGS]
310
324
  shell.print_table(results)
311
325
  end
312
326
 
313
- def render_error exception, options
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
- raise "Expected '--platform' to be one of #{repo.platforms.keys.join(', ')}; got #{platform}" if !repo.platforms.keys.include? options[:platform]
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