some minor refactorings
parent
9a87aa1aaf
commit
25d062ccb4
|
@ -29,8 +29,9 @@ use Symfony\Component\Process\Exception\InvalidArgumentException;
|
||||||
*/
|
*/
|
||||||
class HomeCommand extends Command
|
class HomeCommand extends Command
|
||||||
{
|
{
|
||||||
protected $versionParser;
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
protected function configure()
|
protected function configure()
|
||||||
{
|
{
|
||||||
$this
|
$this
|
||||||
|
@ -45,18 +46,20 @@ EOT
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
$repo = $this->initializeRepo($input, $output);
|
$repo = $this->initializeRepo($input, $output);
|
||||||
$package = $this->getPackage($repo, $input->getArgument('package'));
|
$package = $this->getPackage($repo, $input->getArgument('package'));
|
||||||
|
|
||||||
/** @var CompletePackageInterface $package */
|
if (!$package instanceof CompletePackageInterface) {
|
||||||
if ($package instanceof CompletePackageInterface && filter_var($package->getSourceUrl(), FILTER_VALIDATE_URL)) {
|
|
||||||
$this->openBrowser($package->getSourceUrl());
|
|
||||||
} elseif ($package instanceof CompletePackageInterface) {
|
|
||||||
$this->getIO()->write('no valid source-url given for ' . $package->getName());
|
|
||||||
} else {
|
|
||||||
throw new InvalidArgumentException('package not found');
|
throw new InvalidArgumentException('package not found');
|
||||||
|
} elseif (filter_var($package->getSourceUrl(), FILTER_VALIDATE_URL)) {
|
||||||
|
$this->openBrowser($package->getSourceUrl());
|
||||||
|
} else {
|
||||||
|
$output->writeln('no valid source-url given for ' . $package->getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,18 +95,19 @@ EOT
|
||||||
*/
|
*/
|
||||||
private function openBrowser($url)
|
private function openBrowser($url)
|
||||||
{
|
{
|
||||||
|
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
|
||||||
|
return passthru('start "web" explorer "' . $url . '"');
|
||||||
|
}
|
||||||
|
|
||||||
passthru('which xdg-open', $linux);
|
passthru('which xdg-open', $linux);
|
||||||
passthru('which open', $osx);
|
passthru('which open', $osx);
|
||||||
$windows = defined('PHP_WINDOWS_VERSION_MAJOR');
|
|
||||||
|
|
||||||
if (0 === $linux) {
|
if (0 === $linux) {
|
||||||
passthru('xdg-open ' . $url);
|
passthru('xdg-open ' . $url);
|
||||||
} elseif (0 === $osx) {
|
} elseif (0 === $osx) {
|
||||||
passthru('open ' . $url);
|
passthru('open ' . $url);
|
||||||
} elseif (true === $windows) {
|
|
||||||
passthru('start "web" explorer "' . $url . '"');
|
|
||||||
} else {
|
} else {
|
||||||
$this->getIO()->write('no suitable browser opening tool found, open yourself: ' . $url);
|
$this->getIO()->write('no suitable browser opening command found, open yourself: ' . $url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue