-
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
4 changed files
with
60 additions
and
39 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 Spectre.Console.Cli; | ||
using System.Runtime.InteropServices; | ||
|
||
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