Last active
June 17, 2017 00:33
-
-
Save alnutile/69a54b65176e13f7063dd66470e984c9 to your computer and use it in GitHub Desktop.
Code for Medium post on CLI Skel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
use Symfony\Component\Console\Output\OutputInterface; | |
use Symfony\Component\Process\Exception\ProcessFailedException; | |
use Symfony\Component\Process\Process; | |
require __DIR__.'/bootstrap/autoload.php'; | |
$app = require_once __DIR__.'/bootstrap/app.php'; | |
$app->command('hello [--name=] message', function ( | |
OutputInterface $output, | |
\Alnutile\Example\SkeletonClass $skel, | |
$name, $message) use ($app) { | |
$output->writeln("\nRunning your command\n"); | |
try { | |
$message = $skel->echoPhrase($name, $message); | |
$output->writeln($message); | |
$output->writeln("<info>$name</info>"); | |
$output->writeln("<error>$name</error>"); | |
$output->writeln("<question>$name</question>\n"); | |
} catch (\Exception $e) { | |
$output->writeln(sprintf( | |
"<error>Error</error>\n MESSAGE: %s\n", | |
$e->getMessage() | |
)); | |
} | |
})->defaults([ | |
'name' => "World" | |
])->descriptions("Hello NAME and a message", | |
[ | |
'--name' => "Who is the message to", | |
"message" => "What do you want to say?" | |
] | |
); | |
$app->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment