Add browse command to docs, add a -H flag and tweak fallback mechanism to maximize chances of opening something, refs #2445
parent
e10bf5a172
commit
22afc074a9
|
@ -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
|
||||
|
|
|
@ -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(<<<EOT
|
||||
The home command opens the package in your preferred browser
|
||||
The home command opens a package's repository URL or
|
||||
homepage in your default browser.
|
||||
|
||||
To open the homepage by default, use -H or --homepage.
|
||||
EOT
|
||||
);
|
||||
}
|
||||
|
@ -55,15 +60,20 @@ EOT
|
|||
$package = $this->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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue