Skip to content

Commit

Permalink
feat: added helper commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaile committed Jul 19, 2024
1 parent 632d2df commit d719798
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
39 changes: 39 additions & 0 deletions app/Console/Commands/ListRepositoryFiles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Console\Commands;

use App\Models\Repository;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;

class ListRepositoryFiles extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'repository:list-files {repository} {path?}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'List files in the repository, additional path can be provided to list files in a specific directory instead of the current served directory.';

/**
* Execute the console command.
*/
public function handle(): void
{
$repository = Repository::where('name', $this->argument('repository'))->firstOrFail();
$path = $this->argument('path');
if (is_null($path)) {
$path = $repository->getStablePath();
}
foreach (Storage::files($path, true) as $file) {
$this->info($file);
}
}
}
39 changes: 39 additions & 0 deletions app/Console/Commands/RepositorySnapshots.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Console\Commands;

use App\Models\Repository;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;

class RepositorySnapshots extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'repository:snapshots {repository}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Lists the snapshots for a repository.';

/**
* Execute the console command.
*/
public function handle(): void
{
$repository = Repository::where('name', $this->argument('repository'))->firstOrFail();
$snapshots = collect(Storage::directories($repository->snapshotDir()))->map(function ($snapshot) use ($repository) {
return [
'Snapshot' => basename($snapshot),
'Active' => $snapshot === $repository->getStablePath() ? 'Yes' : 'No',
];
});
$this->table(['Snapshot', 'Active'], $snapshots);
}
}

0 comments on commit d719798

Please sign in to comment.