Skip to content

Commit 39b174b

Browse files
committed
deps: update Spectre.Cli package
1 parent 4d04ff5 commit 39b174b

14 files changed

+77
-74
lines changed

Directory.Packages.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
<PackageVersion Include="OneOf.SourceGenerator" Version="3.0.271" />
1616
<PackageVersion Include="PdfPig" Version="0.1.11" />
1717
<PackageVersion Include="PlantUml.Net" Version="1.4.80" />
18-
<PackageVersion Include="Spectre.Console" Version="0.52.0" />
19-
<PackageVersion Include="Spectre.Console.Cli" Version="0.52.0" />
18+
<PackageVersion Include="Spectre.Console" Version="0.53.0" />
19+
<PackageVersion Include="Spectre.Console.Cli" Version="0.53.0" />
2020
<PackageVersion Include="Stubble.Core" Version="1.10.8" />
2121
<PackageVersion Include="System.Composition" Version="9.0.10" />
2222
<PackageVersion Include="YamlDotNet" Version="16.3.0" />

src/Docfx.App/PdfBuilder.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Concurrent;
66
using System.Diagnostics;
77
using System.Reflection;
8+
using System.Runtime.InteropServices;
89
using System.Text;
910
using System.Text.Json;
1011
using Docfx.Build;
@@ -73,6 +74,19 @@ public static async Task CreatePdf(string outputFolder, CancellationToken cancel
7374

7475
Program.Main(["install", "chromium", "--only-shell"]);
7576

77+
// Create linked CancellationToken with PosixSignalRegistration handler.
78+
// It's required because default `Ctrl+C` interruption is canceled when using WebApplication inside Spectre.Console command.
79+
using var cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
80+
void onSignal(PosixSignalContext context)
81+
{
82+
context.Cancel = true;
83+
cancellationTokenSource.Cancel();
84+
}
85+
using var sigInt = PosixSignalRegistration.Create(PosixSignal.SIGINT, onSignal);
86+
using var sigQuit = PosixSignalRegistration.Create(PosixSignal.SIGQUIT, onSignal);
87+
using var sigTerm = PosixSignalRegistration.Create(PosixSignal.SIGTERM, onSignal);
88+
cancellationToken = cancellationTokenSource.Token;
89+
7690
var builder = WebApplication.CreateBuilder();
7791
builder.Logging.ClearProviders();
7892
builder.WebHost.UseUrls("http://127.0.0.1:0");

src/Docfx.Dotnet/DotnetApiCatalog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static async Task GenerateManagedReferenceYamlFiles(string configPath, Do
5555
}
5656
}
5757

