Skip to content

Commit 05e2988

Browse files
command update for CLI and browser support
1 parent be76b47 commit 05e2988

File tree

8 files changed

+99
-123
lines changed

8 files changed

+99
-123
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ AutoLoader::start();
213213

214214

215215
## Tame Cli
216-
- Custom support for CLI commands
216+
- Custom commands support for CLI
217217

218218
```bash
219219
php tame list
@@ -229,7 +229,7 @@ php tame scaffold:run --force
229229
```
230230

231231
### tame-artisan-call
232-
- Using the CLI from within php, withing the CMD interface.
232+
- Using the CLI from within php, without the CMD interface.
233233

234234
```php
235235
use Tamedevelopers\Support\Capsule\Artisan;

database.php

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

src/Console/Commands/DBCommand.php

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,31 @@ public function schema()
5050
$path = $this->option('path');
5151
$type = $this->option('type');
5252

53-
$import = new DBSchemaExport(
53+
$schema = new DBSchemaExport(
5454
path: !empty($path) ? base_path($path) : $path,
5555
connection: $connection,
5656
type: $type,
5757
);
5858

59-
$this->checkConnection($import->conn);
60-
61-
$response = null;
59+
$this->checkConnection($schema->conn);
60+
$response = ['status' => Constant::STATUS_400, 'message' => ''];
6261

63-
$this->progressBar(function ($report) use ($import, &$response) {
64-
$response = $import->run();
65-
$report();
66-
});
62+
if ($this->isConsole()) {
63+
$this->progressBar(function ($report) use ($schema, &$response) {
64+
$response = $schema->run();
65+
$report();
66+
});
67+
} else{
68+
$response = $schema->run();
69+
}
6770

6871
if($response['status'] != Constant::STATUS_200){
6972
$this->error($response['message']);
70-
return;
73+
return 0;
7174
}
7275

7376
$this->success($response['message']);
77+
return 1;
7478
}
7579

7680
/**
@@ -88,21 +92,24 @@ public function import()
8892
);
8993

9094
$this->checkConnection($import->conn);
95+
$response = ['status' => Constant::STATUS_400, 'message' => ''];
9196

92-
$response = null;
93-
94-
$this->progressBar(function ($report) use ($import, &$response) {
97+
if ($this->isConsole()) {
98+
$this->progressBar(function ($report) use ($import, &$response) {
99+
$response = $import->run();
100+
$report();
101+
});
102+
} else{
95103
$response = $import->run();
96-
97-
$report();
98-
});
104+
}
99105

100106
if($response['status'] != Constant::STATUS_200){
101107
$this->error($response['message']);
102-
return;
108+
return 0;
103109
}
104110

105111
$this->success($response['message']);
112+
return 1;
106113
}
107114

108115
/**
@@ -122,24 +129,27 @@ public function export()
122129
);
123130

124131
$this->checkConnection($export->conn);
132+
$response = ['status' => Constant::STATUS_400, 'message' => ''];
125133

126-
$response = null;
127-
128-
$this->progressBar(function ($report) use ($export, &$response) {
134+
if ($this->isConsole()) {
135+
$this->progressBar(function ($report) use ($export, &$response) {
136+
$response = $export->run();
137+
$report();
138+
});
139+
} else{
129140
$response = $export->run();
130-
131-
$report();
132-
});
141+
}
133142

134143
if($response['status'] != Constant::STATUS_200){
135144
$this->error($response['message']);
136-
return;
145+
return 0;
137146
}
138147

139148
// path
140149
$path = empty($response['path']) ? '' : "\n{$response['path']}";
141150

142151
$this->success("{$response['message']}{$path}");
152+
return 1;
143153
}
144154

145155
/**
@@ -148,18 +158,18 @@ public function export()
148158
*/
149159
public function wipe()
150160
{
151-
$force = $this->option('force');
161+
$force = $this->force();
152162
$response = $this->option('response');
153163

154164
$this->forceChecker();
155-
165+
156166
// prompt for confirmation before proceeding
157167
$confirm = $this->confirm('Proceed with db:wipe?');
158168

159169
// ask once
160-
if (!$confirm) {
170+
if (!$confirm && $this->isConsole()) {
161171
$this->warning("Command aborted.");
162-
return;
172+
return 0;
163173
}
164174

165175
$tables = $this->getTables();
@@ -170,7 +180,7 @@ public function wipe()
170180
$allItems = array_merge($views, $tables, $types);
171181

172182
// only display response when needed
173-
if($this->shouldResponseReturn($response)){
183+
if($this->shouldResponseReturn($response) && $this->isConsole()){
174184
$this->progressBar(function ($report) use ($views, $tables, $types) {
175185
$this->processWipeData($views, $tables, $types, $report);
176186
}, count($allItems));
@@ -179,6 +189,8 @@ public function wipe()
179189
} else{
180190
$this->processWipeData($views, $tables, $types);
181191
}
192+
193+
return 1;
182194
}
183195

184196
/**

src/Console/Commands/KeyCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ public function generate()
3131
$key = Manager::regenerate();
3232
if ( !$key) {
3333
$this->error('Failed to generate the application key.');
34-
return;
34+
return 0;
3535
}
3636

3737
$this->success("Application key generated: {$key}");
38+
return 1;
3839
}
3940

4041
}

src/Console/Commands/MakeCommand.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,36 @@ public function migration()
4040
}
4141

4242
// if no table file name
43-
if(empty($table)){
43+
if(empty($table) && $this->isConsole()){
4444
$table = $this->ask("\nWhat should the migration be named?");
4545
}
46+
47+
if(empty($table)){
48+
return 0;
49+
}
4650

47-
$table = $this->extractTableName($table);
51+
// if create flag come, then we use it as table name
52+
if(!empty($create)){
53+
$table = $create;
54+
} else{
55+
$table = $this->extractTableName($table);
56+
}
4857

4958
$migration = new Migration();
5059

5160
$response = $migration->create($table);
5261

5362
if($response['status'] != Constant::STATUS_200){
5463
$this->error($response['message']);
55-
exit(0);
64+
if($this->isConsole()){
65+
exit(0);
66+
} else{
67+
return 0;
68+
}
5669
}
5770

5871
$this->info($response['message']);
72+
return 1;
5973
}
6074

6175
}

src/Console/Commands/MigrationCommand.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,35 @@ public function handle()
3838
*/
3939
public function fresh()
4040
{
41-
$force = $this->option('force');
41+
$force = $this->force();
4242
$seed = $this->option('seed');
4343

4444
if($force){
4545
Artisan::call('db:wipe --force --drop-types --drop-views --response=0');
4646
}
4747

4848
$migration = new Migration();
49-
5049
$response = $migration->run();
5150

5251
if($response['status'] != Constant::STATUS_200){
5352
$this->error($response['message']);
54-
exit(0);
53+
if($this->isConsole()){
54+
exit(0);
55+
} else{
56+
return 0;
57+
}
5558
}
5659

5760
$this->info($response['message']);
61+
return 1;
5862
}
5963

6064
/**
6165
* Reset and re-run all migrations
6266
*/
6367
public function refresh()
6468
{
65-
Artisan::call('migrate:fresh --force --drop-types --drop-views');
69+
return Artisan::call('migrate:fresh --force --drop-types --drop-views');
6670
}
6771

6872
/**
@@ -79,10 +83,11 @@ public function reset()
7983

8084
if ($response['status'] != Constant::STATUS_200) {
8185
$this->error($response['message']);
82-
return;
86+
return 0;
8387
}
8488

8589
$this->info($response['message']);
90+
return 1;
8691
}
8792

8893
/**
@@ -95,7 +100,7 @@ public function status()
95100

96101
if (!is_dir($migrationsDir)) {
97102
$this->warning("Migrations directory not found: {$migrationsDir}");
98-
return;
103+
return 0;
99104
}
100105

101106
// Connect to DB and validate connection
@@ -110,7 +115,7 @@ public function status()
110115

111116
if (empty($files)) {
112117
$this->info("No migration files found in: {$migrationsDir}");
113-
return;
118+
return 0;
114119
}
115120

116121
// Build a single table output
@@ -138,7 +143,7 @@ public function status()
138143

139144
if (empty($rows)) {
140145
$this->info("No detectable migration tables.");
141-
return;
146+
return 0;
142147
}
143148

144149
// Compute column widths
@@ -167,7 +172,7 @@ public function status()
167172
}
168173
Logger::writeln($sep);
169174

170-
return;
175+
return 1;
171176
}
172177

173178
}

0 commit comments

Comments
 (0)