nixphp/cli

NixPHP CLI Plugin for console applications.

Maintainers

Details

github.com/nixphp/cli

Source

Issues

Installs: 32

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Type:nixphp-plugin

pkg:composer/nixphp/cli

v0.1.2 2025-12-08 21:21 UTC

This package is auto-updated.

Last update: 2025-12-08 21:37:24 UTC


README

Logo

NixPHP CLI Plugin

โ† Back to NixPHP

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

composer require nixphp/cli

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

๐Ÿš€ Usage

๐Ÿ” Run a command

vendor/bin/nix your:command

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

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:

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:

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:

$output->drawStroke(30);

๐Ÿงช Interactive input

You can prompt the user:

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

๐Ÿ“ File structure

A typical CLI setup might look like this:

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

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

bootstrap.php

โœ… Requirements

  • nixphp/framework >= 0.1.0
  • PHP >= 8.3

๐Ÿ“„ License

MIT License.