crodas / cli
Simple and silly abstraction on top of symfony/console
Installs: 6 963
Dependents: 9
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- crodas/class-info: >=0.2.3
- crodas/file-util: >=0.1
- crodas/notoj: >=1.6.0
- crodas/remember: >=0.4.2
- symfony/console: >=2.7
Requires (Dev)
- crodas/phpunit-compat: ^1.7
README
Simple and silly abstraction on top of symfony/console
How does it work?
The main goal is to give a generic and extensible way of registering console applications.
The application itself should like like this (cli.php
).
<?php require __DIR__ . '/vendor/autoload.php'; $cli = new crodas\cli\Cli("/tmp/some.cache.tmp"); // the vendors cli $cli->addDirectory(__DIR__ . '/vendor'); // add my APP directory $cli->addDirectory(__DIR__ . '/apps'); // run $cli->main();
Then inside apps/
we could have apps/cli/foobar.php
and it should look like this:
<?php namespace myApp\Cli; /** * @Cli("foobar", "some text to describe my app") * @Arg('name', OPTIONAL, 'add name') * @Option('foobar', VALUE_REQUIRED|VALUE_IS_ARRAY, 'add name') */ function foobar_main($input, $output) { $arg = $input->getArgument('name'); $opt = $input->getOption('foobar'); $output->writeLn(json_encode(compact('arg', 'opt'))); }
Now we can easily do php cli.php foobar
, foobar_main
function would be called.
Benefits
- Console applications are discovered
- No autoloader needed
- No conventions to follow
- It can use some cache function to avoid scanning lots of directories and files everytime.
- Annotations :-)
- Plugins support
@One
or@Crontab
make sure your command runs just once