简体   繁体   中英

distributing a php command line tool

I have a php command line tool that I would like to share with the world. Well, actually I plan to write it, and it is a tool for loading design documents into couchdb, but that's not really the point.

Anyway, is there a best practice for packaging php scripts so that they can be distributed for easy installation? I'm thinking something along the lines of the good old "./configure & make & make install", but what to do for a php script? I have read about phar, but it seems that it is intended mainly for libraries. So any ideas? Or examples of how other projects have done this?

Composer is a good example of how to package up the tool, both as a stand-alone set of source code, and code that can be run. I installed it as a phar and now can just run it anywhere as ' composer --options args '

There's composer or the good old PEAR that's still widely used, especially for CLI tools. To create your own PEAR channel, Pirum by SensioLabs (the Symfony guys) comes in handy.

For further reading, Stuart Herbert has a great series on component based development .

Check out CLIFramework it handles subcommands, argument validation, option values (multiple, flag, optional, default) and a powerful zsh/bash completion generator.

A compile command is also out-of-box to help you compile your console application into a phar file for distributing. (phpbrew uses this way to distribute the application to the world)

Here is a screencast of using zsh completion generator (it completes arguments and options):

zsh完成生成器

There are also many popular applications using CLIFramework and GetOptionKit. eg, PHPBrew , LazyRecord

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM