Skip to content

Commit 29e018d

Browse files
committed
commit
1 parent 4c8df47 commit 29e018d

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

app/site/commands/App/Shell.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313

1414
namespace App\Site\Commands\App;
1515

16+
use App\App;
1617
use App\Base\Abstracts\Commands\BaseCommand;
1718
use DI\DependencyException;
1819
use DI\NotFoundException;
1920
use Symfony\Component\Console\Input\InputInterface;
2021
use Symfony\Component\Console\Output\OutputInterface;
21-
use Exception;
22+
use Throwable;
2223
use Symfony\Component\Console\Command\Command;
2324

2425
/**
@@ -47,6 +48,8 @@ protected function execute(InputInterface $input, OutputInterface $output) : int
4748
{
4849
$this->getIo()->title('Welcome.');
4950

51+
$app = App::getInstance();
52+
5053
$history = [];
5154
do {
5255
$command = rtrim(trim($this->keepAsking("\n> ")), ';');
@@ -59,11 +62,14 @@ protected function execute(InputInterface $input, OutputInterface $output) : int
5962
case 'exit':
6063
$command = 'exit';
6164
break;
65+
case 'help':
66+
$this->renderHelp();
67+
break;
6268
default:
6369
try {
6470
eval($command . ';');
6571
$history[] = $command;
66-
} catch (Exception $e) {
72+
} catch (Throwable $e) {
6773
$output->writeln($e->getMessage());
6874
}
6975
break;
@@ -73,4 +79,24 @@ protected function execute(InputInterface $input, OutputInterface $output) : int
7379

7480
return Command::SUCCESS;
7581
}
82+
83+
protected function renderHelp()
84+
{
85+
$this->getIo()->writeln(
86+
" ===============================================\n" .
87+
" PHP Interactive Shell\n" .
88+
" ===============================================\n\n" .
89+
" Welcome to the Interactive Shell.\n\n" .
90+
" - You can execute any valid PHP code directly.\n" .
91+
" - Use 'history' to view the list of previously executed commands.\n" .
92+
" - Use 'quit' or 'exit' to leave the shell.\n" .
93+
" - Use 'help' to display this message again.\n\n" .
94+
" Current Variables:\n" .
95+
" - \$this: The current command instance.\n" .
96+
" - \$output: The output interface for writing messages.\n" .
97+
" - \$input: The input interface for reading user input.\n" .
98+
" - \$app: An application reference.\n" .
99+
" ==============================================="
100+
);
101+
}
76102
}

app/site/commands/Db/Shell.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use PDO;
1818
use Symfony\Component\Console\Input\InputInterface;
1919
use Symfony\Component\Console\Output\OutputInterface;
20-
use Exception;
20+
use Throwable;
2121
use Symfony\Component\Console\Command\Command;
2222

2323
/**
@@ -64,6 +64,9 @@ protected function execute(InputInterface $input, OutputInterface $output) : int
6464
case 'exit':
6565
$command = 'exit';
6666
break;
67+
case 'help':
68+
$this->renderHelp();
69+
break;
6770
default:
6871
try {
6972
$statement = $this->getDb()->query($command);
@@ -99,7 +102,7 @@ protected function execute(InputInterface $input, OutputInterface $output) : int
99102
}
100103

101104
$history[] = $command;
102-
} catch (Exception $e) {
105+
} catch (Throwable $e) {
103106
$this->getIo()->error($e->getMessage());
104107
}
105108
break;
@@ -109,4 +112,22 @@ protected function execute(InputInterface $input, OutputInterface $output) : int
109112

110113
return Command::SUCCESS;
111114
}
115+
116+
protected function renderHelp()
117+
{
118+
$this->getIo()->writeln(
119+
" ===============================================\n" .
120+
" DB Interactive Shell\n" .
121+
" ===============================================\n\n" .
122+
" Welcome to the Database Interactive Shell.\n\n" .
123+
" - You can execute any valid SQL queries directly.\n" .
124+
" - Use 'history' to view the list of previously executed queries.\n" .
125+
" - Use 'quit' or 'exit' to leave the shell.\n" .
126+
" - Use 'help' to display this message again.\n\n" .
127+
" Supported Queries:\n" .
128+
" - SELECT, SHOW: Results will be displayed in a table.\n" .
129+
" - INSERT, UPDATE, DELETE, etc.: The number of affected rows will be shown.\n" .
130+
" ==============================================="
131+
);
132+
}
112133
}

0 commit comments

Comments
 (0)