Download the PHP package neuron-php/cli without Composer
On this page you can find all versions of the php package neuron-php/cli. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download neuron-php/cli
More information about neuron-php/cli
Files in neuron-php/cli
Package cli
Short Description Unified command-line interface for the Neuron PHP framework
License MIT
Informations about the package cli
Neuron CLI Component
A unified command-line interface for the Neuron PHP framework that provides a modern, extensible CLI tool for all Neuron components.
Features
- Unified CLI Interface - Single entry point for all component commands
- Automatic Command Discovery - Auto-detects commands from installed components
- Rich Terminal Output - Colored output, tables, and progress bars
- Zero Configuration - Works out of the box with any Neuron component
- Extensible Architecture - Easy to add custom commands
Requirements
- PHP 8.4 or higher
- Composer
Installation
Local Installation (Recommended)
After installation, the CLI will be available at:
Global Installation
Make sure your global Composer bin directory is in your PATH, then:
Basic Usage
List All Commands
Get Help
Config Export
Export a YAML config as environment-style pairs for production.
Notes:
- Keys become UPPER_SNAKE_CASE using
CATEGORY_NAMEfrom YAML. - Nested and array values are flattened (e.g.,
ARRAY_KEY_0,ARRAY_KEY_1). - Booleans and nulls are stringified appropriately for env files.
For Component Developers
The CLI component provides two ways for your component to register commands:
Method 1: CLI Provider Class (Recommended)
This is the preferred method as it keeps all command registrations in one place.
-
Update your component's
composer.json: - Create the provider class:
Method 2: Direct Registration
For simpler cases, you can register commands directly in composer.json:
Creating Command Classes
All commands must extend the base Command class:
Command Naming Conventions
- Use namespace format:
component:action(e.g.,mvc:controller,cms:init) - Use kebab-case for multi-word actions:
make:controller,cache:clear - Group related commands under the same namespace
- Keep names short but descriptive
Built-in Commands
Core Commands
| Command | Description | Usage |
|---|---|---|
help |
Display help for a command | neuron help [command] |
list |
List all available commands | neuron list |
version |
Show version information | neuron version [--verbose] |
config:env |
Export neuron.yaml as KEY=VALUE pairs | neuron config:env [--config=...] [--category=...] [--format=dotenv|shell] [--quote=...] |
Output Helpers
The Output class provides rich formatting options:
Basic Output
Tables
Progress Bars
Interactive Input
The CLI component provides full support for interactive user input in commands:
Interactive Input Methods
| Method | Description | Example |
|---|---|---|
isInteractive() |
Check if terminal supports interaction | if ($this->input->isInteractive()) |
ask($question, $default) |
Ask for text input | $name = $this->input->ask('Name?', 'John') |
confirm($question, $default) |
Ask yes/no question | if ($this->input->confirm('Continue?', true)) |
askSecret($question) |
Ask for hidden input (passwords) | $pass = $this->input->askSecret('Password') |
choice($question, $choices, $default, $multiple) |
Select from options | $opt = $this->input->choice('Pick:', ['A', 'B']) |
readLine($prompt) |
Read raw input line | $line = $this->input->readLine('> ') |
Example: Interactive Setup Command
Secret Input (Passwords)
The askSecret() method hides user input, perfect for passwords and sensitive data:
Choice Selection
The choice() method presents options for selection:
How Command Discovery Works
- Installation Detection: When
neuronis run, the ComponentLoader scans for installed packages - Package Filtering: Only
neuron-php/*packages are considered - Configuration Check: Each package's
composer.jsonis checked for CLI configuration - Provider Loading: If a CLI provider is found, its
register()method is called - Direct Registration: Any directly listed commands are registered
- Project Commands: The root project's
composer.jsonis also checked
This automatic discovery means:
- No manual registration needed
- Commands available immediately after component installation
- Clean separation between components
- No conflicts between component commands
Error Handling
Commands should return appropriate exit codes:
0- Success1- General error2- Misuse of command126- Command cannot execute127- Command not found
Example:
Testing Your Commands
The CLI component provides comprehensive testing support, including the ability to test commands that require user input.
Testing Commands Without User Input
Testing Commands With User Input
Commands that use prompt(), confirm(), secret(), or choice() can be tested using the TestInputReader:
Using Input Reader in Commands
To make your commands testable, use the convenience methods provided by the Command base class:
These convenience methods automatically use the injected IInputReader, making your commands fully testable without requiring actual user input.
TestInputReader Features
The TestInputReader class provides:
- Response Queue: Pre-program multiple responses with
addResponse()oraddResponses() - Prompt History: Track all prompts shown with
getPromptHistory() - Automatic Validation: Throws exceptions if responses run out, helping catch test bugs
- Fluent Interface: Chain
addResponse()calls for cleaner test setup - Full Interface Support: Implements all
IInputReadermethods (prompt, confirm, secret, choice)
Contributing
When adding new features to the CLI component:
- Extend the
Commandbase class for new commands - Add tests in the
tests/directory - Update this README with new features
- Follow PSR-4 naming conventions
- Use the existing code style (tabs, spaces etc)
License
This component is part of the Neuron PHP Framework and is released under the MIT License.
All versions of cli with dependencies
neuron-php/application Version 0.8.*
neuron-php/data Version 0.9.*
symfony/yaml Version ^6.4