An open API service indexing awesome lists of open source software.

https://github.com/decodelabs/clip

CLI kernel integration for DecodeLabs Genesis
https://github.com/decodelabs/clip

cli kernel php

Last synced: about 1 year ago
JSON representation

CLI kernel integration for DecodeLabs Genesis

Awesome Lists containing this project

README

          

# Clip

[![PHP from Packagist](https://img.shields.io/packagist/php-v/decodelabs/clip?style=flat)](https://packagist.org/packages/decodelabs/clip)
[![Latest Version](https://img.shields.io/packagist/v/decodelabs/clip.svg?style=flat)](https://packagist.org/packages/decodelabs/clip)
[![Total Downloads](https://img.shields.io/packagist/dt/decodelabs/clip.svg?style=flat)](https://packagist.org/packages/decodelabs/clip)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/decodelabs/clip/integrate.yml?branch=develop)](https://github.com/decodelabs/clip/actions/workflows/integrate.yml)
[![PHPStan](https://img.shields.io/badge/PHPStan-enabled-44CC11.svg?longCache=true&style=flat)](https://github.com/phpstan/phpstan)
[![License](https://img.shields.io/packagist/l/decodelabs/clip?style=flat)](https://packagist.org/packages/decodelabs/clip)

### CLI kernel integration for DecodeLabs Genesis

Clip provides a framework for building comprehensive CLI based applications on top of [Genesis](https://github.com/decodelabs/genesis).

---

## Installation

Install via Composer:

```bash
composer require decodelabs/clip
```

## Usage

Clip is a middleware library that provides an out-of-the-box setup for implementing a Genesis based CLI task runner. This means you don't really interact with it much directly, except when setting up the core of your task running infrastructure.

### Create your Hub

Define your Genesis Hub by extending Clip's abstract implementation:

```php
namespace MyThing;

use DecodeLabs\Archetype;
use DecodeLabs\Clip\Controller as ControllerInterface;
use DecodeLabs\Clip\Hub as ClipHub;
use DecodeLabs\Clip\Task as TaskInterface;
use DecodeLabs\Monarch;
use DecodeLabs\Pandora\Container;
use DecodeLabs\Veneer;
use MyThing;
use MyThing\Controller;
use MyThing\Task;

class Hub extends ClipHub
{
public function initializePlatform(): void
{
parent::initializePlatform();

// Load tasks from local namespace
Archetype::map(TaskInterface::class, Task::class);

// Create and load your controller (or use Generic)
if(Monarch::$container instanceof Container) {
$controller = new Controller();

Monarch::$container->bindShared(ControllerInterface::class, $controller);
Monarch::$container->bindShared(Controller::class, $controller);
}

// Bind your controller with Veneer
Veneer::register(Controller::class, MyThing::class);
}
}
```

With this hub in place, you can run tasks defined in your nominated namespace from the terminal via a bin defined in composer:

```php
namespace MyThing;

use DecodeLabs\Genesis\Bootstrap\Bin as BinBootstrap;
use MyThing\Hub;

require_once $_composer_autoload_path ?? __DIR__ . '/../vendor/autoload.php';
new BinBootstrap(Hub::class)->run();
```

```json
{
"bin": [
"bin/thing"
]
}
```

Define your task:

```php
namespace MyThing\Task;

use DecodeLabs\Clip\Task;

class MyTask implements Task
{
public function execute(): bool
{
// Do the thing
return true;
}
}
```

```bash
composer exec thing my-task

# or with effigy
effigy thing my-task
```

### Extending

Use the `MyThing` Controller Veneer frontage to run sub-tasks, and build on it to create your library's ecosystem with an easily accessed root.

See [Effigy](https://github.com/decodelabs/genesis) and [Zest](https://github.com/decodelabs/zest) for examples.

## Licensing

Clip is licensed under the MIT License. See [LICENSE](./LICENSE) for the full license text.