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

https://github.com/nixphp/cli

NixPHP CLI Plugin for console aimed applications
https://github.com/nixphp/cli

Last synced: 3 months ago
JSON representation

NixPHP CLI Plugin for console aimed applications

Awesome Lists containing this project

README

          

![Logo](https://nixphp.github.io/docs/assets/nixphp-logo-small-square.png)

[![NixPHP CLI Plugin](https://github.com/nixphp/cli/actions/workflows/php.yml/badge.svg)](https://github.com/nixphp/cli/actions/workflows/php.yml)

[โ† Back to NixPHP](https://github.com/nixphp/framework)

---

# nixphp/cli

> **A minimal, developer-friendly command-line interface for your NixPHP application.**

This plugin gives you a clean CLI system with colored output, argument parsing, and auto-discovered commands. All without external dependencies.

> ๐Ÿงฉ Part of the official NixPHP plugin collection. Install it if you want powerful CLI tools for development, deployment, and automation.

---

## ๐Ÿ“ฆ Features

- โœ… Adds `vendor/bin/nix` as your appโ€™s command-line entry point
- โœ… Auto-discovers commands in `app/Commands/`
- โœ… Supports arguments, options, and interactive input
- โœ… Prints colored output for better UX
- โœ… Fully extensible โ€“ build your own tools and workflows

---

## ๐Ÿ“ฅ Installation

```bash
composer require nixphp/cli
```

This will create `vendor/bin/nix`, your CLI gateway.

---

## ๐Ÿš€ Usage

### ๐Ÿ” Run a command

```bash
vendor/bin/nix your:command
```

Commands are discovered automatically if placed in your appโ€™s `app/Commands/` directory.

```bash
vendor/bin/nix
```

If you call the helper without arguments, it prints all available CLI commands.

---

### ๐Ÿ› ๏ธ Create a custom command

To create your own CLI command, add a class in the `app/Commands/` folder:

```php
namespace App\Commands;

use NixPHP\CLI\Core\AbstractCommand;
use NixPHP\CLI\Core\Input;
use NixPHP\CLI\Core\Output;

class HelloCommand extends AbstractCommand
{
public const NAME = 'hello:say';

protected function configure(): void
{
$this->setTitle('Say Hello');
$this->addArgument('name');
}

public function run(Input $input, Output $output): int
{
$name = $input->getArgument('name');
$output->writeLine("Hello, {$name}!", 'ok');
return static::SUCCESS;
}
}
```

No registration needed โ€” as long as the class resides in `app/Commands/`, it will be picked up automatically.

Then run:

```bash
vendor/bin/nix hello:say John
```

---

## ๐ŸŽจ Colored output

Use `$output->writeLine()` to print messages with color support:

| Type | Appearance |
| ------------ | ----------------------- |
| `'ok'` | โœ… Green |
| `'error'` | โŒ Red |
| `'warning'` | โš ๏ธ Yellow |
| `'title'` | ๐Ÿ’ก Light green on black |
| `'headline'` | ๐Ÿ“ข Light blue on black |

You can also draw horizontal lines:

```php
$output->drawStroke(30);
```

---

## ๐Ÿงช Interactive input

You can prompt the user:

```php
$name = $input->ask('What is your name?');
```

---

## ๐Ÿ“ File structure

A typical CLI setup might look like this:

```text
app/
โ””โ”€โ”€ Commands/
โ””โ”€โ”€ HelloCommand.php

vendor/
โ””โ”€โ”€ bin/
โ””โ”€โ”€ nix

bootstrap.php
```

---

## โœ… Requirements

* `nixphp/framework` >= 0.1.0
* PHP >= 8.3

---

## ๐Ÿ“„ License

MIT License.