Skip to content

Commit f64d43a

Browse files
authored
Merge pull request #2 from elgentos/add-update-command
Added Update Brancher command to overwrite/append labels to existing …
2 parents 9cb6578 + c257147 commit f64d43a

4 files changed

Lines changed: 190 additions & 126 deletions

File tree

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,20 @@ Arguments:
6161
Options:
6262
--output[=OUTPUT] Output format (json, default: table)
6363
```
64+
65+
### brancher:update
66+
67+
```
68+
Description:
69+
Update a Brancher node with new labels
70+
71+
Usage:
72+
brancher:update [options] [--] <hypernode>
73+
74+
Arguments:
75+
hypernode
76+
77+
Options:
78+
--append-labels
79+
--label[=LABEL] Add labels to your Brancher node (comma-separated)
80+
```

app/Commands/ListBrancherNodes.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ public function handle()
5555

5656
$tableData = [];
5757
foreach ($branchers as $brancher) {
58-
$brancher['labels'] = array_keys($brancher['labels']);
5958
foreach ($brancher as $key => $value) {
60-
if (is_array($value)) $brancher[$key] = implode(', ', $value);
59+
if (is_array($value)) $brancher[$key] = http_build_query(data: $value, arg_separator: PHP_EOL);
6160
}
6261
$tableData[] = $brancher;
6362
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace App\Commands;
4+
5+
use Hypernode\Api\Exception\HypernodeApiClientException;
6+
use Hypernode\Api\Exception\HypernodeApiServerException;
7+
use Hypernode\Api\HypernodeClientFactory;
8+
use LaravelZero\Framework\Commands\Command;
9+
10+
class UpdateBrancherNode extends Command
11+
{
12+
/**
13+
* The signature of the command.
14+
*
15+
* @var string
16+
*/
17+
protected $signature = 'brancher:update {hypernode} {--append-labels} {--label= : Add labels to your Brancher node (comma-separated)}';
18+
19+
/**
20+
* The description of the command.
21+
*
22+
* @var string
23+
*/
24+
protected $description = 'Update a Brancher node with new labels';
25+
26+
/**
27+
* Execute the console command.
28+
*
29+
* @return mixed
30+
* @throws HypernodeApiClientException
31+
* @throws HypernodeApiServerException
32+
*/
33+
public function handle()
34+
{
35+
$client = HypernodeClientFactory::create(config('hypernode.api_token'));
36+
37+
$originHypernode = $this->argument('hypernode');
38+
39+
$labels = array_filter(array_map('trim', explode(',', $this->option('label'))));
40+
41+
$client->brancherApp->update($originHypernode, ['labels' => $labels], (bool) $this->option('append-labels'));
42+
43+
$this->line('Brancher node update for ' . $originHypernode . ' requested');
44+
}
45+
}

0 commit comments

Comments
 (0)