-
Notifications
You must be signed in to change notification settings - Fork 867
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
60 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable enable | ||
|
||
using System.Runtime.InteropServices; | ||
using Spectre.Console.Cli; | ||
|
||
namespace Docfx; | ||
|
||
public abstract class CancellableCommandBase<TSettings> : Command<TSettings> | ||
where TSettings : CommandSettings | ||
{ | ||
public abstract int Execute(CommandContext context, TSettings settings, CancellationToken cancellation); | ||
|
||
public sealed override int Execute(CommandContext context, TSettings settings) | ||
{ | ||
using var cancellationSource = new CancellationTokenSource(); | ||
|
||
using var sigInt = PosixSignalRegistration.Create(PosixSignal.SIGINT, onSignal); | ||
using var sigQuit = PosixSignalRegistration.Create(PosixSignal.SIGQUIT, onSignal); | ||
using var sigTerm = PosixSignalRegistration.Create(PosixSignal.SIGTERM, onSignal); | ||
|
||
var exitCode = Execute(context, settings, cancellationSource.Token); | ||
return exitCode; | ||
|
||
void onSignal(PosixSignalContext context) | ||
{ | ||
context.Cancel = true; | ||
cancellationSource.Cancel(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using Docfx.Pdf; | ||
using Spectre.Console.Cli; | ||
|
||
#nullable enable | ||
|
||
namespace Docfx; | ||
|
||
internal class PdfCommand : Command<PdfCommandOptions> | ||
internal class PdfCommand : CancellableCommandBase<PdfCommandOptions> | ||
{ | ||
public override int Execute([NotNull] CommandContext context, [NotNull] PdfCommandOptions options) | ||
public override int Execute(CommandContext context, PdfCommandOptions options, CancellationToken cancellationToken) | ||
{ | ||
return CommandHelper.Run(options, () => | ||
{ | ||
var (config, configDirectory) = Docset.GetConfig(options.ConfigFile); | ||
|
||
if (config.build is not null) | ||
PdfBuilder.Run(config.build, configDirectory, options.OutputFolder).GetAwaiter().GetResult(); | ||
PdfBuilder.Run(config.build, configDirectory, options.OutputFolder, cancellationToken).GetAwaiter().GetResult(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
|
||
using System.Text; | ||
using Docfx.Common; | ||
using Docfx.Plugins; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
|