Add top-level CancellationToken support to Spectre.Console.Cli

Also raise CA2016 (forward the CancellationToken parameter to methods that take one) to warning

Fixes #701
This commit is contained in:
Cédric Luthi
2024-09-09 00:21:17 +02:00
committed by Patrik Svensson
parent d90e94dbb3
commit f5f61ca610
55 changed files with 222 additions and 174 deletions

View File

@@ -1,4 +1,5 @@
using System.IO;
using System.Threading;
using Generator.Models;
using Scriban;
using Spectre.Console.Cli;
@@ -21,7 +22,7 @@ namespace Generator.Commands
public string Input { get; set; }
}
public override int Execute(CommandContext context, Settings settings)
public override int Execute(CommandContext context, Settings settings, CancellationToken cancellationToken)
{
var templates = new FilePath[]
{

View File

@@ -2,6 +2,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using AngleSharp.Html.Parser;
using Generator.Models;
@@ -39,7 +40,7 @@ namespace Generator.Commands
_parser = new HtmlParser();
}
public override async Task<int> ExecuteAsync(CommandContext context, Settings settings)
public override async Task<int> ExecuteAsync(CommandContext context, Settings settings, CancellationToken cancellationToken)
{
var output = new DirectoryPath(settings.Output);
if (!_fileSystem.Directory.Exists(settings.Output))

View File

@@ -4,6 +4,7 @@ using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using Generator.Commands.Samples;
using Spectre.Console;
using Spectre.Console.Cli;
@@ -38,7 +39,7 @@ namespace Generator.Commands
_console = new AsciiCastConsole(console);
}
public override int Execute([NotNull] CommandContext context, [NotNull] Settings settings)
public override int Execute([NotNull] CommandContext context, [NotNull] Settings settings, CancellationToken cancellationToken)
{
var samples = typeof(BaseSample).Assembly
.GetTypes()

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.IO;
using System.Threading;
using Generator.Models;
using Scriban;
using Spectre.Console.Cli;
@@ -16,7 +17,7 @@ namespace Generator.Commands
_fileSystem = new FileSystem();
}
public override int Execute(CommandContext context, GeneratorSettings settings)
public override int Execute(CommandContext context, GeneratorSettings settings, CancellationToken cancellationToken)
{
// Read the spinner model.
var spinners = new List<Spinner>();