58-
internal static async Task Exec(MetadataJsonConfig config, DotnetApiOptions options, string configDirectory, string outputDirectory = null)
58+
internal static async Task Exec(MetadataJsonConfig config, DotnetApiOptions options, string configDirectory, string outputDirectory = null, CancellationToken cancellationToken = default)
5959
{
6060
var stopwatch = Stopwatch.StartNew();
6161

src/docfx/Models/BuildCommand.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88

99
namespace Docfx;
1010

11-
internal class BuildCommand : Command<BuildCommandOptions>
11+
# pragma warning disable 1998 // CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls
12+
13+
internal class BuildCommand : AsyncCommand<BuildCommandOptions>
1214
{
13-
public override int Execute(CommandContext context, BuildCommandOptions settings)
15+
public override Task<int> ExecuteAsync(CommandContext context, BuildCommandOptions settings, CancellationToken cancellationToken)
1416
{
15-
return CommandHelper.Run(settings, () =>
17+
return CommandHelper.RunAsync(settings, async () =>
1618
{
1719
if (settings.Serve && CommandHelper.IsTcpPortAlreadyUsed(settings.Host, settings.Port))
1820
{

src/docfx/Models/CancellableCommandBase.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/docfx/Models/CommandHelper.cs

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,28 @@ public static int Run(Action run)
2020

2121
Logger.Flush();
2222
Logger.UnregisterAllListeners();
23+
// Logger.PrintSummary() method is not called when Run without LogOptions.(DownloadCommand/ServeCommand/TemplateCommand)
2324

2425
return 0;
2526
}
2627

2728
public static int Run(LogOptions options, Action run)
2829
{
29-
var consoleLogListener = new ConsoleLogListener();
30-
Logger.RegisterListener(consoleLogListener);
31-
32-
if (!string.IsNullOrWhiteSpace(options.LogFilePath))
33-
{
34-
Logger.RegisterListener(new ReportLogListener(options.LogFilePath));
35-
}
30+
SetupLogger(options);
3631

37-
if (options.LogLevel.HasValue)
38-
{
39-
Logger.LogLevelThreshold = options.LogLevel.Value;
40-
}
41-
else if (options.Verbose)
42-
{
43-
Logger.LogLevelThreshold = LogLevel.Verbose;
44-
}
32+
run();
4533

46-
Logger.WarningsAsErrors = options.WarningsAsErrors;
34+
CleanupLogger();
35+
return Logger.HasError ? -1 : 0;
36+
}
4737

48-
run();
38+
public static async Task<int> RunAsync(LogOptions options, Func<Task> run)
39+
{
40+
SetupLogger(options);
4941

50-
Logger.Flush();
51-
Logger.UnregisterAllListeners();
52-
Logger.PrintSummary();
42+
await run();
5343

44+
CleanupLogger();
5445
return Logger.HasError ? -1 : 0;
5546
}
5647

@@ -82,4 +73,33 @@ public static bool IsTcpPortAlreadyUsed(string? host, int? port)
8273
}
8374
}
8475
}
76+
77+
private static void SetupLogger(LogOptions options)
78+
{
79+
var consoleLogListener = new ConsoleLogListener();
80+
Logger.RegisterListener(consoleLogListener);
81+
82+
if (!string.IsNullOrWhiteSpace(options.LogFilePath))
83+
{
84+
Logger.RegisterListener(new ReportLogListener(options.LogFilePath));
85+
}
86+
87+
if (options.LogLevel.HasValue)
88+
{
89+
Logger.LogLevelThreshold = options.LogLevel.Value;
90+
}
91+
else if (options.Verbose)
92+
{
93+
Logger.LogLevelThreshold = LogLevel.Verbose;
94+
}
95+
96+
Logger.WarningsAsErrors = options.WarningsAsErrors;
97+
}
98+
99+
private static void CleanupLogger()
100+
{
101+
Logger.Flush();
102+
Logger.UnregisterAllListeners();
103+
Logger.PrintSummary();
104+
}
85105
}

src/docfx/Models/DefaultCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace Docfx;
1212

13-
class DefaultCommand : CancellableCommandBase<DefaultCommand.Options>
13+
class DefaultCommand : Command<DefaultCommand.Options>
1414
{
1515
[Description("Runs metadata, build and pdf commands")]
1616
internal class Options : BuildCommandOptions

src/docfx/Models/DownloadCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Docfx;
1010

1111
internal class DownloadCommand : Command<DownloadCommandOptions>
1212
{
13-
public override int Execute([NotNull] CommandContext context, [NotNull] DownloadCommandOptions options)
13+
public override int Execute([NotNull] CommandContext context, [NotNull] DownloadCommandOptions options, CancellationToken cancellationToken)
1414
{
1515
return CommandHelper.Run(() =>
1616
{

src/docfx/Models/InitCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Docfx;
1313

1414
class InitCommand : Command<InitCommandOptions>
1515
{
16-
public override int Execute([NotNull] CommandContext context, [NotNull] InitCommandOptions options)
16+
public override int Execute([NotNull] CommandContext context, [NotNull] InitCommandOptions options, CancellationToken cancellationToken)
1717
{
1818
WriteLine(
1919
"""

src/docfx/Models/MergeCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Docfx;
88

99
internal class MergeCommand : Command<MergeCommandOptions>
1010
{
11-
public override int Execute([NotNull] CommandContext context, [NotNull] MergeCommandOptions options)
11+
public override int Execute([NotNull] CommandContext context, [NotNull] MergeCommandOptions options, CancellationToken cancellationToken)
1212
{
1313
return CommandHelper.Run(options, () =>
1414
{

0 commit comments

Comments
 (0)