I have a use case where we need to modify application flow if the application is being run from the command line via Artisan (migrations, seeds, route:list).
In Laravel
You can use the PHP function php_sapi_name
(http://php.net/manual/en/function.php-sapi-name.php), to found out if the script was launched from a command or not.
In your case, you should check something like
if (strpos(php_sapi_name(), 'cli') !== false) {
// Run from command
}
You may have to check the doc to find the proper value to check in each case though. (It may differ sometimes, but basically there should always be a different output from a script launched through a command)