Re: Command line PHP
| From: | Andy McKenzie | Date: | Fri, 07 Jan 2011 17:44:46 +0000 |
| Subject: | Re: Command line PHP | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-310557@lists.php.net to get a copy of this message | ||
On Fri, Jan 7, 2011 at 11:55 AM, larry@garfieldtech.com
<larry@garfieldtech.com> wrote:
> Hi folks. I have a project coming up that will involve writing a
> non-trivial command line PHP application. Most of it will be nice and
> abstracted and standalone and all of that jazz, but it will need to do
> command line interation. I'm not sure yet if it will be interactive or if I
> just need to parse lots of command line switches.
>
> Has anyone used a CLI-handling library they like? I recall briefly using
> the PEAR CLI library many many years ago and disliking it because it was
> only barely a step above the raw PHP-CLI SAPI, and still required lots of
> if-else branching in my code. I don't know if there's anything better since
> then, however. I prefer clean OO to procedural, but can work with
> procedural if needs be. The fewer dependencies it has the better as well.
>
> Any recommendations?
>
> (Open source, GPLv2-compatible required.)
>
> --Larry Garfield
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
If all you want is a way to handle command line arguments, I built a
library to do that a few years ago. I got sick of needing to switch
languages to write a quick command-line script, and I hated the PEAR
CLI tools. I haven't really looked at it since, and since it was just
about the first thing I wrote that was object oriented I suspect it's
got some problems, but you're welcome to give it a try.
http://people.chem.umass.edu/amckenzie/code/php/php_cli_io/
It handles flags both with and without short forms, and flags with
either zero, one or two arguments. The demo file in the package has
the docs written into it -- read through it to see how the library
works.
If anyone tries it, let me know what you think, and what I've done
wrong. It does everything I need, but I don't think anyone else has
ever used it.
-Alex