Skip to content

Commit

Permalink
Move debug process into handleException method
Browse files Browse the repository at this point in the history
  • Loading branch information
afbora committed Feb 24, 2024
1 parent 3a19f8d commit c701b09
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/CLI/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static function command(...$args): void
try {
$cli->run(...$args);
} catch (Throwable $e) {
$cli->error((string)$e);
$cli->handleException($e);
}
}

Expand Down Expand Up @@ -312,6 +312,19 @@ public function dir(?string $folder = null): string
return $folder;
}

/**
* Handles exception with throwing exception or out error message
*/
protected function handleException(Throwable $e): never
{
if ($this->isDefined('debug') === true) {
throw $e;
}

$this->error($e->getMessage());
exit;
}

/**
* Gets path for global commands (respecting 'XDG_CONFIG_HOME' if set)
*
Expand Down Expand Up @@ -531,12 +544,7 @@ public function run(?string $name = null, ...$args): void
try {
$this->climate->arguments->parse($argv);
} catch (Throwable $e) {
if ($this->climate->arguments->defined('debug') === true) {
throw $e;
}

$this->error($e->getMessage());
exit;
$this->handleException($e);
}

// enable quiet mode
Expand All @@ -553,12 +561,7 @@ public function run(?string $name = null, ...$args): void
try {
$command['command']($this);
} catch (Throwable $e) {
if ($this->climate->arguments->defined('debug') === true) {
throw $e;
}

$this->error($e->getMessage());
exit;
$this->handleException($e);
}
}

Expand Down

0 comments on commit c701b09

Please sign in to comment.