Download the PHP package swew/cli without Composer
On this page you can find all versions of the php package swew/cli. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package cli
Short Description SWEW/CLI: A PHP package for streamlined command line interface (CLI) development, providing an intuitive API for creating custom commands, handling input/output, and executing command logic effortlessly. Simplify your CLI application development with rapid development.
License MIT
Informations about the package cli
SWEW/CLI
The package is a PHP library for building console applications and commands in an object-oriented manner. It provides a simple and intuitive API for defining commands and handling arguments and options. It also includes utilities for interacting with the console, such as coloring output and prompting for user input. With this package, you can quickly create powerful command-line tools and automate repetitive tasks in your development workflow.
Packages developed by SWEW
- swew/cli - A command-line interface program with formatting and text entry functions.
- swew/test - A test framework that is designed to fix the fatal flaw of other test frameworks.
- swew/db - A lightweight, fast, and secure PHP library for interacting with databases, creating migrations, and running queries.
- swew/dd - The simplest way to debug variables. As in Laravel.
Install
Example of use
Create command
Create cli-program
Run cli-program
API / DOC
Console — User Commands
An example of creating a command with SWEW-CLI.
The command must be inherited from the Swew\Cli\Command
class and the class must be callable via the __invoke
method.
The class must also have two obligatory constants.
NAME
- necessary to call the command, it can also contain arguments.- The
DESCRIPTION
is a description of the command and is used to call thehelp
message.
As a result of the execution of the command should return the result - the status code. If all was successful, it is 0
.
By inheriting from the class Command
- we also get auxiliary methods defined in it.
init(): void
- will be run before execution (can be overridden)arg(string $key):
CommandArgument` - getting the argument passed to the commandargv(string $key): mixed
- get valuegetHelpMessage(): string
- get help message for the command (can be overridden)isValid(): bool
- check if all required arguments are passed to the command correctlygetErrorMessage():string
- Get an error messagecall(string $command, ?array $args:) int
- call another command
Working with command parameters, description of arguments
Writing Output
write / writeLn / info / warn / error
Width / Height
Formatting
Symbols
</>
- escape<br>
- new line<b>
- bold<u>
- underline
Colors
Color | Background Color |
---|---|
<black> |
<bgBlack> |
<gray> |
<bgGray> |
<white> |
<bgWhite> |
<red> |
<bgRed> |
<green> |
<bgGreen> |
<yellow> |
<bgYellow> |
<blue> |
<bgBlue> |
<purple> |
<bgPurple> |
<cyan> |
<bgCyan> |
Cursors
<saveCursor>
<restoreCursor>
<eraseToEndLine>
<eraseToStartLine>
<eraseLine>
<eraseToBottom>
<eraseToTop>
Without formatting
If you do not want to use formatting, specify this
Clear bash colors
Remove bash color symbols from string
Empty lines
Link
Prompting For Input
ask
askYesNo
secret
Choice Question
Choice Multiple
Tables
Progress bar
Output
If you only need output to the console, you can use the Output
class separately.