Skip to content

Commit 6417c82

Browse files
author
Andreas Frömer
committed
Add possibility for unit prefix filter
1 parent ac2bb45 commit 6417c82

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/SystemCtl.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,20 @@ public static function unitFromSuffix(string $unitSuffix, string $unitName): Uni
6161
/**
6262
* List all supported units
6363
*
64+
* @param null|string $unitPrefix
6465
* @param string[] $unitTypes
6566
* @return array|\string[]
6667
*/
67-
public function listUnits(array $unitTypes = self::SUPPORTED_UNITS): array
68+
public function listUnits(?string $unitPrefix = null, array $unitTypes = self::SUPPORTED_UNITS): array
6869
{
69-
$process = $this->getProcessBuilder()
70-
->add('list-units')
71-
->getProcess();
70+
$processBuilder = $this->getProcessBuilder()
71+
->add('list-units');
72+
73+
if ($unitPrefix) {
74+
$processBuilder->add($unitPrefix . '*');
75+
}
76+
77+
$process = $processBuilder->getProcess();
7278

7379
$process->run();
7480
$output = $process->getOutput();
@@ -89,11 +95,12 @@ public function getService(string $name): Service
8995
}
9096

9197
/**
92-
* @return Service[]
98+
* @param null|string $unitPrefix
99+
* @return array|Service[]
93100
*/
94-
public function getServices(): array
101+
public function getServices(?string $unitPrefix = null): array
95102
{
96-
$units = $this->listUnits(['service']);
103+
$units = $this->listUnits($unitPrefix, ['service']);
97104

98105
return array_map(function ($unitName) {
99106
return new Service($unitName, $this->getProcessBuilder());
@@ -110,11 +117,12 @@ public function getTimer(string $name): Timer
110117
}
111118

112119
/**
113-
* @return Timer[]
120+
* @param null|string $unitPrefix
121+
* @return array|Timer[]
114122
*/
115-
public function getTimers(): array
123+
public function getTimers(?string $unitPrefix = null): array
116124
{
117-
$units = $this->listUnits(['timer']);
125+
$units = $this->listUnits($unitPrefix, ['timer']);
118126

119127
return array_map(function ($unitName) {
120128
return new Timer($unitName, $this->getProcessBuilder());

0 commit comments

Comments
 (0)