PHPackages                             vanilla/garden-cli - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. vanilla/garden-cli

ActiveLibrary[CLI &amp; Console](/categories/cli)

vanilla/garden-cli
==================

A full-featured, yet ridiculously simple commandline parser for your next php cli script. Stop fighting with getopt().

v4.0(3y ago)1171.2M↓18.9%16[4 issues](https://github.com/vanilla/garden-cli/issues)[6 PRs](https://github.com/vanilla/garden-cli/pulls)20MITPHPPHP &gt;=8.1

Since Jun 21Pushed 3y ago16 watchersCompare

[ Source](https://github.com/vanilla/garden-cli)[ Packagist](https://packagist.org/packages/vanilla/garden-cli)[ RSS](/packages/vanilla-garden-cli/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (37)Used By (20)

Garden CLI
==========

[](#garden-cli)

[![Build Status](https://camo.githubusercontent.com/45f5496f0f9dda6e50a47d4ab357df4d6a78cf666feb970e9dc04145ac6f582c/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f76616e696c6c612f67617264656e2d636c692e7376673f7374796c653d666c6174)](https://travis-ci.org/vanilla/garden-cli)[![Packagist Version](https://camo.githubusercontent.com/1e8a9a315df03940f2df164a15da1e5a9c697637af5fa9b8e6ce2686103f118c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f76616e696c6c612f67617264656e2d636c692e7376673f7374796c653d666c6174)](https://packagist.org/packages/vanilla/garden-cli)[![MIT License](https://camo.githubusercontent.com/b56a1c7728b1d942cc8409e14b118a9e3df45d8e47162ee3e455009620d66a0f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f76616e696c6c612f67617264656e2d636c692e7376673f7374796c653d666c6174)](https://camo.githubusercontent.com/b56a1c7728b1d942cc8409e14b118a9e3df45d8e47162ee3e455009620d66a0f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f76616e696c6c612f67617264656e2d636c692e7376673f7374796c653d666c6174)[![CLA](https://camo.githubusercontent.com/b12a1c60d68c7cf8618f1c7ac25e2ee3482e52afa91da59b0491bc9dcdad7b0a/68747470733a2f2f636c612d617373697374616e742e696f2f726561646d652f62616467652f76616e696c6c612f67617264656e2d636c69)](https://cla-assistant.io/vanilla/garden-cli)

- [Introduction](#introduction)
- [Defining The CLI](#defining-the-cli)
- [The CliApplication Class](#the-cliapplication-class)
- [Logging](#logging)

Introduction
------------

[](#introduction)

Garden CLI is a PHP command line interface library meant to provide a full set of functionality with a clean and simple api.

### Why use Garden CLI?

[](#why-use-garden-cli)

PHP's `getopt()` provides little functionality and is prone to failure where one typo in your command line options can wreck and entire command call. Garden CLI solves this problem and provides additional functionality.

- Your commands get automatic support for `--help` to print out help for your commands.
- Support a single command or multiple commands. (ex. git pull, git push, etc.)
- Have command options parsed and validated with error information automatically printed out.
- A simple, elegant syntax so that even your most basic command line scripts will take little effort to implement robust parsing.

### Installation

[](#installation)

*Garden CLI requires PHP 8.1 or higher*

Garden CLI is [PSR-4](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md) compliant and can be installed using [composer](//getcomposer.org). Just add `vanilla/garden-cli` to your composer.json.

```
"require": {
    "vanilla/garden-cli": "~4.0"
}
```

Defining The CLI
----------------

[](#defining-the-cli)

The `Cli` class provides a fluent interface for defining commands, opts, and args.

### Basic Example

[](#basic-example)

Here is a basic example of a command line script that uses Garden CLI to parse its options. Let's say you are writing a script called `dbdump.php` to dump some data from your database.

```
