mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-01 23:42:48 +08:00
56 lines
1.4 KiB
PHP
56 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace base\common\command\admin;
|
|
|
|
use app\common\console\Command;
|
|
use think\console\Input;
|
|
use think\console\Output;
|
|
use think\facade\App;
|
|
|
|
class ClearBase extends Command
|
|
{
|
|
protected function configure()
|
|
{
|
|
parent::configure();
|
|
|
|
// 指令配置
|
|
$this->setName('admin:clear')
|
|
->setDescription('删除开发临时生成目录');
|
|
}
|
|
|
|
protected function execute(Input $input, Output $output)
|
|
{
|
|
$dir = App::getRootPath() . '/runtime/source/';
|
|
$deleted = false;
|
|
$message = '';
|
|
$command_line = '';
|
|
|
|
if (!is_dir($dir)) {
|
|
$deleted = true;
|
|
$message = '目录不存在,无需删除';
|
|
} else {
|
|
if (strpos(strtolower(PHP_OS), 'win') === 0) {
|
|
$command_line = implode(' ', ['rd', '/s', '/q', str_replace('/', '\\', $dir)]);
|
|
} else {
|
|
$command_line = implode(' ', ['rm', '-rf', $dir]);
|
|
}
|
|
|
|
exec($command_line);
|
|
$deleted = !is_dir($dir);
|
|
$message = $deleted ? '删除成功' : '删除失败';
|
|
}
|
|
|
|
// 文本模式输出
|
|
$output->writeln('删除测试目录');
|
|
if ($command_line) {
|
|
$output->info('删除目录:' . $command_line);
|
|
$output->info('run command: ' . $command_line);
|
|
}
|
|
$output->info($message);
|
|
|
|
return $deleted ? 0 : 1;
|
|
}
|
|
}
|