2022-02-23 15:58:18 +00:00
< ? php declare ( strict_types = 1 );
2016-04-22 20:54:04 +00:00
/*
* This file is part of Composer .
*
* ( c ) Nils Adermann < naderman @ naderman . de >
* Jordi Boggiano < j . boggiano @ seld . be >
*
* 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 ;
2022-04-14 20:24:33 +00:00
use Composer\Console\Input\InputArgument ;
2016-04-26 19:10:56 +00:00
use Symfony\Component\Console\Input\ArrayInput ;
2022-04-14 20:24:33 +00:00
use Composer\Console\Input\InputOption ;
2016-04-22 20:54:04 +00:00
use Symfony\Component\Console\Output\OutputInterface ;
/**
* @ author Jordi Boggiano < j . boggiano @ seld . be >
*/
2022-02-16 12:24:57 +00:00
class OutdatedCommand extends BaseCommand
2016-04-22 20:54:04 +00:00
{
2022-04-14 20:24:33 +00:00
use CompletionTrait ;
2021-11-30 00:03:23 +00:00
2022-02-18 09:38:54 +00:00
protected function configure () : void
2016-04-22 20:54:04 +00:00
{
$this
-> setName ( 'outdated' )
2022-08-16 08:28:59 +00:00
-> setDescription ( 'Shows a list of installed packages that have updates available, including their latest version' )
2022-08-17 12:20:07 +00:00
-> setDefinition ([
2022-07-21 14:30:01 +00:00
new InputArgument ( 'package' , InputArgument :: OPTIONAL , 'Package to inspect. Or a name including a wildcard (*) to filter lists of packages instead.' , null , $this -> suggestInstalledPackage ( false )),
2016-04-28 18:48:56 +00:00
new InputOption ( 'outdated' , 'o' , InputOption :: VALUE_NONE , 'Show only packages that are outdated (this is the default, but present here for compat with `show`' ),
new InputOption ( 'all' , 'a' , InputOption :: VALUE_NONE , 'Show all installed packages with their latest versions' ),
2020-10-26 13:47:31 +00:00
new InputOption ( 'locked' , null , InputOption :: VALUE_NONE , 'Shows updates for packages from the lock file, regardless of what is currently in vendor dir' ),
2016-04-24 14:17:08 +00:00
new InputOption ( 'direct' , 'D' , InputOption :: VALUE_NONE , 'Shows only packages that are directly required by the root package' ),
2016-11-28 10:54:35 +00:00
new InputOption ( 'strict' , null , InputOption :: VALUE_NONE , 'Return a non-zero exit code when there are outdated packages' ),
2022-06-09 09:45:32 +00:00
new InputOption ( 'major-only' , 'M' , InputOption :: VALUE_NONE , 'Show only packages that have major SemVer-compatible updates.' ),
new InputOption ( 'minor-only' , 'm' , InputOption :: VALUE_NONE , 'Show only packages that have minor SemVer-compatible updates.' ),
new InputOption ( 'patch-only' , 'p' , InputOption :: VALUE_NONE , 'Show only packages that have patch SemVer-compatible updates.' ),
2023-12-20 14:37:27 +00:00
new InputOption ( 'sort-by-age' , 'A' , InputOption :: VALUE_NONE , 'Displays the installed version\'s age, and sorts packages oldest first.' ),
2022-05-13 12:09:09 +00:00
new InputOption ( 'format' , 'f' , InputOption :: VALUE_REQUIRED , 'Format of the output: text or json' , 'text' , [ 'json' , 'text' ]),
2022-07-21 14:30:01 +00:00
new InputOption ( 'ignore' , null , InputOption :: VALUE_REQUIRED | InputOption :: VALUE_IS_ARRAY , 'Ignore specified package(s). Use it if you don\'t want to be informed about new versions of some packages.' , null , $this -> suggestInstalledPackage ( false )),
2020-06-05 14:48:10 +00:00
new InputOption ( 'no-dev' , null , InputOption :: VALUE_NONE , 'Disables search in require-dev packages.' ),
2021-11-23 16:16:58 +00:00
new InputOption ( 'ignore-platform-req' , null , InputOption :: VALUE_REQUIRED | InputOption :: VALUE_IS_ARRAY , 'Ignore a specific platform requirement (php & ext- packages). Use with the --outdated option' ),
new InputOption ( 'ignore-platform-reqs' , null , InputOption :: VALUE_NONE , 'Ignore all platform requirements (php & ext- packages). Use with the --outdated option' ),
2022-08-17 12:20:07 +00:00
])
2018-07-24 12:32:52 +00:00
-> setHelp (
<<< EOT
2016-04-22 20:54:04 +00:00
The outdated command is just a proxy for `composer show -l`
2017-01-22 18:59:50 +00:00
The color coding ( or signage if you have ANSI colors disabled ) for dependency versions is as such :
2016-04-22 20:54:04 +00:00
2017-01-22 18:59:50 +00:00
- < info > green </ info > ( = ) : Dependency is in the latest version and is up to date .
- < comment > yellow </ comment > ( ~ ) : Dependency has a new version available that includes backwards
2016-04-22 20:54:04 +00:00
compatibility breaks according to semver , so upgrade when you can but it
may involve work .
2017-01-22 18:59:50 +00:00
- < highlight > red </ highlight > ( ! ) : Dependency has a new version that is semver - compatible and you should upgrade it .
2016-04-22 20:54:04 +00:00
2019-03-04 11:55:38 +00:00
Read more at https :// getcomposer . org / doc / 03 - cli . md #outdated
2016-04-22 20:54:04 +00:00
EOT
)
;
}
2022-02-16 12:24:57 +00:00
protected function execute ( InputInterface $input , OutputInterface $output ) : int
2016-04-22 20:54:04 +00:00
{
2022-08-17 12:20:07 +00:00
$args = [
2019-10-21 10:50:14 +00:00
'command' => 'show' ,
2016-04-26 19:10:56 +00:00
'--latest' => true ,
2022-08-17 12:20:07 +00:00
];
2016-04-28 18:48:56 +00:00
if ( ! $input -> getOption ( 'all' )) {
2016-04-26 19:10:56 +00:00
$args [ '--outdated' ] = true ;
}
if ( $input -> getOption ( 'direct' )) {
$args [ '--direct' ] = true ;
}
2022-02-16 12:24:57 +00:00
if ( null !== $input -> getArgument ( 'package' )) {
2016-04-26 19:10:56 +00:00
$args [ 'package' ] = $input -> getArgument ( 'package' );
}
2016-11-28 10:54:35 +00:00
if ( $input -> getOption ( 'strict' )) {
$args [ '--strict' ] = true ;
}
2022-06-09 09:45:32 +00:00
if ( $input -> getOption ( 'major-only' )) {
$args [ '--major-only' ] = true ;
}
2016-12-28 17:44:32 +00:00
if ( $input -> getOption ( 'minor-only' )) {
$args [ '--minor-only' ] = true ;
}
2022-03-15 14:52:04 +00:00
if ( $input -> getOption ( 'patch-only' )) {
$args [ '--patch-only' ] = true ;
}
2020-10-26 13:47:31 +00:00
if ( $input -> getOption ( 'locked' )) {
$args [ '--locked' ] = true ;
}
2020-06-05 14:48:10 +00:00
if ( $input -> getOption ( 'no-dev' )) {
$args [ '--no-dev' ] = true ;
}
2023-12-20 14:37:27 +00:00
if ( $input -> getOption ( 'sort-by-age' )) {
$args [ '--sort-by-age' ] = true ;
}
2022-02-16 12:24:57 +00:00
$args [ '--ignore-platform-req' ] = $input -> getOption ( 'ignore-platform-req' );
2021-11-23 16:16:58 +00:00
if ( $input -> getOption ( 'ignore-platform-reqs' )) {
$args [ '--ignore-platform-reqs' ] = true ;
}
2017-03-07 13:19:51 +00:00
$args [ '--format' ] = $input -> getOption ( 'format' );
2018-10-31 16:18:54 +00:00
$args [ '--ignore' ] = $input -> getOption ( 'ignore' );
2016-04-26 19:10:56 +00:00
$input = new ArrayInput ( $args );
2016-04-22 20:54:04 +00:00
return $this -> getApplication () -> run ( $input , $output );
}
2016-05-03 06:26:14 +00:00
/**
2021-10-27 13:47:42 +00:00
* @ inheritDoc
2016-05-03 06:26:14 +00:00
*/
2022-02-18 13:32:38 +00:00
public function isProxyCommand () : bool
2016-05-03 06:26:14 +00:00
{
return true ;
}
2016-04-22 20:54:04 +00:00
}