Skip to content

Commit

Permalink
🚧 converting from jobs to commands
Browse files Browse the repository at this point in the history
Signed-off-by: bnomei <b@bnomei.com>
  • Loading branch information
bnomei committed Nov 13, 2022
1 parent 19e9f5d commit 0b49b51
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion README.md
Expand Up @@ -238,7 +238,7 @@ If you want you can also call any of [the core shipping with the CLI](https://gi

### Running commands in your code

You can run any command in you own code as well like in a model, template, controller or hook. Since commands do not return data directly you need to retrieve data stored for janitor using a helper `janitor()->data($commandName)`.
You can run any command in you own code as well like in a model, template, controller or hook. Since commands do not return data directly you need to retrieve data stored for Janitor using a helper `janitor()->data($commandName)`.

#### Get data returned from a command
```php
Expand All @@ -260,6 +260,28 @@ if(F::exists($backup)) {
}
```

#### Calling a command with parameters

Supplying parameter to the core CLI functions can be a bit tricky since you need to separate argument key and argument values. It seems easy with one but gets a bit tedious with a dynamic list of parameters and if values contain `space`-chars or quotes. But fret not – Janitor has a helper for that as well.

```php
Kirby\CLI\CLI::command('uuid', '--page', 'page://82h2nkal12ls'); // tests/site/commands/uuid.php

janitor()->command('uuid --page page://82h2nkal12ls');

var_dump(janitor()->data('whistle'));
```

> Remember that using the `janitor()->command($string)`-helper you can call any of your own commands and the core commands as well, not just the ones defined by Janitor.
If you want to work with command strings yourself you can use the following static helper method.

```php
list($name, $args) = Bnomei\Janitor::parseCommand('uuid --page page://82h2nkal12ls');
Kirby\CLI\CLI::command($name, ...$args);
```


### Webhook with secret

You can not call Janitors api unauthenticated. You either need to use the panel button or you can set a `secret` in your config.php file and call the janitor api URL with that secret.
Expand Down

0 comments on commit 0b49b51

Please sign in to comment.