Skip to content

Commit 675dd93

Browse files
authored
使用 Spectre.Console.Cli,并启用本地化
使用 Spectre.Console.Cli,并启用本地化
2 parents e65ab3b + 2dc5b76 commit 675dd93

24 files changed

+317
-228
lines changed

scripts/PublishToLocal.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $OutputEncoding = [System.Console]::OutputEncoding = [System.Console]::InputEnco
99

1010
$commandLinePath = Join-Path $location "../src/Command/CommandLine";
1111
$studioPath = Join-Path $location "../src/Studio/AterStudio";
12-
$dotnetVersion = "net8.0"
12+
$dotnetVersion = "net9.0"
1313

1414
try {
1515
Set-Location $location
@@ -48,7 +48,7 @@ try {
4848
$xml.Save($studioProjectPath)
4949

5050
# pack modules
51-
& "./PackTemplate.ps1"
51+
# & "./PackTemplate.ps1"
5252

5353
# build web project
5454
if ($withStudio -eq $true) {

src/Command/Command.Share/Command.Share.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
</PropertyGroup>
77
<ItemGroup>
88
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.4" />
9+
<PackageReference Include="Spectre.Console" Version="0.50.0" />
910
</ItemGroup>
1011
<ItemGroup>
1112
<ProjectReference Include="..\..\Definition\Share\Share.csproj" />

src/Command/Command.Share/CommandRunner.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using CodeGenerator;
1+
using CodeGenerator;
22
using CodeGenerator.Helper;
33
using CodeGenerator.Models;
4-
using Entity;
4+
using Command.Share.Runners;
55
using Microsoft.Extensions.Logging;
66
using Share.Services;
77

@@ -25,8 +25,8 @@ public class CommandRunner(CodeGenService codeGen, CodeAnalysisService codeAnaly
2525
public static async Task RunStudioAsync()
2626
{
2727
using var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
28-
ILogger<StudioCommand> studioLogger = loggerFactory.CreateLogger<StudioCommand>();
29-
var studioCommand = new StudioCommand(studioLogger);
28+
ILogger<StudioRunner> studioLogger = loggerFactory.CreateLogger<StudioRunner>();
29+
var studioCommand = new StudioRunner(studioLogger);
3030
await studioCommand.RunStudioAsync();
3131
}
3232

@@ -36,8 +36,8 @@ public static async Task RunStudioAsync()
3636
public static void UpdateStudio()
3737
{
3838
using var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
39-
ILogger<StudioCommand> studioLogger = loggerFactory.CreateLogger<StudioCommand>();
40-
var studioCommand = new StudioCommand(studioLogger);
39+
ILogger<StudioRunner> studioLogger = loggerFactory.CreateLogger<StudioRunner>();
40+
var studioCommand = new StudioRunner(studioLogger);
4141
studioCommand.UpdateStudio();
4242
}
4343

@@ -52,7 +52,7 @@ public async Task GenerateNgAsync(string url = "", string output = "")
5252
try
5353
{
5454
_logger.LogInformation("🚀 Generating ts models and ng services...");
55-
RequestCommand cmd = new(url, output, RequestLibType.NgHttp);
55+
RequestRunner cmd = new(url, output, RequestLibType.NgHttp);
5656
await cmd.RunAsync();
5757
}
5858
catch (WebException webExp)
@@ -77,7 +77,7 @@ public async Task GenerateRequestAsync(string url = "", string output = "", Requ
7777
try
7878
{
7979
_logger.LogInformation($"🚀 Generating ts models and {type} request services...");
80-
RequestCommand cmd = new(url, output, type);
80+
RequestRunner cmd = new(url, output, type);
8181
await cmd.RunAsync();
8282
}
8383
catch (WebException webExp)
@@ -171,7 +171,7 @@ public async Task GenerateApiAsync(string entityPath, string sharePath = "",
171171
/// <returns></returns>
172172
public static async Task GenerateCSharpApiClientAsync(string swaggerUrl, string outputPath, LanguageType language = LanguageType.CSharp)
173173
{
174-
ApiClientCommand cmd = new(swaggerUrl, outputPath, language);
174+
ApiClientRunner cmd = new(swaggerUrl, outputPath, language);
175175
await cmd.RunAsync();
176176
}
177177
}

src/Command/Command.Share/GlobalUsings.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
global using Command.Share.Commands;
55
global using Framework.Common.Utils;
66
global using Microsoft.OpenApi.Models;
7-
global using Microsoft.OpenApi.Readers;
7+
global using Microsoft.OpenApi.Readers;
8+
global using Spectre.Console;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
namespace Command.Share;
3+
public class OutputHelper
4+
{
5+
public static void ShowLogo()
6+
{
7+
string logo = """
8+
_____ _____ __ __
9+
| __ \ | __ \ \ \ / /
10+
| | | | | |__) | \ \_/ /
11+
| | | | | _ / \ /
12+
| |__| | | | \ \ | |
13+
|_____/ |_| \_\ |_|
14+
""";
15+
string sign1 = " —→ for freedom 🗽 ←—";
16+
string sign2 = " 🌐 [link]https://dusi.dev/docs[/]";
17+
18+
AnsiConsole.MarkupLine($"[bold green]{logo}[/]");
19+
AnsiConsole.MarkupLine($"[blue]{sign2}[/]");
20+
AnsiConsole.MarkupLine("");
21+
AnsiConsole.MarkupLine($"[yellow]{sign1}[/]");
22+
}
23+
24+
public static void ShowError(string message)
25+
{
26+
AnsiConsole.MarkupLine($"[red]✖️ {message}[/]");
27+
}
28+
29+
public static void ShowSuccess(string message)
30+
{
31+
AnsiConsole.MarkupLine($"[green]✔️ {message}[/]");
32+
}
33+
34+
public static void ShowInfo(string message)
35+
{
36+
AnsiConsole.MarkupLine($"ℹ️ {message}");
37+
}
38+
}
39+
40+
public class SubCommand
41+
{
42+
public const string New = "new";
43+
public const string Studio = "studio";
44+
public const string Update = "update";
45+
public const string NewDes = "NewDes";
46+
public const string StudioDes = "StudioDes";
47+
public const string StudioUpdateDes = "StudioUpdateDes";
48+
}

src/Command/Command.Share/Commands/ApiClientCommand.cs renamed to src/Command/Command.Share/Runners/ApiClientRunner.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using CodeGenerator.Models;
1+
using CodeGenerator.Models;
22
using Share.Infrastructure.Helper;
3-
namespace Command.Share.Commands;
3+
namespace Command.Share.Runners;
44
/// <summary>
55
/// 客户端请求生成
66
/// </summary>
7-
public class ApiClientCommand : CommandBase
7+
public class ApiClientRunner : CommandBase
88
{
99
/// <summary>
1010
/// swagger文档链接
@@ -24,7 +24,7 @@ public class ApiClientCommand : CommandBase
2424
/// </summary>
2525
public string OutputPath { get; set; }
2626

27-
public ApiClientCommand(string docUrl, string output, LanguageType languageType)
27+
public ApiClientRunner(string docUrl, string output, LanguageType languageType)
2828
{
2929
DocUrl = docUrl;
3030
DocName = docUrl.Split('/').Reverse().Skip(1).First();
File renamed without changes.

src/Command/Command.Share/Commands/DocCommand.cs renamed to src/Command/Command.Share/Runners/DocRunner.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
using Microsoft.OpenApi.Models;
1+
using Microsoft.OpenApi.Models;
22
using Microsoft.OpenApi.Readers;
33

44
namespace Command.Share.Commands;
5-
public class DocCommand : CommandBase
5+
public class DocRunner : CommandBase
66
{
77
public string DocUrl { get; set; } = default!;
88
public OpenApiDocument? ApiDocument { get; set; }
99

1010
public string OutputPath { get; set; }
1111

12-
public DocCommand(string docUrl, string output)
12+
public DocRunner(string docUrl, string output)
1313
{
1414
DocUrl = docUrl;
1515
OutputPath = Path.Combine(output);

src/Command/Command.Share/Commands/RequestCommand.cs renamed to src/Command/Command.Share/Runners/RequestRunner.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using CodeGenerator.Models;
2-
namespace Command.Share.Commands;
1+
using CodeGenerator.Models;
2+
namespace Command.Share.Runners;
33

44
/// <summary>
55
/// 前端ts请求生成命令
66
/// </summary>
7-
public class RequestCommand : CommandBase
7+
public class RequestRunner : CommandBase
88
{
99
/// <summary>
1010
/// swagger文档链接
@@ -21,7 +21,7 @@ public class RequestCommand : CommandBase
2121

2222
public string OutputPath { get; set; }
2323

24-
public RequestCommand(string docUrl, string output, RequestLibType libType)
24+
public RequestRunner(string docUrl, string output, RequestLibType libType)
2525
{
2626
DocUrl = docUrl;
2727
OutputPath = output;

src/Command/Command.Share/Commands/StudioCommand.cs renamed to src/Command/Command.Share/Runners/StudioRunner.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
using Microsoft.Extensions.Logging;
88
using Share.Infrastructure.Helper;
99

10-
namespace Command.Share.Commands;
11-
public class StudioCommand(ILogger<StudioCommand> logger)
10+
namespace Command.Share.Runners;
11+
public class StudioRunner(ILogger<StudioRunner> logger)
1212
{
13-
private readonly ILogger<StudioCommand> _logger = logger;
13+
private readonly ILogger<StudioRunner> _logger = logger;
1414

1515
public async Task RunStudioAsync()
1616
{
@@ -112,7 +112,7 @@ public void UpdateStudio()
112112
"Microsoft.Extensions.Configuration.Abstractions",
113113
"Microsoft.Extensions.DependencyInjection.Abstractions",
114114
"Microsoft.Extensions.DependencyInjection",
115-
"Microsoft.Extensions.Logging.Abstractions",
115+
"Microsoft.Extensions.Logging.Abstractions",1
116116
"Microsoft.Extensions.Logging",
117117
"Microsoft.Extensions.Options",
118118
"Microsoft.Extensions.Primitives",

0 commit comments

Comments
 (0)