diff --git a/doc/03-cli.md b/doc/03-cli.md index 7d557a8d3..7a897fd37 100644 --- a/doc/03-cli.md +++ b/doc/03-cli.md @@ -268,6 +268,16 @@ php composer.phar show monolog/monolog 1.0.2 * **--platform (-p):** List only platform packages (php & extensions). * **--self (-s):** List the root package info. +## browse / home + +The `browse` (aliased to `home`) opens a package's repository URL or homepage +in your browser. + +### Options + +* **--homepage (-H):** Open the homepage instead of the repository URL. + times. + ## depends The `depends` command tells you which other packages depend on a certain diff --git a/src/Composer/Command/HomeCommand.php b/src/Composer/Command/HomeCommand.php index 550f06308..1d3411a04 100644 --- a/src/Composer/Command/HomeCommand.php +++ b/src/Composer/Command/HomeCommand.php @@ -19,6 +19,7 @@ use Composer\Package\Loader\InvalidPackageException; use Composer\Repository\CompositeRepository; use Composer\Repository\RepositoryInterface; use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Process\Exception\InvalidArgumentException; @@ -36,12 +37,16 @@ class HomeCommand extends Command $this ->setName('browse') ->setAliases(array('home')) - ->setDescription('opens the package in your browser') + ->setDescription('Opens the package\'s repository URL or homepage in your browser.') ->setDefinition(array( - new InputArgument('package', InputArgument::REQUIRED, 'Package to goto'), + new InputArgument('package', InputArgument::REQUIRED, 'Package to browse to.'), + new InputOption('homepage', 'H', InputOption::VALUE_NONE, 'Open the homepage instead of the repository URL.'), )) ->setHelp(<<getPackage($repo, $input->getArgument('package')); if (!$package instanceof CompletePackageInterface) { - throw new InvalidArgumentException('package not found'); + throw new InvalidArgumentException('Package not found'); } - if (filter_var($package->getSourceUrl(), FILTER_VALIDATE_URL)) { - $support = $package->getSupport(); - $url = isset($support['source']) ? $support['source'] : $package->getSourceUrl(); - $this->openBrowser($url); - } else { - throw new InvalidPackageException(array($package->getName() => 'invalid source-url')); + + $support = $package->getSupport(); + $url = isset($support['source']) ? $support['source'] : $package->getSourceUrl(); + if (!$url || $input->getOption('home')) { + $url = $package->getHomepage(); } + + if (!filter_var($url, FILTER_VALIDATE_URL)) { + throw new InvalidPackageException(array($package->getName() => $input->getOption('home') ? 'Invalid or missing homepage' : 'Invalid or missing repository URL')); + } + + $this->openBrowser($url); } /**