Skip to content

Commit

Permalink
Merge pull request #14 from getkirby/develop
Browse files Browse the repository at this point in the history
1.0.1
  • Loading branch information
bastianallgeier authored Oct 5, 2022
2 parents 5c7a9cf + c2729d2 commit 9182f92
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
50 changes: 29 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ The Kirby command line interface helps simplifying common tasks with your Kirby
composer global require getkirby/cli
```

Make sure to add the following to your `~/.bash_profile` (Mac OS users) or into your `~/.bashrc` (Linux users).
Make sure to add your composer bin directory to your `~/.bash_profile` (Mac OS users) or into your `~/.bashrc` (Linux users).

Your global composer directory is normally either `~/.composer/vendor/bin` or `~/.config/composer/vendor/bin`. You can find the correct path by running …

```
composer -n config --global home
```

Afterwards, add the result to your bash profile …

```
export PATH=~/.composer/vendor/bin:$PATH
Expand All @@ -24,7 +32,7 @@ export PATH=~/.composer/vendor/bin:$PATH
Check if the installation worked by running the following in your terminal.

```
kirby
kirby
```

This should print the Kirby CLI version and a list of available commands
Expand Down Expand Up @@ -58,15 +66,15 @@ This should print the Kirby CLI version and a list of available commands

## Writing commands

You can create a new command via the CLI:
You can create a new command via the CLI:

```bash
kirby make:command hello
```

This will create a new `site/commands` folder in your installation with a new `hello.php` file

The CLI will already put the basic scaffolding into the file:
The CLI will already put the basic scaffolding into the file:

```php
<?php
Expand All @@ -80,7 +88,7 @@ return [
];
```

You can define your command logic in the command callback. The `$cli` object comes with a set of handy tools to create output, parse command arguments, create prompts and more.
You can define your command logic in the command callback. The `$cli` object comes with a set of handy tools to create output, parse command arguments, create prompts and more.

## Global commands

Expand All @@ -90,7 +98,7 @@ You might have some commands that you need for all your local Kirby installation
kirby make:command hello --global
```

The command file will then be place in `~/.kirby/commands/hello.php` and is automatically available everywhere.
The command file will then be place in `~/.kirby/commands/hello.php` and is automatically available everywhere.

## Check for installed commands

Expand All @@ -108,39 +116,39 @@ Once you no longer need a command, you can remove it with …
kirby remove:command hello
```

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

## Formatting Output

Sending messages to the terminal is super easy.
Sending messages to the terminal is super easy.

### $cli->out()

```php
```php
$cli->out('This is some simple text');
```

### $cli->success()

```php
```php
$cli->success('This is text in a nice green box');
```

### $cli->error()

```php
```php
$cli->error('This is red text for errors');
```

### $cli->bold()

```php
```php
$cli->bold('This is some bold text');
```

### $cli->br()

```php
```php
// this will create a line break
$cli->br();
```
Expand All @@ -149,7 +157,7 @@ For more available colors and formats, check out the CLImate docs: https://clima

## Arguments

Your commands can define a list of required and optional arguments that need to be provided by the user.
Your commands can define a list of required and optional arguments that need to be provided by the user.

```php
<?php
Expand All @@ -174,7 +182,7 @@ The command can now be executed by providing the name …
kirby hello Joe
```

If no name is provided, an error will be shown.
If no name is provided, an error will be shown.

### Argument docs

Expand All @@ -196,7 +204,7 @@ return [
];
```

As a third alternative you can either take the argument or ask for it if it is not provided:
As a third alternative you can either take the argument or ask for it if it is not provided:

```php
<?php
Expand All @@ -215,13 +223,13 @@ return [
];
```

## Checkboxes Radios and more
## Checkboxes Radios and more

The CLI also supports more complex ways to get input from users. Check out the CLImate docs how to work with user input: https://climate.thephpleague.com/terminal-objects/input/
The CLI also supports more complex ways to get input from users. Check out the CLImate docs how to work with user input: https://climate.thephpleague.com/terminal-objects/input/

## Combining commands

You can reuse all existing commands in your custom commands to create entire chains of actions.
You can reuse all existing commands in your custom commands to create entire chains of actions.

```php
<?php
Expand All @@ -240,7 +248,7 @@ return [

## kirby.cli.json

You can place a kirby.cli.json file in root folder of your project to setup the Kirby instance with custom directories. This is useful if you use a non-standard Kirby installation with a public webroot for example.
You can place a kirby.cli.json file in root folder of your project to setup the Kirby instance with custom directories. This is useful if you use a non-standard Kirby installation with a public webroot for example.

```json
{
Expand Down Expand Up @@ -278,7 +286,7 @@ The config can also set where local commands are stored. By default, they are st

---

© 2009-2022 Bastian Allgeier
© 2009-2022 Bastian Allgeier
[getkirby.com](https://getkirby.com) · [License agreement](./LICENSE.md)


Expand Down
2 changes: 2 additions & 0 deletions commands/make/command.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
],
'command' => static function (CLI $cli): void {
$name = $cli->argOrPrompt('name', 'Enter a name for the command:');
$name = str_replace(':', '/', $name);

$root = $cli->arg('global') === true ? 'commands.global' : 'commands.local';
$file = $cli->root($root) . '/' . $name . '.php';

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "getkirby/cli",
"description": "Kirby command line interface",
"license": "MIT",
"version": "1.0.0",
"version": "1.0.1",
"keywords": [
"kirby",
"cms",
Expand All @@ -24,6 +24,7 @@
}
],
"require": {
"composer-runtime-api": "^2.2",
"ext-zip": "*",
"guzzlehttp/guzzle": "^7.5",
"league/climate": "^3.8",
Expand Down

0 comments on commit 9182f92

Please sign in to comment.