Skip to content

Commit

Permalink
feat(framework): overhaul console interactions (#754)
Browse files Browse the repository at this point in the history
  • Loading branch information
aidan-casey committed Dec 3, 2024
1 parent 4b97431 commit 513eef8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Commands/DiscoveryClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(

#[ConsoleCommand(
name: 'discovery:clear',
description: 'Clear all cached discovery files',
description: 'Clears all cached discovery files',
aliases: ['dc'],
)]
public function __invoke(): void
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/DiscoveryGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public function generateDiscoveryCache(DiscoveryCacheStrategy $strategy): void
$count += $discoveryItems->count();
}

$this->writeln(sprintf(
'<success>Done</success> %d items cached',
$this->success(sprintf(
'Cached <em>%d</em> items',
$count,
));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/DiscoveryStatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(

#[ConsoleCommand(
name: 'discovery:status',
description: 'List all discovery locations and discovery classes',
description: 'Lists all discovery locations and discovery classes',
aliases: ['ds'],
)]
public function __invoke(): void
Expand Down
12 changes: 6 additions & 6 deletions src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
) {
}

#[ConsoleCommand(name: 'install', middleware: [ForceMiddleware::class])]
#[ConsoleCommand(name: 'install', description: 'Applies the specified installer', middleware: [ForceMiddleware::class])]
public function __invoke(?string $installer = null): void
{
$installer = $this->resolveInstaller($installer);
Expand All @@ -35,15 +35,15 @@ public function __invoke(?string $installer = null): void
return;
}

if (! $this->confirm("Running the `{$installer->getName()}` installer, continue?")) {
$this->error('Aborted');
if (! $this->confirm("Running the <em>{$installer->getName()}</em> installer, continue?")) {
$this->error('Aborted.');

return;
}

$installer->install();

$this->success('Done');
$this->success('Done.');
}

private function resolveInstaller(?string $search): ?Installer
Expand All @@ -55,10 +55,10 @@ private function resolveInstaller(?string $search): ?Installer
if (! $search) {
$search = $this->ask(
question: 'Please choose an installer',
options: $installers->map(fn (Installer $installer) => $installer->getName())->toArray(),
options: $installers->mapWithKeys(fn (Installer $installer) => yield $installer::class => $installer->getName())->toArray(),
);
}

return $installers->first(fn (Installer $installer) => $installer->getName() === $search);
return $installers->first(fn (Installer $installer) => $installer::class === $search || $installer->getName() === $search);
}
}
11 changes: 8 additions & 3 deletions src/PublishesFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Tempest\Core;

use Closure;
use Tempest\Console\Exceptions\ConsoleException;
use Tempest\Console\HasConsole;
use Tempest\Container\Inject;
use Tempest\Generation\ClassManipulator;
Expand Down Expand Up @@ -50,7 +51,7 @@ public function publish(
): void {
try {
if (! $this->console->confirm(
question: sprintf('Do you want to create "%s"', $destination),
question: sprintf('Do you want to create <em>%s</em>?', $destination),
default: true,
)) {
throw new FileGenerationAbortedException('Skipped.');
Expand Down Expand Up @@ -95,10 +96,14 @@ public function publish(
$callback($source, $destination);
}

$this->console->success(sprintf('File successfully created at "%s".', $destination));
$this->console->success(sprintf('File successfully created at <em>%s</em>".', $destination));
} catch (FileGenerationAbortedException $exception) {
$this->console->info($exception->getMessage());
} catch (Throwable $throwable) {
if ($throwable instanceof ConsoleException) {
throw $throwable;
}

throw new FileGenerationFailedException(
message: 'The file could not be published.',
previous: $throwable,
Expand Down Expand Up @@ -180,7 +185,7 @@ public function askForOverride(string $targetPath): bool
}

return $this->console->confirm(
question: sprintf('The file "%s" already exists. Do you want to override it?', $targetPath),
question: sprintf('The file <em>%s</em> already exists. Do you want to override it?', $targetPath),
);
}
}

0 comments on commit 513eef8

Please sign in to comment.