Skip to content

Commit 20fe5c8

Browse files
update
1 parent 4f64647 commit 20fe5c8

File tree

8 files changed

+104
-63
lines changed

8 files changed

+104
-63
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
APP_NAME="ORM Database"
22
APP_ENV=local
3-
APP_KEY=base64:gLf20f1FOUlfG/l5-BccCrdZBXy6iEsVZA7nEBtS84zU=
3+
APP_KEY=base64:EA9NZ93VJdzIBfTCd1eKHBMFt+lRWaJlAiD0k8w52zs=
44
APP_DEBUG=true
55
SITE_EMAIL=
66

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ require_once __DIR__ . '/vendor/autoload.php';
190190
| By default you don't need to define any path again |
191191
| |
192192
| Files you'll see after you reload browser: |
193-
| `.env` `.env.example` `.gitignore` `.htaccess` `.user.ini` `init.php` `tame[bash]` |
193+
| `.env` `.env.example` `.gitignore` `.htaccess` `.user.ini` `init.php` |
194194

195195
```php
196196
use Tamedevelopers\Database\AutoLoader;

README2.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

console.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Tamedevelopers Database CLI
2+
3+
## Quick start
4+
5+
1. Install dependencies
6+
```bash
7+
composer install
8+
```
9+
10+
2. List commands
11+
```bash
12+
php database list
13+
# or via composer bin (after composer install)
14+
./vendor/bin/database list
15+
```
16+
17+
3. Scaffold example table
18+
```bash
19+
php database scaffold --name=posts
20+
```
21+
22+
## Adding new commands
23+
- Register your provider in `composer.json`:
24+
25+
```json
26+
"extra": {
27+
"tamedevelopers": {
28+
"providers": [
29+
"Vendor\\Package\\Kernal"
30+
]
31+
}
32+
},
33+
```
34+
35+
- Create a new class anywhere inside directory `app/Console`, e.g. `Kernal.php`
36+
```php
37+
38+
namespace Vendor\Package;
39+
40+
use App\Console\Commands\MakeModelCommand;
41+
use Tamedevelopers\Support\Capsule\CommandProviderInterface;
42+
43+
class KernalCommand implements CommandProviderInterface
44+
{
45+
/** @inheritDoc */
46+
public function register(Artisan $artisan) :void
47+
{
48+
$this->register(
49+
'make:model',
50+
[new MakeModelCommand(), 'handle'],
51+
'Database model generator'
52+
);
53+
}
54+
}
55+
```
56+
57+
## Notes
58+
- Commands run in CLI, no manual browser reload needed.
59+
- Env and logger are booted automatically in the sample command.

src/Console/Commands/DBCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ public function wipe()
159159

160160
// ask once
161161
if (!$confirm) {
162-
$this->warning("Command aborted.\n");
163-
return 0;
162+
$this->warning("Command aborted.");
163+
return;
164164
}
165165
}
166166

src/Console/Commands/KeyCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ class KeyCommand extends CommandHelper
1717
*/
1818
public function handle()
1919
{
20-
echo "Usage:\n";
21-
echo " php tame key:generate\n\n";
20+
Logger::helpHeader('<yellow>Usage:</yellow>');
21+
Logger::writeln(' php tame key:generate');
22+
Logger::writeln('');
2223
}
2324

2425
/**
@@ -29,12 +30,11 @@ public function generate()
2930
{
3031
$key = Manager::regenerate();
3132
if ( !$key) {
32-
Logger::error('Failed to generate the application key.');
33-
return 0;
33+
$this->error('Failed to generate the application key.');
34+
return;
3435
}
3536

36-
Logger::success("Application key generated: {$key}\n");
37-
return 1;
37+
$this->success("Application key generated: {$key}");
3838
}
3939

4040
}

src/Console/Commands/MigrationCommand.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ class MigrationCommand extends CommandHelper
2424
*/
2525
public function handle()
2626
{
27-
echo "Usage examples:\n";
28-
echo " php tame migrate:fresh --seed --force\n";
29-
echo " php tame migrate:refresh --seed --force\n";
30-
echo " php tame migrate:status\n";
31-
echo " php tame migrate:reset\n";
27+
Logger::helpHeader('<yellow>Usage:</yellow>');
28+
Logger::writeln(' php tame migrate:fresh --seed --force');
29+
Logger::writeln(' php tame migrate:refresh');
30+
Logger::writeln(' php tame migrate:status');
31+
Logger::writeln(' php tame migrate:reset');
32+
Logger::writeln('');
3233
}
3334

3435
/**
@@ -40,8 +41,6 @@ public function fresh()
4041
$force = $this->option('force');
4142
$seed = $this->option('seed');
4243

43-
44-
4544
if($force){
4645
Artisan::call('db:wipe --force --drop-types --drop-views --response=0');
4746
}
@@ -96,7 +95,7 @@ public function status()
9695

9796
if (!is_dir($migrationsDir)) {
9897
$this->warning("Migrations directory not found: {$migrationsDir}");
99-
return 0;
98+
return;
10099
}
101100

102101
// Connect to DB and validate connection
@@ -111,7 +110,7 @@ public function status()
111110

112111
if (empty($files)) {
113112
$this->info("No migration files found in: {$migrationsDir}");
114-
return 0;
113+
return;
115114
}
116115

117116
// Build a single table output
@@ -139,7 +138,7 @@ public function status()
139138

140139
if (empty($rows)) {
141140
$this->info("No detectable migration tables.");
142-
return 0;
141+
return;
143142
}
144143

145144
// Compute column widths
@@ -168,7 +167,7 @@ public function status()
168167
}
169168
Logger::writeln($sep);
170169

171-
return 0;
170+
return;
172171
}
173172

174173
}

src/Console/Commands/ScaffoldCommand.php

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace Tamedevelopers\Database\Console\Commands;
66

77
use Tamedevelopers\Support\Env;
8+
use Tamedevelopers\Support\Tame;
9+
use Tamedevelopers\Database\AutoLoader;
810
use Tamedevelopers\Database\DatabaseManager;
911
use Tamedevelopers\Support\Capsule\CommandHelper;
1012

@@ -19,19 +21,31 @@ class ScaffoldCommand extends CommandHelper
1921
*/
2022
public function handle()
2123
{
22-
23-
dd(
24-
'scaffold command'
25-
);
26-
// Ensure env and logger are booted
27-
Env::boot();
28-
Env::loadOrFail();
29-
30-
// Example: ensure connection booted (if your manager requires it)
31-
// Adjust to your initialization flow if different
32-
$db = new DatabaseManager();
24+
// if app is running inside of a framework
25+
$frameworkChecker = (new Tame)->isAppFramework();
26+
27+
// force scaffold command only on local environment
28+
$force = $this->force();
29+
30+
// Check for framework mode
31+
if(!$frameworkChecker && !$force){
32+
$this->warning("Sorry! This command can't be run in a framework.");
33+
return;
34+
}
35+
36+
// prompt for confirmation before proceeding
37+
$confirm = $this->confirm('Proceed with Scalfolding the application?');
38+
39+
// ask once
40+
if (!$confirm) {
41+
$this->warning("Command aborted.");
42+
return;
43+
}
3344

45+
// scalffolding database manager
46+
AutoLoader::start();
3447

48+
$this->info("App scalffolding Manager has been successfully runned!");
3549
}
3650

3751
}

0 commit comments

Comments
 (0)