Re: Command line PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11-01-07 02:33 PM, Robert Cummings wrote:
On 11-01-07 11:55 AM, larry@xxxxxxxxxxxxxxxx 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.)

Hi Larry,

I wrote the following some time ago:

http://www.interjinn.com/jinnDoc/interJinn.class.JinnCoreServicesCliArguments.php

It is tied to my framework, but could easily be lifted and embedded in a
standalone class. License is GPL V2 so feel free to adapt as befits said
license.

I just realized it's one of my lazy classes and so it's not fully documented :) It would be as simple as (if converted to a standalone class):

<?php

    $args = new CliArgs();

    $param1 = $args->getArg( 'param1' );
    $param2 = $args->getArg( 'param2' );
    $files = $args->getSequence();

?>

For any of the following command-lines:

    ./myscript.php --param1=foo --param2=fee file1 file2 file3

    ./myscript.php --param1 foo --param2 fee file1 file2 file3

    ./myscript.php -param1=foo -param2=fee file1 file2 file3

    ./myscript.php -param1 foo -param2 fee file1 file2 file3

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux