Skip to content

Commit 3c30587

Browse files
committed
Improve error message when keep run is called without a command
- Override run() method to catch missing command argument exception - Provide helpful usage message with examples - Replace unhelpful Symfony exception with clear user guidance
1 parent b37b82f commit 3c30587

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

src/Commands/RunCommand.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
use function Laravel\Prompts\info;
1717
use function Laravel\Prompts\note;
1818

19+
use Symfony\Component\Console\Input\InputInterface;
20+
use Symfony\Component\Console\Output\OutputInterface;
21+
use Illuminate\Console\OutputStyle;
22+
1923
class RunCommand extends BaseCommand
2024
{
2125
use GathersInput, ResolvesTemplates;
@@ -42,17 +46,31 @@ public function __construct(Filesystem $filesystem)
4246
$this->processRunner = new ProcessRunner();
4347
}
4448

49+
/**
50+
* Override run to provide better error message for missing command
51+
*/
52+
public function run(InputInterface $input, OutputInterface $output): int
53+
{
54+
try {
55+
return parent::run($input, $output);
56+
} catch (\Symfony\Component\Console\Exception\RuntimeException $e) {
57+
if (str_contains($e->getMessage(), 'Not enough arguments (missing: "cmd")')) {
58+
$this->output = new OutputStyle($input, $output);
59+
error('No command specified to run');
60+
note('Usage: keep run [options] -- <command> [arguments]');
61+
note('Example: keep run --vault=ssm --stage=production -- npm start');
62+
note('Example: keep run --vault=ssm --stage=production -- php artisan serve');
63+
return self::FAILURE;
64+
}
65+
throw $e;
66+
}
67+
}
68+
4569
protected function process(): int
4670
{
4771
// Get command and arguments
4872
$commandArgs = $this->argument('cmd');
4973

50-
if (empty($commandArgs)) {
51-
error('No command specified');
52-
note('Usage: keep run [options] -- <command> [arguments]');
53-
return self::FAILURE;
54-
}
55-
5674
// Validate command exists
5775
$command = $commandArgs[0];
5876
if (!$this->processRunner->commandExists($command) && !file_exists($command)) {

0 commit comments

Comments
 (0)