Class: Gamerom::Cli
- Inherits:
-
Thor
- Object
- Thor
- Gamerom::Cli
- Defined in:
- lib/gamerom/cli.rb
Overview
Cli - Main cli commands
Class Method Summary collapse
Instance Method Summary collapse
- #config ⇒ Object
- #info(*args) ⇒ Object
- #install(*args) ⇒ Object
- #install_all ⇒ Object
- #list ⇒ Object
- #platforms ⇒ Object
- #recover ⇒ Object
- #regions ⇒ Object
- #repo ⇒ Object
- #search(*args) ⇒ Object
- #stats ⇒ Object
- #stats_all ⇒ Object
- #uninstall(*args) ⇒ Object
- #uninstall_all ⇒ Object
- #update_all_databases ⇒ Object
- #update_database ⇒ Object
- #version ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
10 11 12 |
# File 'lib/gamerom/cli.rb', line 10 def self.exit_on_failure? true end |
Instance Method Details
#config ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/gamerom/cli.rb', line 15 def config cfg = { ROM_ROOT: Gamerom::ROM_ROOT, CACHE_DIR: Gamerom::CACHE_DIR, GAME_DIR: Gamerom::GAME_DIR, LOG_DIR: Gamerom::LOG_DIR, } pp cfg end |
#info(*args) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gamerom/cli.rb', line 28 def info(*args) game_identifier = args.join(' ') repo = Repo.new([:repo]) validate_platform repo, [:platform] puts "showing info for game #{game_identifier} on #{[:platform]} platform on #{[:repo]} repo..." game = repo.find([:platform], game_identifier) if !game.nil? puts game puts game.filenames if game.installed? else shell.say "Game #{game_identifier} not found", :red end rescue StandardError => e render_error e, exit 1 end |
#install(*args) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/gamerom/cli.rb', line 48 def install(*args) game_identifier = args.join(' ') repo = Repo.new([:repo]) validate_platform repo, [:platform] game = repo.find([:platform], game_identifier) if game.nil? shell.say "Game #{game_identifier} not found", :red return end puts "installing game #{game.id} - #{game.name} - #{game.region} on #{[:platform]} platform on #{[:repo]} repo..." if game.installed? shell.say 'Game already installed', :yellow return end game.install shell.say 'Game installed', :green rescue StandardError => e render_error e, exit 1 end |
#install_all ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/gamerom/cli.rb', line 73 def install_all repo = Repo.new([:repo]) validate_platform repo, [:platform] games = repo.games [:platform], region: [:region] games.each do |game| install(game.id) unless game.installed? end rescue StandardError => e render_error e, exit 1 end |
#list ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/gamerom/cli.rb', line 89 def list repo = Repo.new([:repo]) validate_platform repo, [:platform] puts "listing available games for #{[:platform]} platform on #{[:repo]} repo..." games = repo.games [:platform], region: [:region] print_game_table(games) rescue StandardError => e render_error e, exit 1 end |
#platforms ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/gamerom/cli.rb', line 102 def platforms puts "listing available platforms for #{[:repo]} repo..." platforms = { platforms: Repo.new([:repo]).platforms } puts platforms.to_yaml rescue StandardError => e render_error e, exit 1 end |
#recover ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/gamerom/cli.rb', line 114 def recover repo = Repo.new([:repo]) validate_platform repo, [:platform] puts "recovering state of roms for #{[:platform]} platform on #{[:repo]} repo..." games = repo.games [:platform] games_not_found = [] games.each do |game| filename = nil basename = "#{Gamerom::GAME_DIR}/#{repo.name}/#{[:platform]}/#{game[:region]}/#{game[:name]}" %w[zip 7z rar].each do |ext| fullname = "#{basename}.#{ext}" filename = fullname if File.exist? fullname end if filename game.update_state File.basename(filename) puts "Found game #{game[:name]}" else games_not_found << game[:name] end end if games_not_found.count.positive? puts 'Games not found:' puts games_not_found end rescue StandardError => e puts e. exit 1 end |
#regions ⇒ Object
147 148 149 150 151 152 153 154 155 |
# File 'lib/gamerom/cli.rb', line 147 def regions repo = Repo.new([:repo]) validate_platform repo, [:platform] puts "listing available regions for #{[:platform]} platform on #{[:repo]} repo..." puts repo.regions [:platform] rescue StandardError => e render_error e, exit 1 end |
#repo ⇒ Object
158 159 160 161 162 163 164 |
# File 'lib/gamerom/cli.rb', line 158 def repo puts 'listing available repo...' puts Repo.list rescue StandardError => e render_error e, exit 1 end |
#search(*args) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/gamerom/cli.rb', line 171 def search(*args) keyword = args.join(' ') repo = Repo.new([:repo]) validate_platform repo, [:platform] puts "searching available games for #{[:platform]} platform on #{[:repo]} repo..." games = repo.games [:platform], region: [:region], keyword: keyword if [:install] games.each do |game| install(game.id) unless game.installed? end else print_game_table(games) end rescue StandardError => e render_error e, exit 1 end |
#stats ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/gamerom/cli.rb', line 192 def stats repo = Repo.new([:repo]) validate_platform repo, [:platform] puts "stats for #{[:platform]} platform on #{[:repo]} repo..." games = repo.games [:platform] total = games.count installed = games.select(&:installed?).count size = 0 if File.exist? "#{Gamerom::GAME_DIR}/#{repo.name}/#{[:platform]}" size = `du -hs "#{Gamerom::GAME_DIR}/#{repo.name}/#{[:platform]}/"|awk '{ print $1 }'` end puts " All: #{installed}/#{total} - size: #{size}" repo.regions([:platform]).each do |region| games = repo.games([:platform], region: region) total = games.count installed = games.select(&:installed?).count size = 0 if File.exist? "#{Gamerom::GAME_DIR}/#{repo.name}/#{[:platform]}/#{region}" size = `du -hs "#{Gamerom::GAME_DIR}/#{repo.name}/#{[:platform]}/#{region}/"|awk '{ print $1 }'` end puts " #{region}: #{installed}/#{total} - size: #{size}" end puts rescue StandardError => e render_error e, exit 1 end |
#stats_all ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/gamerom/cli.rb', line 222 def stats_all repo = Repo.new([:repo]) repo.platforms.each_key do |platform| a = Gamerom::Cli.new a. = { platform: platform, repo: [:repo] } a.stats end rescue StandardError => e render_error e, exit 1 end |
#uninstall(*args) ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/gamerom/cli.rb', line 237 def uninstall(*args) game_identifier = args.join(' ') repo = Repo.new([:repo]) validate_platform repo, [:platform] game = repo.find([:platform], game_identifier) if game.nil? shell.say "Game #{game_identifier} not found", :red return end puts "uninstalling game #{game.id} - #{game.name} - #{game.region} on #{[:platform]} platform..." unless game.installed? shell.say 'Game is not installed', :yellow return end game.uninstall shell.say 'Game uninstalled', :green rescue StandardError => e render_error e, exit 1 end |
#uninstall_all ⇒ Object
262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/gamerom/cli.rb', line 262 def uninstall_all repo = Repo.new([:repo]) validate_platform repo, [:platform] games = repo.games [:platform], region: [:region] games.each do |game| uninstall(game.id) if game.installed? end rescue StandardError => e render_error e, exit 1 end |
#update_all_databases ⇒ Object
276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/gamerom/cli.rb', line 276 def update_all_databases puts "updating all databases on #{[:repo]} repo..." repo = Repo.new([:repo]) repo.platforms.each_key do |platform| repo = Repo.new([:repo]) repo.update_database platform end shell.say 'All game databases updated', :green rescue StandardError => e render_error e, exit 1 end |
#update_database ⇒ Object
292 293 294 295 296 297 298 299 300 301 |
# File 'lib/gamerom/cli.rb', line 292 def update_database repo = Repo.new([:repo]) validate_platform repo, [:platform] puts "updating #{[:platform]} platform on #{[:repo]} repo..." repo.update_database [:platform] shell.say "Game database updated for platform #{[:platform]} on #{[:repo]} repo", :green rescue StandardError => e render_error e, exit 1 end |