PHPackages                             pmjones/auto-shell - 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. pmjones/auto-shell

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

pmjones/auto-shell
==================

Automatically parses command-line strings to command classes.

1.0.3(2mo ago)511.4k↑25%23MITPHPPHP &gt;=8.1CI passing

Since Jan 19Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/pmjones/AutoShell)[ Packagist](https://packagist.org/packages/pmjones/auto-shell)[ RSS](/packages/pmjones-auto-shell/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (5)Dependencies (10)Versions (6)Used By (3)

AutoShell
=========

[](#autoshell)

[![PDS Skeleton](https://camo.githubusercontent.com/50d01a5094afcc3a827c3cadaec43d23b2a256cb249f5fdd6e5ffdb53ea7971c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7064732d736b656c65746f6e2d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/php-pds/skeleton)[![PDS Composer Script Names](https://camo.githubusercontent.com/0c17df07fd0a51ad878f1de0d4c17ea8e460f2e96ce796c8cd58e6c96ed9c08d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7064732d636f6d706f7365722d2d7363726970742d2d6e616d65732d626c75653f7374796c653d666c61742d737175617265)](https://github.com/php-pds/composer-script-names)

*AutoShell* automatically maps CLI command names to PHP command classes in a specified namespace, reflecting on a specified main method within that class to determine the argument and option values. The method parameters may be scalar values(int, float, string, bool) or arrays.

*AutoShell* has no dependencies and is low-maintenance. Merely adding a class to your source code, in the recognized namespace and with the recognized main method name, automatically makes it available as a command.

Think of *AutoShell* as the "router" for your CLI command classes:

- Under ADR or MVC, you have a Front Controller pass the URL to a Router, and get back a Route object describing which Action/Controller to invoke (with the arguments thereto). The Front Controller would then invoke the Action/Controller with those arguments.
- Here, you have a Console class pass `$_SERVER['argv']` to a Shell, and get back an Exec object describing which Command class to invoke (with the options and arguments thereto). The Console would then invoke the Command with those options and arguments.

That is:

```
Front Controller    => Console
Router              => Shell
Route               => Exec
Action/Controller   => Command

```

Getting Started
---------------

[](#getting-started)

> Note:
>
> The documentation examples follow the [pds/skeleton](https://github.com/php-pds/skeleton) standard for directory and file names.

### Installation

[](#installation)

Install *AutoShell* using Composer:

```
composer require pmjones/auto-shell

```

### Console Script

[](#console-script)

You will need a console script to run your commands. To create a console script, open a file in your project at `bin/console.php` and add the following code:

```
