From 97a79590962202be740eec2e90b2dbd1f26786b3 Mon Sep 17 00:00:00 2001 From: DaneEveritt Date: Fri, 13 May 2022 21:49:06 -0400 Subject: [PATCH] Support outputting all of the nodes on the instance --- .../Node/NodeConfigurationCommand.php | 10 ++++-- app/Console/Commands/Node/NodeListCommand.php | 34 +++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 app/Console/Commands/Node/NodeListCommand.php diff --git a/app/Console/Commands/Node/NodeConfigurationCommand.php b/app/Console/Commands/Node/NodeConfigurationCommand.php index 7cb31ba9a..fdd06417b 100644 --- a/app/Console/Commands/Node/NodeConfigurationCommand.php +++ b/app/Console/Commands/Node/NodeConfigurationCommand.php @@ -15,14 +15,20 @@ class NodeConfigurationCommand extends Command public function handle() { + $column = ctype_digit((string) $this->argument('node')) ? 'id' : 'uuid'; + /** @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'); if (!in_array($format, ['yaml', 'yml', 'json'])) { $this->error('Invalid format specified. Valid options are "yaml" and "json".'); - return 1; + exit(1); } if ($format === 'json') { diff --git a/app/Console/Commands/Node/NodeListCommand.php b/app/Console/Commands/Node/NodeListCommand.php new file mode 100644 index 000000000..01ed4fde4 --- /dev/null +++ b/app/Console/Commands/Node/NodeListCommand.php @@ -0,0 +1,34 @@ +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; + } +}