- 重命名 log_file 为 test_scenario(测试场景) - 拆分维度表:tx_panel、tx_hardware、tx_software、rx_type - 采用星型模型设计,消除数据冗余 - 为所有表添加软删除字段 is_deleted - 更新关系说明,包含全局查询过滤器配置 - 更新 ER 图和查询示例 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
168 lines
3.9 KiB
Markdown
168 lines
3.9 KiB
Markdown
# CLI 命令设计
|
|
|
|
> 所属模块:[架构概览](./概览.md)
|
|
|
|
---
|
|
|
|
## 1. 命令概览
|
|
|
|
| 命令 | 说明 |
|
|
|------|------|
|
|
| `parse` | 解析日志文件并存储到数据库 |
|
|
| `stats` | 查询统计信息 |
|
|
| `export` | 导出数据 |
|
|
| `clean` | 清理数据 |
|
|
|
|
---
|
|
|
|
## 2. 命令详解
|
|
|
|
### 2.1 parse - 解析日志文件
|
|
|
|
```bash
|
|
# 解析单个文件
|
|
dotnet run parse --file path/to/log.txt
|
|
|
|
# 解析目录下所有文件
|
|
dotnet run parse --dir path/to/logs/
|
|
|
|
# 解析目录(递归)
|
|
dotnet run parse --dir path/to/logs/ --recursive
|
|
|
|
# 强制重新解析(覆盖已有数据)
|
|
dotnet run parse --file log.txt --force
|
|
```
|
|
|
|
### 2.2 stats - 查询统计
|
|
|
|
```bash
|
|
# 查看文件解析统计
|
|
dotnet run stats --file log.txt
|
|
|
|
# 查看整体统计
|
|
dotnet run stats --summary
|
|
|
|
# 按 FOD 类型统计
|
|
dotnet run stats --by-fod-type
|
|
```
|
|
|
|
### 2.3 export - 导出数据
|
|
|
|
```bash
|
|
# 导出为 CSV
|
|
dotnet run export --format csv --output ./output/
|
|
|
|
# 导出为 JSON
|
|
dotnet run export --format json --output ./output/
|
|
|
|
# 按文件导出
|
|
dotnet run export --file log.txt --format csv
|
|
```
|
|
|
|
### 2.4 clean - 清理数据
|
|
|
|
```bash
|
|
# 清理指定文件的数据
|
|
dotnet run clean --file log.txt --confirm
|
|
|
|
# 清理所有数据
|
|
dotnet run clean --all --confirm
|
|
```
|
|
|
|
---
|
|
|
|
## 3. 命令实现
|
|
|
|
```csharp
|
|
// Commands/ParseCommand.cs
|
|
using System.CommandLine;
|
|
|
|
namespace WCTDataMiner.Commands;
|
|
|
|
public class ParseCommand : Command
|
|
{
|
|
public ParseCommand(ParseService parseService)
|
|
: base("parse", "Parse log files and store data to database")
|
|
{
|
|
var fileOption = new Option<string>(
|
|
"--file",
|
|
"Path to a single log file to parse"
|
|
);
|
|
|
|
var dirOption = new Option<string>(
|
|
"--dir",
|
|
"Path to directory containing log files"
|
|
);
|
|
|
|
var recursiveOption = new Option<bool>(
|
|
"--recursive",
|
|
() => false,
|
|
"Recursively search subdirectories"
|
|
);
|
|
|
|
var forceOption = new Option<bool>(
|
|
"--force",
|
|
() => false,
|
|
"Force re-parse even if file already parsed"
|
|
);
|
|
|
|
AddOption(fileOption);
|
|
AddOption(dirOption);
|
|
AddOption(recursiveOption);
|
|
AddOption(forceOption);
|
|
|
|
this.SetHandler(async (file, dir, recursive, force) =>
|
|
{
|
|
if (!string.IsNullOrEmpty(file))
|
|
{
|
|
await parseService.ParseFileAsync(file, force);
|
|
}
|
|
else if (!string.IsNullOrEmpty(dir))
|
|
{
|
|
await parseService.ParseDirectoryAsync(dir, recursive, force);
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Please specify --file or --dir");
|
|
}
|
|
}, fileOption, dirOption, recursiveOption, forceOption);
|
|
}
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## 4. Program.cs 入口
|
|
|
|
```csharp
|
|
// Program.cs
|
|
using System.CommandLine;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using WCTDataMiner.Commands;
|
|
|
|
var builder = Host.CreateApplicationBuilder(args);
|
|
|
|
// 注册服务
|
|
builder.Services.AddScoped<ParseService>();
|
|
builder.Services.AddScoped<StatsService>();
|
|
builder.Services.AddScoped<ExportService>();
|
|
builder.Services.AddScoped<CleanService>();
|
|
builder.Services.AddDatabaseServices(builder.Configuration);
|
|
|
|
var app = builder.Build();
|
|
|
|
// 创建根命令
|
|
var rootCommand = new RootCommand("WCTDataMiner - FOD Log Data Parser");
|
|
|
|
// 使用服务提供者获取服务
|
|
using var scope = app.Services.CreateScope();
|
|
var provider = scope.ServiceProvider;
|
|
|
|
rootCommand.AddCommand(new ParseCommand(provider.GetRequiredService<ParseService>()));
|
|
rootCommand.AddCommand(new StatsCommand(provider.GetRequiredService<StatsService>()));
|
|
rootCommand.AddCommand(new ExportCommand(provider.GetRequiredService<ExportService>()));
|
|
rootCommand.AddCommand(new CleanCommand(provider.GetRequiredService<CleanService>()));
|
|
|
|
return await rootCommand.InvokeAsync(args);
|
|
``` |