Files
pterodactyl-panel/app/Console/Commands/Node/NodeConfigurationCommand.php
T

48 lines
1.4 KiB
PHP
Raw Normal View History

<?php
2026-10-05 18:10:18 -04:00
declare(strict_types=1);
namespace Pterodactyl\Console\Commands\Node;
2026-10-05 18:10:18 -04:00
use Illuminate\Console\Attributes\Description;
use Illuminate\Console\Attributes\Signature;
use Illuminate\Console\Command;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Models\Node;
2026-10-05 18:10:18 -04:00
#[Description('Displays the configuration for the specified node.')]
#[Signature('p:node:configuration
{node : The ID or UUID of the node to return the configuration for.}
{--format=yaml : The output format. Options are "yaml" and "json".}')]
class NodeConfigurationCommand extends Command
{
2022-10-14 10:59:20 -06:00
public function handle(): int
{
2026-10-05 18:10:18 -04:00
$argument = $this->argument('node');
$column = ctype_digit($argument) ? 'id' : 'uuid';
2026-10-05 18:10:18 -04:00
$node = Node::query()->where($column, $argument)->first();
if ($node === null) {
$this->error('The selected node does not exist.');
2026-10-05 18:10:18 -04:00
return 1;
}
$format = $this->option('format');
2026-10-05 18:10:18 -04:00
if (! in_array($format, ['yaml', 'yml', 'json'])) {
$this->error('Invalid format specified. Valid options are "yaml" and "json".');
2022-10-14 10:59:20 -06:00
return 1;
}
if ($format === 'json') {
$this->output->write($node->getJsonConfiguration(true));
} else {
$this->output->write($node->getYamlConfiguration());
}
$this->output->newLine();
return 0;
}
}