Skip to content

Commit e4c8d24

Browse files
committed
bunch more
1 parent 619a336 commit e4c8d24

7 files changed

Lines changed: 396 additions & 31 deletions

File tree

src/Commands/DeleteCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
use function Laravel\Prompts\confirm;
66
use function Laravel\Prompts\table;
77

8-
class DeleteCommand extends AbstractCommand
8+
class DeleteCommand extends BaseCommand
99
{
10-
public $signature = 'keep:delete {--force : Skip confirmation prompt} '
10+
public $signature = 'delete {--force : Skip confirmation prompt} '
1111
.self::KEY_SIGNATURE
1212
.self::CONTEXT_SIGNATURE
1313
.self::VAULT_SIGNATURE

src/Commands/DiffCommand.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,25 @@ public function process()
3232
}
3333

3434
if (empty($vaults)) {
35-
return $this->error('No vaults available for comparison.');
35+
$this->error('No vaults available for comparison.');
36+
return self::FAILURE;
3637
}
3738

3839
if (empty($stages)) {
39-
return $this->error('No stages available for comparison.');
40+
$this->error('No stages available for comparison.');
41+
return self::FAILURE;
4042
}
4143

4244
$diffService = new DiffService;
4345
$diffs = spin(fn () => $diffService->compare($vaults, $stages), 'Gathering secrets for comparison...');
4446

45-
return $diffs->isNotEmpty()
46-
? $this->displayTable($diffs, $vaults, $stages, $diffService)
47-
: $this->info('No secrets found in any of the specified vault/stage combinations.');
47+
if ($diffs->isNotEmpty()) {
48+
$this->displayTable($diffs, $vaults, $stages, $diffService);
49+
return self::SUCCESS;
50+
} else {
51+
$this->info('No secrets found in any of the specified vault/stage combinations.');
52+
return self::SUCCESS;
53+
}
4854
}
4955

5056
protected function getVaultsToCompare(): array
@@ -87,14 +93,14 @@ protected function getStagesToCompare(): array
8793
return Keep::getStages();
8894
}
8995

90-
protected function displayTable(Collection $diffs, array $vaults, array $stages, DiffService $diffService): bool
96+
protected function displayTable(Collection $diffs, array $vaults, array $stages, DiffService $diffService): void
9197
{
9298
$this->newLine();
9399
$this->info('Secret Comparison Matrix');
94100

95101
// Build column headers
96102
$headers = ['Key'];
97-
$vaultEnvCombinations = [];
103+
$vaultStageCombinations = [];
98104

99105
foreach ($vaults as $vault) {
100106
foreach ($stages as $stage) {
@@ -124,8 +130,6 @@ protected function displayTable(Collection $diffs, array $vaults, array $stages,
124130
table($headers, $rows);
125131

126132
$this->displaySummary($diffs, $vaults, $stages, $diffService);
127-
128-
return true;
129133
}
130134

131135
protected function displaySummary(Collection $diffs, array $vaults, array $stages, DiffService $diffService): void

src/Commands/ExportCommand.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
use STS\Keep\Data\Collections\SecretCollection;
66

7-
class ExportCommand extends AbstractCommand
7+
class ExportCommand extends BaseCommand
88
{
9-
public $signature = 'keep:export
9+
public $signature = 'export
1010
{--format=env : json|env}
1111
{--output= : File where to save the output (defaults to stdout)}
1212
{--overwrite : Overwrite the output file if it exists}
@@ -17,7 +17,7 @@ class ExportCommand extends AbstractCommand
1717

1818
public $description = 'Export all stage secrets in a specified vault';
1919

20-
public function process(): int
20+
public function process()
2121
{
2222
$context = $this->context();
2323
$secrets = $context->createVault()->list();
@@ -32,8 +32,6 @@ public function process(): int
3232
}
3333

3434
$this->line($this->formatOutput($secrets));
35-
36-
return self::SUCCESS;
3735
}
3836

3937
protected function formatOutput(SecretCollection $secrets): string

src/Commands/HistoryCommand.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
use function Laravel\Prompts\table;
1212

13-
class HistoryCommand extends AbstractCommand
13+
class HistoryCommand extends BaseCommand
1414
{
15-
public $signature = 'keep:history
15+
public $signature = 'history
1616
{--limit=10 : Maximum number of history entries to return}
1717
{--format=table : table|json}
1818
{--user= : Filter by user who modified the secret (partial match)}
@@ -26,7 +26,7 @@ class HistoryCommand extends AbstractCommand
2626

2727
public $description = 'Display change history for a secret';
2828

29-
public function process(): int
29+
public function process()
3030
{
3131
$key = $this->key();
3232
$limit = (int) $this->option('limit');
@@ -66,22 +66,18 @@ public function process(): int
6666

6767
return self::FAILURE;
6868
}
69-
70-
return self::SUCCESS;
7169
}
7270

7371
protected function displayTable(SecretHistoryCollection $historyCollection, string $key): bool
7472
{
75-
$timezone = config('keep.display_timezone', config('app.timezone', 'UTC'));
76-
7773
$this->line("History for secret: <info>{$key}</info>");
7874

79-
$rows = $historyCollection->map(function (SecretHistory $history) use ($timezone, $historyCollection) {
75+
$rows = $historyCollection->map(function (SecretHistory $history) use ($historyCollection) {
8076
return [
8177
'Version' => $history->version(),
8278
'Value' => $history->value() ?? '<null>',
8379
'Type' => $history->dataType(),
84-
'Modified Date' => $history->formattedDate($timezone),
80+
'Modified Date' => $history->formattedDate(),
8581
'Modified By' => $history->lastModifiedUser() ?? '<unknown>',
8682
];
8783
})->toArray();

src/Data/SecretHistory.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,12 @@ public function isSecure(): bool
8686
return $this->secure;
8787
}
8888

89-
public function formattedDate(?string $timezone = null): ?string
89+
public function formattedDate(): ?string
9090
{
9191
if (! $this->lastModifiedDate) {
9292
return null;
9393
}
9494

95-
if ($timezone) {
96-
return $this->lastModifiedDate->setTimezone($timezone)->format('Y-m-d H:i:s T');
97-
}
98-
9995
return $this->lastModifiedDate->format('Y-m-d H:i:s T');
10096
}
10197

src/KeepApplication.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ public function __construct(protected KeepInstall $install)
4444

4545
$this->add((new Commands\GetCommand()));
4646
$this->add((new Commands\SetCommand()));
47-
$this->add((new Commands\ListCommand()));
4847
$this->add((new Commands\CopyCommand()));
48+
$this->add((new Commands\DeleteCommand()));
49+
$this->add((new Commands\HistoryCommand()));
50+
51+
$this->add((new Commands\ListCommand()));
52+
$this->add((new Commands\ExportCommand()));
4953

5054
$this->add((new Commands\DiffCommand()));
5155

0 commit comments

Comments
 (0)