Download the PHP package leafs/sprout without Composer
On this page you can find all versions of the php package leafs/sprout. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package sprout
Short Description Fast, lightweight and minimal CLI framework for PHP
License MIT
Homepage https://leafphp.dev
Informations about the package sprout
Leaf Sprout (WIP)
🌱 Fast, lightweight and minimal CLI framework for PHP. It provides a type-safe, feature-rich environment to build CLI apps of all sizes, plus a ton of helpers for building amazing experiences for users interacting with your CLI app.
- Not based on any Laravel or Symfony console components
- First-class support for Leaf & Leaf modules
- Comes with built in styling, input handling, output handling, and more
- Support for PHP 7.4 and above
- Easy to use, easy to extend
Installation
You can install Leaf Sprout using the Leaf CLI or Composer:
Usage
To get started, you need to create a file which will be the entry point for your CLI app. This file should be executable and should have a shebang at the top of the file. Here's an example of a simple CLI app:
You can then run your CLI app using the PHP CLI:
Writing Commands
You can write your commands in a functional way using the command() method on the app instance, or you can create a class that extends the Leaf\Sprout\Command class. Here's an example of a command written as a class:
You can then register this command with the app instance:
Styling Output
Leaf Sprout comes with a built-in output styling system that allows you to style your output using a simple API adapted from Symfony Console. Here's an example of how you can style your output:
Or you can use pre-configured styles like success(), error(), warning(), and info():
Later versions will include more advanced styling options modelled after TailwindCSS and TermWind.
Input Handling
Leaf Sprout comes with a built-in input handling system that allows you to easily get input from the user. The easiest way is to use the prompt() method:
You can also have multiple prompts in a single command for more complex interactions like setting up a project via your CLI:
When the user runs the command, they will be prompted for the project name, type, and whether they want to install dependencies. The results will be stored in the $results variable. The prompt type can be text, select, confirm, password, number, or text, when set to null, the prompt will be skipped.
Besides prompts, you can also use the arguments() and options() methods to get arguments and options passed to the command:
Output Handling
Process Handling
Sprout comes with a built-in process handling system that allows you to run processes on the system. You can use the process() method to run a process:
You can also use the run() method to run a process and log the output to the console in real-time, and then return it's exit code:
Composer & Npm Scripts
A lot of console applications allow you to install composer or npm dependencies, and sprout makes it a whole lot easier to do so:
For npm, you can also specify the package manager you want to use:
All the composer and npm commands log the output to the console in real-time. If you want to change the output, you can pass a callback as the second argument:
The also return a process instance which you can use to get the output, check if the process was successful, and get the exit code: