* Jordi Boggiano * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Composer\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Composer\Downloader\VcsDownloader; /** * @author Tiago Ribeiro * @author Rui Marinho */ class StatusCommand extends Command { protected function configure() { $this ->setName('status') ->setDescription('Show a list of locally modified packages') ->setDefinition(array( new InputOption('verbose', 'v|vv|vvv', InputOption::VALUE_NONE, 'Show modified files for each directory that contains changes.'), )) ->setHelp(<<getComposer(); $installedRepo = $composer->getRepositoryManager()->getLocalRepository(); $dm = $composer->getDownloadManager(); $im = $composer->getInstallationManager(); $errors = array(); // list packages foreach ($installedRepo->getPackages() as $package) { $downloader = $dm->getDownloaderForInstalledPackage($package); if ($downloader instanceof VcsDownloader) { $targetDir = $im->getInstallPath($package); if ($changes = $downloader->getLocalChanges($targetDir)) { $errors[$targetDir] = $changes; } } } // output errors/warnings if (!$errors) { $output->writeln('No local changes'); } else { $output->writeln('You have changes in the following dependencies:'); } foreach ($errors as $path => $changes) { if ($input->getOption('verbose')) { $indentedChanges = implode("\n", array_map(function ($line) { return ' ' . $line; }, explode("\n", $changes))); $output->writeln(''.$path.':'); $output->writeln($indentedChanges); } else { $output->writeln($path); } } if ($errors && !$input->getOption('verbose')) { $output->writeln('Use --verbose (-v) to see modified files'); } return $errors ? 1 : 0; } }