Skip to content

Commit 97a7959

Browse files
committed
Support outputting all of the nodes on the instance
1 parent 3f47d7a commit 97a7959

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

app/Console/Commands/Node/NodeConfigurationCommand.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,20 @@ class NodeConfigurationCommand extends Command
1515

1616
public function handle()
1717
{
18+
$column = ctype_digit((string) $this->argument('node')) ? 'id' : 'uuid';
19+
1820
/** @var \Pterodactyl\Models\Node $node */
19-
$node = Node::query()->findOrFail($this->argument('node'));
21+
$node = Node::query()->where($column, $this->argument('node'))->firstOr(function () {
22+
$this->error('The selected node does not exist.');
23+
24+
exit(1);
25+
});
2026

2127
$format = $this->option('format');
2228
if (!in_array($format, ['yaml', 'yml', 'json'])) {
2329
$this->error('Invalid format specified. Valid options are "yaml" and "json".');
2430

25-
return 1;
31+
exit(1);
2632
}
2733

2834
if ($format === 'json') {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Pterodactyl\Console\Commands\Node;
4+
5+
use Pterodactyl\Models\Node;
6+
use Illuminate\Console\Command;
7+
8+
class NodeListCommand extends Command
9+
{
10+
protected $signature = 'p:node:list {--format=text : The output format: "text" or "json". }';
11+
12+
public function handle()
13+
{
14+
$nodes = Node::query()->with('location')->get()->map(function (Node $node) {
15+
return [
16+
'id' => $node->id,
17+
'uuid' => $node->uuid,
18+
'name' => $node->name,
19+
'location' => $node->location->short,
20+
'host' => $node->getConnectionAddress(),
21+
];
22+
});
23+
24+
if ($this->option('format') === 'json') {
25+
$this->output->write($nodes->toJson(JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
26+
} else {
27+
$this->table(['ID', 'UUID', 'Name', 'Location', 'Host'], $nodes->toArray());
28+
}
29+
30+
$this->output->newLine();
31+
32+
return 0;
33+
}
34+
}

0 commit comments

Comments
 (0)