Fix disabling of built-in commands when using ./lnms (#12308)

* Fix disabling of built-in commands when using ./lnms in production

It wasn't working correctly after Laravel upstream changes

* Use nunomaduro/laravel-console-summary

* fix command name

Co-authored-by: Tony Murray <murraytony@gmail.com>
This commit is contained in:
Jellyfrog 2020-11-19 22:51:20 +01:00 committed by GitHub
parent aded238299
commit 820cf1dcca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 131 additions and 104 deletions

View File

@ -1,32 +0,0 @@
<?php
/**
* MigrateInstallCommand.php
*
* -Description-
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @link http://librenms.org
* @copyright 2019 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace App\Console;
use Illuminate\Database\Console\Migrations\InstallCommand;
class MigrateInstallCommand extends InstallCommand
{
protected $hidden = true;
}

View File

@ -1,41 +0,0 @@
<?php
/**
* ModelMakeCommand.php
*
* -Description-
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @link http://librenms.org
* @copyright 2019 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace App\Console;
use Illuminate\Foundation\Console\ModelMakeCommand as LaravelModelMakeCommand;
class ModelMakeCommand extends LaravelModelMakeCommand
{
/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace . '\Models';
}
}

View File

@ -2,40 +2,15 @@
namespace App\Providers;
use App\Console\MigrateInstallCommand;
use Illuminate\Foundation\Providers\ArtisanServiceProvider;
use Illuminate\Support\ServiceProvider;
class CliServiceProvider extends ArtisanServiceProvider
class CliServiceProvider extends ServiceProvider
{
public function register()
{
// Restrict LibreNMS CLI commands
if (defined('LIBRENMS_CLI') && $this->app->environment() == 'production') {
$this->commands = array_intersect_key($this->commands, [
'Migrate' => true,
'MigrateInstall' => true,
]);
$this->registerCommands($this->commands);
} else {
$this->app->register(\Laravel\Tinker\TinkerServiceProvider::class);
parent::register();
if (defined('ARTISAN_BINARY') && ARTISAN_BINARY == 'lnms' && $this->app->environment() == 'production') {
$this->app->register(\NunoMaduro\LaravelConsoleSummary\LaravelConsoleSummaryServiceProvider::class);
}
}
protected function registerModelMakeCommand()
{
// override with our own implementation to put models in the correct namespace
$this->app->singleton('command.model.make', function ($app) {
return new \App\Console\ModelMakeCommand($app['files']);
});
}
protected function registerMigrateInstallCommand()
{
// override so we can hide it
$this->app->singleton('command.migrate.install', function ($app) {
return new MigrateInstallCommand($app['migration.repository']);
});
}
}

View File

@ -46,6 +46,7 @@
"laravel/tinker": "^2.0",
"laravel/ui": "^3.0",
"librenms/laravel-vue-i18n-generator": "^0.1.46",
"nunomaduro/laravel-console-summary": "^1.7",
"oriceon/toastr-5-laravel": "dev-master",
"pear/console_color2": "^0.1",
"pear/console_table": "^1.3",
@ -129,5 +130,12 @@
"python-requirements": [
"scripts/check_requirements.py || pip3 install --user -r requirements.txt || :"
]
},
"extra": {
"laravel": {
"dont-discover": [
"nunomaduro/laravel-console-summary"
]
}
}
}

61
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "05264c05dd948950fbe0657997dc873e",
"content-hash": "3e9cbf21097ccab201f6851522787f3e",
"packages": [
{
"name": "amenadiel/jpgraph",
@ -2367,6 +2367,65 @@
],
"time": "2020-09-26T10:30:38+00:00"
},
{
"name": "nunomaduro/laravel-console-summary",
"version": "v1.7.0",
"source": {
"type": "git",
"url": "https://github.com/nunomaduro/laravel-console-summary.git",
"reference": "f43a1aa3c655190fe12ae461e7dda2876ca26890"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nunomaduro/laravel-console-summary/zipball/f43a1aa3c655190fe12ae461e7dda2876ca26890",
"reference": "f43a1aa3c655190fe12ae461e7dda2876ca26890",
"shasum": ""
},
"require": {
"illuminate/console": "^7.0|^8.0",
"illuminate/support": "^7.0|^8.0",
"php": "^7.2.5|^8.0"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"NunoMaduro\\LaravelConsoleSummary\\LaravelConsoleSummaryServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"NunoMaduro\\LaravelConsoleSummary\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nuno Maduro",
"email": "enunomaduro@gmail.com"
}
],
"description": "A Beautiful Laravel Console Summary for your Laravel/Laravel Zero commands.",
"keywords": [
"artisan",
"cli",
"command-line",
"console",
"laravel",
"laravel-zero",
"php",
"symfony"
],
"support": {
"issues": "https://github.com/nunomaduro/laravel-console-summary/issues",
"source": "https://github.com/nunomaduro/laravel-console-summary"
},
"time": "2020-10-30T14:42:45+00:00"
},
{
"name": "opis/closure",
"version": "3.6.0",

View File

@ -0,0 +1,58 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Hide Commands
|--------------------------------------------------------------------------
|
| This option allows to hide certain commands from the summary output.
| They will still be available in your application. Wildcards are supported
|
| Examples: "make:*", "list"
|
*/
'hide' => [
'auth:*',
'cache:*',
'clear-compiled',
'config:cache',
'config:clear',
'db:*',
'debugbar:*',
'down',
'dusk',
'dusk:*',
'env',
'event:*',
'help',
'ide-helper:*',
'key:*',
'list',
'make:*',
'migrate:*',
'notifications:*',
'optimize:*',
'package:*',
'queue:*',
'release:*',
'route:*',
'schedule:*',
'schema:*',
'serve',
'session:*',
'storage:*',
'stub:*',
'test',
'tinker',
'translation:*',
'ui:*',
'up',
'vendor:*',
'view:*',
'vue-i18n:*',
'ziggy:*',
],
];

2
lnms
View File

@ -31,7 +31,7 @@ $app = require_once __DIR__.'/bootstrap/app.php';
|
*/
define('LIBRENMS_CLI', true);
define('ARTISAN_BINARY', 'lnms');
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);