Skip to content

Commit 14b714d

Browse files
update
1 parent 54c9649 commit 14b714d

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

Capsule/CommandHelper.php

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected function forceChecker($options = []): void
4848
{
4949
$force = isset($options['force']) || isset($options['f']);
5050

51-
if ($this->isProductionEnv()) {
51+
if ($this->isProduction()) {
5252
if (!$force) {
5353
$this->error("You are in production! Use [--force|-f] flag, to run this command.");
5454
exit(1);
@@ -59,7 +59,7 @@ protected function forceChecker($options = []): void
5959
/**
6060
* Extracts the flag types from option keys like "drop-types" or "drop-views".
6161
*/
62-
protected function getFlagTypes($options = []): array
62+
protected function flag($options = []): array
6363
{
6464
$types = [];
6565
foreach ($options as $key => $value) {
@@ -73,7 +73,7 @@ protected function getFlagTypes($options = []): array
7373
/**
7474
* Determine if the current environment is production.
7575
*/
76-
protected function isProductionEnv(): bool
76+
protected function isProduction(): bool
7777
{
7878
$env = Env::env('APP_ENV');
7979
$productionAliases = ['prod', 'production', 'live'];
@@ -83,19 +83,36 @@ protected function isProductionEnv(): bool
8383

8484
/**
8585
* Get a specific option value from options array.
86-
* Example: getOption($options, 'force', false)
87-
*/
88-
protected function getOption(array $options, string $key, $default = null)
86+
* Example: option('force', false)
87+
*
88+
* @param string $key
89+
* @param string|array|bool|null $default
90+
*
91+
* @return mixed
92+
*/
93+
protected function option(string $key, $default = null)
8994
{
90-
return $options[$key] ?? $default;
95+
// backtrace
96+
$trace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 2);
97+
98+
// get backtrace information about the caller's context
99+
$args = $trace[1]['args'][1] ?? [];
100+
101+
return $args[$key] ?? $default;
91102
}
92103

93104
/**
94105
* Check if an option/flag exists and is truthy.
95106
*/
96-
protected function hasOption(array $options, string $key): bool
107+
protected function hasOption(string $key): bool
97108
{
98-
return !empty($options[$key]);
109+
// backtrace
110+
$trace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 2);
111+
112+
// get backtrace information about the caller's context
113+
$args = $trace[1]['args'][1] ?? [];
114+
115+
return !empty($args[$key]);
99116
}
100117

101118
/**

Commands/MakeCommand.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
class MakeCommand extends CommandHelper
1313
{
1414
/**
15-
* Default entry when running command
15+
* Default entry when running commands.
16+
*
17+
* @return void
1618
*/
17-
public function handle(array $args = [], array $options = []): int
19+
public function handle()
1820
{
19-
echo "Usage examples:\n";
20-
echo " php tame make\n";
21-
echo " php tame make:command [name] --path=users\n\n";
22-
return 0;
21+
Logger::helpHeader('<yellow>Usage:</yellow>');
22+
Logger::writeln(' php tame make:command [name] --path=users');
23+
Logger::writeln('');
2324
}
2425

2526
/**
@@ -28,7 +29,7 @@ public function handle(array $args = [], array $options = []): int
2829
public function command(array $args = [], array $options = []): int
2930
{
3031
$name = $args[0] ?? null;
31-
$path = $this->getOption($options, 'path');
32+
$path = $this->hasOption('path');
3233

3334
// if not provided, prompt for file name
3435
if(empty($name)){

0 commit comments

Comments
 (0)