Skip to content

Commit c5f8592

Browse files
committed
use Ct alias for CancellationToken
1 parent 95ae67f commit c5f8592

File tree

8 files changed

+28
-21
lines changed

8 files changed

+28
-21
lines changed

Directory.Build.props

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@
2121
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
2222
</PropertyGroup>
2323

24+
<ItemGroup>
25+
<Compile Include="$(MSBuildThisFileDirectory)/Global.cs" Link="Global.cs" />
26+
</ItemGroup>
27+
2428
</Project>

Global.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma warning disable IDE0005 // Remove unnecessary using directives
2+
global using Ct = System.Threading.CancellationToken;
3+
#pragma warning restore IDE0005

SimpleExec/Command.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static class Command
3535
/// If set to <c>true</c>, when the command is cancelled, any child processes created by the command
3636
/// are left running after the command is cancelled.
3737
/// </param>
38-
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the command to exit.</param>
38+
/// <param name="cancellationToken">A <see cref="Ct"/> to observe while waiting for the command to exit.</param>
3939
/// <exception cref="ExitCodeException">The command exited with non-zero exit code.</exception>
4040
/// <remarks>
4141
/// By default, the resulting command line and the working directory (if specified) are echoed to standard output (stdout).
@@ -52,7 +52,7 @@ public static void Run(
5252
bool createNoWindow = false,
5353
Func<int, bool>? handleExitCode = null,
5454
bool cancellationIgnoresProcessTree = false,
55-
CancellationToken cancellationToken = default) =>
55+
Ct cancellationToken = default) =>
5656
ProcessStartInfo
5757
.Create(
5858
Resolve(Validate(name)),
@@ -89,7 +89,7 @@ public static void Run(
8989
/// If set to <c>true</c>, when the command is cancelled, any child processes created by the command
9090
/// are left running after the command is cancelled.
9191
/// </param>
92-
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the command to exit.</param>
92+
/// <param name="cancellationToken">A <see cref="Ct"/> to observe while waiting for the command to exit.</param>
9393
/// <exception cref="ExitCodeException">The command exited with non-zero exit code.</exception>
9494
public static void Run(
9595
string name,
@@ -102,7 +102,7 @@ public static void Run(
102102
bool createNoWindow = false,
103103
Func<int, bool>? handleExitCode = null,
104104
bool cancellationIgnoresProcessTree = false,
105-
CancellationToken cancellationToken = default) =>
105+
Ct cancellationToken = default) =>
106106
ProcessStartInfo
107107
.Create(
108108
Resolve(Validate(name)),
@@ -121,7 +121,7 @@ private static void Run(
121121
string echoPrefix,
122122
Func<int, bool>? handleExitCode,
123123
bool cancellationIgnoresProcessTree,
124-
CancellationToken cancellationToken)
124+
Ct cancellationToken)
125125
{
126126
using var process = new Process();
127127
process.StartInfo = startInfo;
@@ -156,7 +156,7 @@ private static void Run(
156156
/// If set to <c>true</c>, when the command is cancelled, any child processes created by the command
157157
/// are left running after the command is cancelled.
158158
/// </param>
159-
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the command to exit.</param>
159+
/// <param name="cancellationToken">A <see cref="Ct"/> to observe while waiting for the command to exit.</param>
160160
/// <returns>A <see cref="Task"/> that represents the asynchronous running of the command.</returns>
161161
/// <exception cref="ExitCodeReadException">The command exited with non-zero exit code.</exception>
162162
/// <remarks>
@@ -174,7 +174,7 @@ public static Task RunAsync(
174174
bool createNoWindow = false,
175175
Func<int, bool>? handleExitCode = null,
176176
bool cancellationIgnoresProcessTree = false,
177-
CancellationToken cancellationToken = default) =>
177+
Ct cancellationToken = default) =>
178178
ProcessStartInfo
179179
.Create(
180180
Resolve(Validate(name)),
@@ -211,7 +211,7 @@ public static Task RunAsync(
211211
/// If set to <c>true</c>, when the command is cancelled, any child processes created by the command
212212
/// are left running after the command is cancelled.
213213
/// </param>
214-
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the command to exit.</param>
214+
/// <param name="cancellationToken">A <see cref="Ct"/> to observe while waiting for the command to exit.</param>
215215
/// <returns>A <see cref="Task"/> that represents the asynchronous running of the command.</returns>
216216
/// <exception cref="ExitCodeReadException">The command exited with non-zero exit code.</exception>
217217
public static Task RunAsync(
@@ -225,7 +225,7 @@ public static Task RunAsync(
225225
bool createNoWindow = false,
226226
Func<int, bool>? handleExitCode = null,
227227
bool cancellationIgnoresProcessTree = false,
228-
CancellationToken cancellationToken = default) =>
228+
Ct cancellationToken = default) =>
229229
ProcessStartInfo
230230
.Create(
231231
Resolve(Validate(name)),
@@ -244,7 +244,7 @@ private static async Task RunAsync(
244244
string echoPrefix,
245245
Func<int, bool>? handleExitCode,
246246
bool cancellationIgnoresProcessTree,
247-
CancellationToken cancellationToken)
247+
Ct cancellationToken)
248248
{
249249
using var process = new Process();
250250
process.StartInfo = startInfo;
@@ -276,7 +276,7 @@ private static async Task RunAsync(
276276
/// If set to <c>true</c>, when the command is cancelled, any child processes created by the command
277277
/// are left running after the command is cancelled.
278278
/// </param>
279-
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the command to exit.</param>
279+
/// <param name="cancellationToken">A <see cref="Ct"/> to observe while waiting for the command to exit.</param>
280280
/// <returns>
281281
/// A <see cref="Task{TResult}"/> representing the asynchronous running of the command and reading of standard output (stdout) and standard error (stderr).
282282
/// The task result is a <see cref="ValueTuple{T1, T2}"/> representing the contents of standard output (stdout) and standard error (stderr).
@@ -293,7 +293,7 @@ private static async Task RunAsync(
293293
Func<int, bool>? handleExitCode = null,
294294
string? standardInput = null,
295295
bool cancellationIgnoresProcessTree = false,
296-
CancellationToken cancellationToken = default) =>
296+
Ct cancellationToken = default) =>
297297
ProcessStartInfo
298298
.Create(
299299
Resolve(Validate(name)),
@@ -332,7 +332,7 @@ private static async Task RunAsync(
332332
/// If set to <c>true</c>, when the command is cancelled, any child processes created by the command
333333
/// are left running after the command is cancelled.
334334
/// </param>
335-
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the command to exit.</param>
335+
/// <param name="cancellationToken">A <see cref="Ct"/> to observe while waiting for the command to exit.</param>
336336
/// <returns>
337337
/// A <see cref="Task{TResult}"/> representing the asynchronous running of the command and reading of standard output (stdout) and standard error (stderr).
338338
/// The task result is a <see cref="ValueTuple{T1, T2}"/> representing the contents of standard output (stdout) and standard error (stderr).
@@ -349,7 +349,7 @@ private static async Task RunAsync(
349349
Func<int, bool>? handleExitCode = null,
350350
string? standardInput = null,
351351
bool cancellationIgnoresProcessTree = false,
352-
CancellationToken cancellationToken = default) =>
352+
Ct cancellationToken = default) =>
353353
ProcessStartInfo
354354
.Create(
355355
Resolve(Validate(name)),
@@ -371,7 +371,7 @@ private static async Task RunAsync(
371371
Func<int, bool>? handleExitCode,
372372
string? standardInput,
373373
bool cancellationIgnoresProcessTree,
374-
CancellationToken cancellationToken)
374+
Ct cancellationToken)
375375
{
376376
using var process = new Process();
377377
process.StartInfo = startInfo;

SimpleExec/ProcessExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace SimpleExec;
77

88
internal static class ProcessExtensions
99
{
10-
public static void Run(this Process process, IEnumerable<string> secrets, bool noEcho, string echoPrefix, bool cancellationIgnoresProcessTree, CancellationToken cancellationToken)
10+
public static void Run(this Process process, IEnumerable<string> secrets, bool noEcho, string echoPrefix, bool cancellationIgnoresProcessTree, Ct cancellationToken)
1111
{
1212
var cancelled = new StrongBox<long>(0);
1313

@@ -36,7 +36,7 @@ public static void Run(this Process process, IEnumerable<string> secrets, bool n
3636
}
3737
}
3838

39-
public static async Task RunAsync(this Process process, IEnumerable<string> secrets, bool noEcho, string echoPrefix, bool cancellationIgnoresProcessTree, CancellationToken cancellationToken)
39+
public static async Task RunAsync(this Process process, IEnumerable<string> secrets, bool noEcho, string echoPrefix, bool cancellationIgnoresProcessTree, Ct cancellationToken)
4040
{
4141
using var sync = new SemaphoreSlim(1, 1);
4242
var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);

SimpleExecTests/EchoingCommands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static class EchoingCommands
1010
private const string SecretLower = "secret";
1111
private const string SecretUpper = "SECRET";
1212

13-
private static CancellationToken Ct => TestContext.Current.CancellationToken;
13+
private static Ct Ct => TestContext.Current.CancellationToken;
1414

1515
[Fact]
1616
public static void EchoingACommand()

SimpleExecTests/ExitCodes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace SimpleExecTests;
66

77
public static class ExitCodes
88
{
9-
private static CancellationToken Ct => TestContext.Current.CancellationToken;
9+
private static Ct Ct => TestContext.Current.CancellationToken;
1010

1111
[Theory]
1212
[InlineData(0, false)]

SimpleExecTests/ReadingCommands.cs

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

99
public static class ReadingCommands
1010
{
11-
private static CancellationToken Ct => TestContext.Current.CancellationToken;
11+
private static Ct Ct => TestContext.Current.CancellationToken;
1212

1313
[Theory]
1414
[InlineData(false)]

SimpleExecTests/RunningCommands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace SimpleExecTests;
1010
public static class RunningCommands
1111
{
1212
private static readonly string Command = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "hello-world.cmd" : "ls";
13-
private static CancellationToken Ct => TestContext.Current.CancellationToken;
13+
private static Ct Ct => TestContext.Current.CancellationToken;
1414

1515
public static bool OsPlatformIsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
1616

0 commit comments

Comments
 (0)