Skip to content

Commit

Permalink
New debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
afbora committed Feb 23, 2024
1 parent 6430c1f commit c50c8f3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ Once you no longer need a command, you can remove it with …
kirby remove:command hello
```

## Debugging

Use the `-d` or `--debug` argument to run the command in debug mode:

```bash
kirby make:command hello --debug
```

If you have a local and a global command, you can choose which one to delete.

## Formatting Output
Expand Down
27 changes: 25 additions & 2 deletions src/CLI/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ public function run(?string $name = null, ...$args): void
]
]);

// add help as last argument
// add help argument
$this->climate->arguments->add([
'help' => [
'description' => 'Prints a usage statement',
Expand All @@ -511,6 +511,16 @@ public function run(?string $name = null, ...$args): void
]
]);

// add debug argument
$this->climate->arguments->add([
'debug' => [
'description' => 'Enables debug mode',
'prefix' => 'd',
'longPrefix' => 'debug',
'noValue' => true
]
]);

// build the args array
$argv = [
'kirby',
Expand All @@ -521,6 +531,10 @@ 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;
}
Expand All @@ -536,7 +550,16 @@ public function run(?string $name = null, ...$args): void
return;
}

$command['command']($this);
try {
$command['command']($this);
} catch (Throwable $e) {
if ($this->climate->arguments->defined('debug') === true) {
throw $e;
}

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

/**
Expand Down

0 comments on commit c50c8f3

Please sign in to comment.