Skip to content

Commit 5cae1bd

Browse files
committed
cast --only option to ServerGroup, fix name resolution
1 parent 8c39b10 commit 5cae1bd

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/Commands/CommandCommand.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Codinglabs\Yolo\Commands;
44

55
use Codinglabs\Yolo\Paths;
6+
use Codinglabs\Yolo\Helpers;
67
use Codinglabs\Yolo\Manifest;
78
use Codinglabs\Yolo\Concerns\UsesEc2;
89
use Codinglabs\Yolo\Enums\ServerGroup;
@@ -41,17 +42,17 @@ public function handle(): void
4142
return;
4243
}
4344

44-
$groups = str_contains($this->option('group'), ',')
45+
$serverGroups = str_contains($this->option('group'), ',')
4546
? explode(',', $this->option('group'))
4647
: [$this->option('group')];
4748

48-
foreach ($groups as $group) {
49-
$instances = $this->findSshPrefixesForGroup($group);
49+
foreach ($serverGroups as $serverGroup) {
50+
$instances = $this->findSshPrefixesForGroup(ServerGroup::from($serverGroup));
5051

51-
info("Found " . count($instances) . " instances in group $group on {$this->argument('environment')}");
52+
info("Found " . count($instances) . " instances in group $serverGroup on {$this->argument('environment')}");
5253

5354
foreach ($instances as $ipAddress => $sshCommand) {
54-
warning("Executing command '$command' in group $group on instance $ipAddress on {$this->argument('environment')}...");
55+
warning("Executing command '$command' in group $serverGroup on instance $ipAddress on {$this->argument('environment')}...");
5556

5657
$process = new Process(
5758
command: [
@@ -70,11 +71,11 @@ public function handle(): void
7071
}
7172
}
7273

73-
protected function findSshPrefixesForGroup(string $group): array
74+
protected function findSshPrefixesForGroup(ServerGroup $serverGroup): array
7475
{
7576
$prefixes = [];
7677

77-
foreach (static::ec2IpByName(name: $group, firstOnly: false) as $ipAddress) {
78+
foreach (static::ec2IpByName(name: Helpers::keyedResourceName($serverGroup, exclusive: false), firstOnly: false) as $ipAddress) {
7879
$prefixes[$ipAddress] = static::formatSshCommand(
7980
ipAddress: $ipAddress,
8081
sshKey: $this->option('ssh-key')

0 commit comments

Comments
 (0)