-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Symfony console has a lot of nice things -- like color-coding outputs, prompting for inputs, and generating more detailed help screens for subcommands. The CLI parsing is ideal for use with shebangs, so we have to do some acrobatics to make it fit.
- Loading branch information
Showing
10 changed files
with
233 additions
and
110 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
namespace Pogo; | ||
|
||
use Pogo\Command\DownloadCommand; | ||
use Pogo\Command\HelpCommand; | ||
use Pogo\Command\ParseCommand; | ||
use Pogo\Command\RunCommand; | ||
use Pogo\Command\UpdateCommand; | ||
use Symfony\Component\Console\Input\ArgvInput; | ||
|
||
class Application extends \Symfony\Component\Console\Application { | ||
|
||
/** | ||
* Primary entry point for execution of the standalone command. | ||
* | ||
* @param array $args | ||
*/ | ||
public static function main($args) { | ||
$version = '@package_version@'; | ||
|
||
// FIXME: this handles "-D=foo script.php" but not "-D foo script.php" | ||
$pogoInput = PogoInput::create($args); | ||
$input = new ArgvInput($pogoInput->encode()); | ||
|
||
$application = new Application('pogo', ($version{0} === '@') ? '(local version)' : $version); | ||
$application->setAutoExit(FALSE); | ||
$application->setCatchExceptions(TRUE); | ||
return $application->run($input); | ||
} | ||
|
||
/** | ||
* Gets the default commands that should always be available. | ||
* | ||
* @return \Symfony\Component\Console\Command\Command[] An array of default Command instances | ||
*/ | ||
protected function getDefaultCommands() { | ||
return [ | ||
new HelpCommand(), | ||
new ParseCommand(), | ||
new DownloadCommand(), | ||
new RunCommand(), | ||
new UpdateCommand(), | ||
]; | ||
} | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Pogo\Command; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
|
||
class BaseCommand extends Command { | ||
|
||
private $synopsis = []; | ||
|
||
/** | ||
* Returns the synopsis for the command. | ||
* | ||
* @param bool $short Whether to show the short version of the synopsis (with options folded) or not | ||
* | ||
* @return string The synopsis | ||
*/ | ||
public function getSynopsis($short = FALSE) { | ||
$key = $short ? 'short' : 'long'; | ||
|
||
if (!isset($this->synopsis[$key])) { | ||
global $argv; | ||
$prog = basename($argv[0]); | ||
$this->synopsis[$key] = trim(sprintf('%s --%s %s', $prog, $this->getName(), $this->getDefinition()->getSynopsis($short))); | ||
} | ||
|
||
return $this->synopsis[$key]; | ||
} | ||
|
||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.