Support outputting all of the nodes on the instance
This commit is contained in:
parent
3f47d7a12c
commit
97a7959096
2 changed files with 42 additions and 2 deletions
|
@ -15,14 +15,20 @@ class NodeConfigurationCommand extends Command
|
||||||
|
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
$column = ctype_digit((string) $this->argument('node')) ? 'id' : 'uuid';
|
||||||
|
|
||||||
/** @var \Pterodactyl\Models\Node $node */
|
/** @var \Pterodactyl\Models\Node $node */
|
||||||
$node = Node::query()->findOrFail($this->argument('node'));
|
$node = Node::query()->where($column, $this->argument('node'))->firstOr(function () {
|
||||||
|
$this->error('The selected node does not exist.');
|
||||||
|
|
||||||
|
exit(1);
|
||||||
|
});
|
||||||
|
|
||||||
$format = $this->option('format');
|
$format = $this->option('format');
|
||||||
if (!in_array($format, ['yaml', 'yml', 'json'])) {
|
if (!in_array($format, ['yaml', 'yml', 'json'])) {
|
||||||
$this->error('Invalid format specified. Valid options are "yaml" and "json".');
|
$this->error('Invalid format specified. Valid options are "yaml" and "json".');
|
||||||
|
|
||||||
return 1;
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($format === 'json') {
|
if ($format === 'json') {
|
||||||
|
|
34
app/Console/Commands/Node/NodeListCommand.php
Normal file
34
app/Console/Commands/Node/NodeListCommand.php
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pterodactyl\Console\Commands\Node;
|
||||||
|
|
||||||
|
use Pterodactyl\Models\Node;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class NodeListCommand extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'p:node:list {--format=text : The output format: "text" or "json". }';
|
||||||
|
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$nodes = Node::query()->with('location')->get()->map(function (Node $node) {
|
||||||
|
return [
|
||||||
|
'id' => $node->id,
|
||||||
|
'uuid' => $node->uuid,
|
||||||
|
'name' => $node->name,
|
||||||
|
'location' => $node->location->short,
|
||||||
|
'host' => $node->getConnectionAddress(),
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
if ($this->option('format') === 'json') {
|
||||||
|
$this->output->write($nodes->toJson(JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||||
|
} else {
|
||||||
|
$this->table(['ID', 'UUID', 'Name', 'Location', 'Host'], $nodes->toArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->output->newLine();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue