Part 13 of Magento Development Deep Dive traces how a bin/magento console command actually gets discovered and run -- from the real bin/magento entry script, through Cli::getApplicationCommands()'s fork between core and vendor commands, down to a real, complete, currently shipping command: cron:install.
Every code scene in this video is a verbatim excerpt from a real local git checkout of the public magento/magento2 repository, tag 2.4.9, commit 755e34dd689021c5165db9d35ecff74f7dc51527 -- file paths and line numbers cited on screen.
What you'll see traced, file and line:
bin/magento -- the real, complete CLI entry point (whole file)
Framework/Console/Cli.php -- getApplicationCommands() and getVendorCommands()
Framework/Console/CommandLocator.php -- the static registry vendor tools push into
Framework/Console/CommandListInterface.php and CommandList.php -- the real contract and default implementation
Cron/etc/di.xml -- how a real core module registers its own commands
Cron/Console/Command/CronInstallCommand.php -- configure() and execute(), a real shipped command end to end
== CHAPTERS ==
00:00 Cold open
00:39 Title
01:13 What you'll understand
01:54 From bin/magento to a running command
02:41 Prerequisites
03:16 Step 1 - bin/magento entry point
03:49 Step 2 - getApplicationCommands()
04:23 Step 3 - getVendorCommands()
04:53 Step 4 - CommandLocator
05:25 Step 5 - CommandListInterface and CommandList
05:56 Step 6 - real di.xml registration
06:31 Step 7 - configure()
07:07 Step 8 - execute()
07:37 Gotchas
08:26 Recap
09:11 Next part
This is part of an ongoing series walking through real, cited Magento 2 framework source code -- no paraphrased or invented examples.