refactor(project): 迁移项目命名并移除WPF客户端
This commit is contained in:
84
src/Gpulse.WCT.DataAnalyzer/Commands/ExportCommand.cs
Normal file
84
src/Gpulse.WCT.DataAnalyzer/Commands/ExportCommand.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System.CommandLine;
|
||||
using Gpulse.WCT.DataAnalyzer.Core.Services;
|
||||
|
||||
namespace Gpulse.WCT.DataAnalyzer.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// 数据导出命令
|
||||
/// </summary>
|
||||
public class ExportCommand : Command
|
||||
{
|
||||
public ExportCommand(ExportService exportService)
|
||||
: base("export", "Export data to CSV or JSON")
|
||||
{
|
||||
var formatOption = new Option<string>(
|
||||
"--format",
|
||||
() => "csv",
|
||||
"Export format: csv or json"
|
||||
);
|
||||
|
||||
var outputOption = new Option<string>(
|
||||
"--output",
|
||||
() => "./data/output",
|
||||
"Output directory path"
|
||||
);
|
||||
|
||||
var typeOption = new Option<string>(
|
||||
"--type",
|
||||
() => "all",
|
||||
"Data type to export: qfod, ploss, or all"
|
||||
);
|
||||
|
||||
AddOption(formatOption);
|
||||
AddOption(outputOption);
|
||||
AddOption(typeOption);
|
||||
|
||||
this.SetHandler(async (format, output, type) =>
|
||||
{
|
||||
format = format.ToLower();
|
||||
type = type.ToLower();
|
||||
|
||||
Console.WriteLine($"Exporting {type} data as {format.ToUpper()} to {output}...");
|
||||
|
||||
try
|
||||
{
|
||||
if (format == "csv")
|
||||
{
|
||||
if (type is "qfod" or "all")
|
||||
{
|
||||
var path = await exportService.ExportQfodToCsvAsync(output);
|
||||
Console.WriteLine($" Qfod CSV exported: {path}");
|
||||
}
|
||||
|
||||
if (type is "ploss" or "all")
|
||||
{
|
||||
var path = await exportService.ExportPlossToCsvAsync(output);
|
||||
Console.WriteLine($" Ploss CSV exported: {path}");
|
||||
}
|
||||
}
|
||||
else if (format == "json")
|
||||
{
|
||||
if (type is "qfod" or "all")
|
||||
{
|
||||
var path = await exportService.ExportQfodToJsonAsync(output);
|
||||
Console.WriteLine($" Qfod JSON exported: {path}");
|
||||
}
|
||||
|
||||
if (type is "ploss" or "all")
|
||||
{
|
||||
var path = await exportService.ExportPlossToJsonAsync(output);
|
||||
Console.WriteLine($" Ploss JSON exported: {path}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Unknown format: {format}. Use 'csv' or 'json'.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Export failed: {ex.Message}");
|
||||
}
|
||||
}, formatOption, outputOption, typeOption);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user