alex-kalanis / kw_clipr
CLI Processor
Requires
- php: >=7.4.0
- ext-mbstring: *
- alex-kalanis/kw_input: >=3.0 <4
- alex-kalanis/kw_locks: >=3.0 <4
- alex-kalanis/kw_paths: >=4.0 <5
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/phpstan: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: >=8.0 <=9
- psr/container: =2.0.2
- shipmonk/composer-dependency-analyser: ^1.4
Suggests
- alex-kalanis/kw_locks: Locks in KWCMS
- psr/container: PSR-11 - DI support - API
README
CLI Processor
Basic framework for running your scripts from CLI in a bit prettier package. It calls task from predefined sources and allows them to run. Based on django cli and private CliC. You can use it as base for running your own scripts like regular checks or menial tasks. All that with simplified write to CLI output. All that with coloring and runable from web interface, *nix or Windows CLI. As extra you will get a table engine which creates output in markdown syntax.
Command line query is simple: clipr task --rest-of-params -t here
.
It uses kw_input for determination which params came. So with a bit of tinkering you can
also pass regular files to tasks for some processing.
The tasks returns Unix codes and Clipr pass them back to caller. See the IStatuses interface for their description.
PHP Installation
Direct usage
Install and set PHP on target machine. Then download this project and by following steps fill it by tasks suited for your needs.
1.) Download clipr somewhere / install via Composer
2a.) For *nix check if your base script with bootstrap can be executed
2b.) For Windows check if you have PHP installed and in %PATH%
3.) Run Clipr from /bin without parameters to test if it works; You must be inside the project dir.
4a.) Here you probably copy clipr initial file to somewhere for better access for users.
4b.) Then it's necessary to include your own autoloader in that file. Preset one probably will not work.
4c.) And you need to set correct paths to basic clipr tasks, mainly due different Composer paths.
5.) Call your clipr initial file and check if it works again. Try Listing for check tasks.
6.) Make another directory with your tasks and fill them with classes based on your use-case.
6.) Call them and check if everything runs
Composer
composer.phar require alex-kalanis/kw_clipr
(Refer to Composer Documentation if you are not familiar with composer)
PHP Usage
Each task is stored in preset directories in which it's possible to find them the fast way. The paths are set in initial file. And each task is subclass of kw_clipr\Tasks\ATask, which allows to write outputs and call params.
For running task simply call your/path/to/clipr task/name --task-params
For creating your tasks you must create some directory where they will be, create some tasks with correct namespacing and add that root namespace into Clipr init file to paths. If you use DI autoloading for your classes then you also need to specify that autoloader in Clipr init file - in example there is already a prepared commented-out place. I saw this with DI of DB or other services accessing classes.
Clipr tasks can be set into tree, so you can separate them by some of your logic. Not need to fill one directory with one huge list of tasks.
For beginning I advise to just copy one of tasks and play with it.
Changes
- v2 uses different way to initialize DI
- v3 uses changed locking mechanism for single-running tasks
- v4 returns status codes
- v5 uses arrays as path settings
Caveats
In default setup it contains subparts of kw_autoload and kw_inputs projects - both are necessary to run without other dependencies. If you install this via Composer you'll see kw_input twice and kw_autoload as extra weight. But that's okay. kw_autoload doesn't see composer files if they aren't in predefined paths where kw_autoload can look for them. For default run it isn't necessary to use the whole machine of Composer and it has been developed without it.
And at last - there is NO dependency injection support by default. You must set it by yourself. Because that usually means at least installing Composer and that's the thing I want to avoid. Usual DI libraries are very dependent on Composer. And the whole PSR has been made with Composer in mind. Also original project CliC had no DI support. Version 2 has better support for DI, but it is not running by default. And default tasks do not have it.