增加删除临时目录的命令

This commit is contained in:
2022-09-24 10:50:25 +08:00
parent 90578e7acd
commit 2620e44420
2 changed files with 55 additions and 1 deletions

View File

@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace app\common\command\admin;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\facade\App;
class Clear extends Command
{
protected function configure()
{
// 指令配置
$this->setName('admin:clear')
->setDescription('删除开发临时生成目录');
}
protected function execute(Input $input, Output $output)
{
// 指令输出
$output->writeln('删除测试目录');
$command_line = '';
$dir = App::getRootPath() . '/runtime/source/';
if (!is_dir($dir)) {
$output->writeln('删除成功');
return;
}
if (strpos(strtolower(PHP_OS), 'win') === 0) {
$command_line = implode(' ', ['rd', '/s', '/q', str_replace('/', '\\', $dir)]);
} else {
$command_line = implode(' ', ['rm', '-rf', $dir]);
}
$output->info('删除目录:' . $command_line);
$output->info('run command: ' . $command_line);
exec($command_line);
$output->info('删除成功');
}
}

View File

@@ -3,6 +3,7 @@
// | 控制台配置
// +----------------------------------------------------------------------
use app\common\command\admin\Clear;
use app\common\command\admin\Version;
use app\common\command\admin\ResetPassword;
use app\common\command\curd\Migrate;
@@ -17,6 +18,7 @@ return [
ResetPassword::class,
Timer::class,
Version::class,
Migrate::class
Migrate::class,
Clear::class
],
];