Changing app queue platforms from an argument list to --options

This commit is contained in:
ilumos 2017-09-07 21:46:19 +01:00
parent 964712ada7
commit eb8e32337d
2 changed files with 36 additions and 36 deletions

View file

@ -72,12 +72,11 @@ Automatically fill a [lancache](https://github.com/zeropingheroes/lancache) with
* Authorise a Steam account to allow download of apps in their library.
* If no account is specified, the `DEFAULT_STEAM_USER` account is used
`steam:queue-app appid [platform(s)] [--account=account]`
`steam:queue-app appid [--windows] [--osx] [--linux]`
* Queue a Steam app for downloading.
* Optionally the platform(s) to download can be specified as a comma-separated list
* Available platforms are: windows, osx, linux
* If no platform is specified, the Windows version of the app will be queued
* Optionally the platform(s) to download can be specified as options
* If no platform option is specified, the Windows version of the app will be queued
`steam:dequeue [--app_id=] [--platform=] [--account=] [--status=]`

View file

@ -3,7 +3,9 @@
namespace Zeropingheroes\LancacheAutofill\Commands\Steam;
use Illuminate\Console\Command;
use Illuminate\Database\Capsule\Manager as Capsule;
use Zeropingheroes\LancacheAutofill\Models\{
SteamApp, SteamQueueItem
};
class QueueApp extends Command
{
@ -14,7 +16,9 @@ class QueueApp extends Command
*/
protected $signature = 'steam:queue-app
{app_id : The ID of the app}
{platforms=windows : Comma separated list of platforms to download the app for [windows, osx, linux]}';
{--windows=true : Queue the Windows version of the app}
{--osx : Queue the OS X version of the app}
{--linux : Queue the Linux version of the app}';
/**
* The console command description.
@ -23,13 +27,6 @@ class QueueApp extends Command
*/
protected $description = 'Queue a Steam app for downloading';
/**
* The permissible platforms.
*
* @var array
*/
const PLATFORMS = ['windows', 'osx', 'linux'];
/**
* Execute the console command.
*
@ -37,43 +34,47 @@ class QueueApp extends Command
*/
public function handle()
{
// If no platforms are specified, default to windows
$platforms = explode(',', $this->argument('platforms')) ?? ['windows'];
$appId = $this->argument('app_id');
if (array_diff($platforms, $this::PLATFORMS)) {
$this->error('Invalid platform(s) specified. Available platforms are: '.implode(' ', $this::PLATFORMS));
die();
}
// Check if app with specified ID exists
$app = Capsule::table('steam_apps')
->where('id', $this->argument('app_id'))
->first();
if (!$app) {
if (!$app = SteamApp::find($appId)) {
$this->error('Steam app with ID '.$this->argument('app_id').' not found');
die();
}
// Add platforms depending on options
if ($this->option('windows')) {
$platforms[] = 'windows';
}
if ($this->option('osx')) {
$platforms[] = 'osx';
}
if ($this->option('linux')) {
$platforms[] = 'linux';
}
// Queue each platform separately
foreach ($platforms as $platform) {
$alreadyQueued = Capsule::table('steam_queue')
->where('app_id', $app->id)
$alreadyQueued = SteamQueueItem::where('app_id', $app->id)
->where('platform', $platform)
->count();
->first();
if ($alreadyQueued) {
$this->error('Steam app "'.$app->name.'" on platform "'.$platform.'" already in download queue');
$this->error('Steam app "'.$app->name.'" on platform "'.ucfirst($platform).'" already in download queue');
continue;
}
// Add the app to the download queue, specifying the platform and account
Capsule::table('steam_queue')->insert([
'app_id' => $app->id,
'platform' => $platform,
'status' => 'queued',
]);
$steamQueueItem = new SteamQueueItem;
$steamQueueItem->app_id = $app->id;
$steamQueueItem->platform = $platform;
$steamQueueItem->status = 'queued';
$this->info('Added Steam app "'.$app->name.'" on platform "'.$platform.'" to download queue');
if ($steamQueueItem->save()) {
$this->info('Added Steam app "'.$app->name.'" on platform "'.ucfirst($platform).'" to download queue');
}
}