Skip to content

Instantly share code, notes, and snippets.

@alnutile
Last active June 17, 2017 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alnutile/69a54b65176e13f7063dd66470e984c9 to your computer and use it in GitHub Desktop.
Save alnutile/69a54b65176e13f7063dd66470e984c9 to your computer and use it in GitHub Desktop.
Code for Medium post on CLI Skel
#!/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