Skip to content

Commit 173c99d

Browse files
committed
Create Optional "Add to Git" Functionality
1 parent 78c275c commit 173c99d

8 files changed

+67
-19
lines changed

src/Commands/MakeAllRepository.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ class MakeAllRepository extends Command
1111
*
1212
* @var string
1313
*/
14-
protected $signature = 'command:make-all-repository {table_names*} {--k|foreign-keys : Detect foreign keys} {--d|delete : Delete resource} {--f|force : Override/Delete existing classes}';
14+
protected $signature = 'command:make-all-repository {table_names*}
15+
{--k|foreign-keys : Detect foreign keys}
16+
{--d|delete : Delete resource}
17+
{--f|force : Override/Delete existing classes}
18+
{--g|add-to-git : Add created file to git repository}';
1519

1620
/**
1721
* The console command description.
@@ -39,22 +43,24 @@ public function handle()
3943
$force = $this->option('force');
4044
$delete = $this->option('delete');
4145
$detectForeignKeys = $this->option('foreign-keys');
46+
$addToGit = $this->option('add-to-git');
4247

4348
foreach ($tableNames as $_tableName) {
4449
$arguments = [
4550
'table_name' => $_tableName,
4651
'--foreign-keys' => $detectForeignKeys,
4752
'--delete' => $delete,
48-
'--force' => $force
53+
'--force' => $force,
54+
'--add-to-git' => $addToGit
4955
];
5056

5157
$this->call('command:make-entity', $arguments);
52-
$this->call('command:make-factory', ['table_name' => $_tableName, '--delete' => $delete, '--force' => $force]);
58+
$this->call('command:make-factory', ['table_name' => $_tableName, '--delete' => $delete, '--force' => $force, '--add-to-git' => $addToGit]);
5359
$this->call('command:make-resource', $arguments);
5460
$this->call('command:make-interface-repository', $arguments);
5561
$this->call('command:make-mysql-repository', $arguments);
5662
$this->call('command:make-redis-repository', $arguments);
57-
$this->call('command:make-repository', ['table_name' => $_tableName, '--delete' => $delete, '--force' => $force]);
63+
$this->call('command:make-repository', ['table_name' => $_tableName, '--delete' => $delete, '--force' => $force, '--add-to-git' => $addToGit]);
5864
}
5965
}
6066
}

src/Commands/MakeEntity.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ class MakeEntity extends Command
1212
*
1313
* @var string
1414
*/
15-
protected $signature = 'command:make-entity {table_name} {--k|foreign-keys : Detect foreign keys} {--d|delete : Delete resource} {--f|force : Override/Delete existing mysql repository}';
15+
protected $signature = 'command:make-entity {table_name}
16+
{--k|foreign-keys : Detect foreign keys}
17+
{--d|delete : Delete resource}
18+
{--f|force : Override/Delete existing mysql repository}
19+
{--g|add-to-git : Add created file to git repository}';
1620

1721
/**
1822
* The console command description.
@@ -123,13 +127,17 @@ public function handle(): int
123127
// Create Additional Setters and Getters from Foreign keys
124128
if ($detectForeignKeys) {
125129
foreach ($foreignKeys as $_foreignKey) {
126-
$baseContent = substr_replace($baseContent, $this->writeAccessors($accessorsStub, $_foreignKey->VARIABLE_NAME, $_foreignKey->ENTITY_DATA_TYPE), -1, 0);
130+
$baseContent = substr_replace($baseContent,
131+
$this->writeAccessors($accessorsStub, $_foreignKey->VARIABLE_NAME, $_foreignKey->ENTITY_DATA_TYPE),
132+
-1, 0);
127133
}
128134
}
129135

130136
file_put_contents($filenameWithPath, $baseContent);
131137

132-
shell_exec('git add '.$filenameWithPath);
138+
if ($this->option('add-to-git')) {
139+
shell_exec('git add '.$filenameWithPath);
140+
}
133141

134142
$this->info("Entity \"$entityName\" has been created.");
135143

src/Commands/MakeFactory.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ class MakeFactory extends Command
1212
*
1313
* @var string
1414
*/
15-
protected $signature = 'command:make-factory {table_name} {--d|delete : Delete resource} {--f|force : Override/Delete existing factory class}';
15+
protected $signature = 'command:make-factory {table_name}
16+
{--d|delete : Delete resource}
17+
{--f|force : Override/Delete existing factory class}
18+
{--g|add-to-git : Add created file to git repository}';
1619

1720
/**
1821
* The console command description.
@@ -88,7 +91,9 @@ public function handle(): int
8891

8992
file_put_contents("$relativeFactoriesPath/$factoryName.php", $factoryContent);
9093

91-
shell_exec("git add $relativeFactoriesPath/$factoryName.php");
94+
if ($this->option('add-to-git')) {
95+
shell_exec("git add $relativeFactoriesPath/$factoryName.php");
96+
}
9297

9398
$this->info("Factory \"$factoryName\" has been created.");
9499

src/Commands/MakeInterfaceRepository.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ class MakeInterfaceRepository extends Command
1212
*
1313
* @var string
1414
*/
15-
protected $signature = 'command:make-interface-repository {table_name} {--k|foreign-keys : Detect foreign keys} {--d|delete : Delete resource} {--f|force : Override/Delete existing mysql repository}';
15+
protected $signature = 'command:make-interface-repository {table_name}
16+
{--k|foreign-keys : Detect foreign keys}
17+
{--d|delete : Delete resource}
18+
{--f|force : Override/Delete existing mysql repository}
19+
{--g|add-to-git : Add created file to git repository}';
1620

1721
/**
1822
* The console command description.
@@ -105,7 +109,9 @@ public function handle(): int
105109

106110
file_put_contents("$relativeInterfacePath/$interfaceName.php", $interfaceContent);
107111

108-
shell_exec("git add $relativeInterfacePath/$interfaceName.php");
112+
if ($this->option('add-to-git')) {
113+
shell_exec("git add $relativeInterfacePath/$interfaceName.php");
114+
}
109115

110116
$this->info("Interface \"$interfaceName\" has been created.");
111117

src/Commands/MakeMySqlRepository.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ class MakeMySqlRepository extends Command
1212
*
1313
* @var string
1414
*/
15-
protected $signature = 'command:make-mysql-repository {table_name} {--k|foreign-keys : Detect foreign keys} {--d|delete : Delete resource} {--f|force : Override/Delete existing mysql repository}';
15+
protected $signature = 'command:make-mysql-repository {table_name}
16+
{--k|foreign-keys : Detect foreign keys}
17+
{--d|delete : Delete resource}
18+
{--f|force : Override/Delete existing mysql repository}
19+
{--g|add-to-git : Add created file to git repository}';
1620

1721
/**
1822
* The console command description.
@@ -196,7 +200,9 @@ public function handle(): int
196200

197201
file_put_contents("$relativeMysqlRepositoryPath/$mysqlRepositoryName.php", $mysqlRepositoryContent);
198202

199-
shell_exec("git add $relativeMysqlRepositoryPath/$mysqlRepositoryName.php");
203+
if ($this->option('add-to-git')) {
204+
shell_exec("git add $relativeMysqlRepositoryPath/$mysqlRepositoryName.php");
205+
}
200206

201207
$this->info("MySql Repository \"$mysqlRepositoryName\" has been created.");
202208

src/Commands/MakeRedisRepository.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ class MakeRedisRepository extends Command
1212
*
1313
* @var string
1414
*/
15-
protected $signature = 'command:make-redis-repository {table_name} {--k|foreign-keys : Detect foreign keys} {--d|delete : Delete resource} {--f|force : Override/Delete existing redis repository}';
15+
protected $signature = 'command:make-redis-repository {table_name}
16+
{--k|foreign-keys : Detect foreign keys}
17+
{--d|delete : Delete resource}
18+
{--f|force : Override/Delete existing redis repository}
19+
{--g|add-to-git : Add created file to git repository}';
1620

1721
/**
1822
* The console command description.
@@ -85,7 +89,9 @@ public function handle(): int
8589

8690
file_put_contents("$relativeRedisRepositoryPath/$redisRepositoryName.php", $redisRepositoryContent);
8791

88-
shell_exec("git add $relativeRedisRepositoryPath/$redisRepositoryName.php");
92+
if ($this->option('add-to-git')) {
93+
shell_exec("git add $relativeRedisRepositoryPath/$redisRepositoryName.php");
94+
}
8995

9096
$this->info("Redis Repository \"$redisRepositoryName\" has been created.");
9197

src/Commands/MakeRepository.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ class MakeRepository extends Command
1111
*
1212
* @var string
1313
*/
14-
protected $signature = 'command:make-repository {table_name} {--d|delete : Delete resource} {--f|force : Override/Delete existing repository class}';
14+
protected $signature = 'command:make-repository {table_name}
15+
{--d|delete : Delete resource}
16+
{--f|force : Override/Delete existing repository class}
17+
{--g|add-to-git : Add created file to git repository}';
1518

1619
/**
1720
* The console command description.
@@ -66,7 +69,9 @@ public function handle(): int
6669

6770
file_put_contents("$relativeRepositoryPath/$repository.php", $repositoryContent);
6871

69-
shell_exec("git add $relativeRepositoryPath/$repository.php");
72+
if ($this->option('add-to-git')) {
73+
shell_exec("git add $relativeRepositoryPath/$repository.php");
74+
}
7075

7176
$this->info("Repository \"$repository\" has been created.");
7277

src/Commands/MakeResource.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ class MakeResource extends Command
1212
*
1313
* @var string
1414
*/
15-
protected $signature = 'command:make-resource {table_name} {--k|foreign-keys : Detect foreign keys} {--d|delete : Delete resource} {--f|force : Override/Delete existing mysql repository}';
15+
protected $signature = 'command:make-resource {table_name}
16+
{--k|foreign-keys : Detect foreign keys}
17+
{--d|delete : Delete resource}
18+
{--f|force : Override/Delete existing mysql repository}
19+
{--g|add-to-git : Add created file to git repository}';
1620

1721
/**
1822
* The console command description.
@@ -105,7 +109,9 @@ public function handle(): int
105109

106110
file_put_contents("$relativeResourcesPath/$resourceName.php", $resourceContent);
107111

108-
shell_exec("git add $relativeResourcesPath/$resourceName.php");
112+
if ($this->option('add-to-git')) {
113+
shell_exec("git add $relativeResourcesPath/$resourceName.php");
114+
}
109115

110116
$this->info("Resource \"$resourceName\" has been created.");
111117

0 commit comments

Comments
 (0)