Skip to content

Commit 2565c1d

Browse files
Merge pull request #505 from bilal-fazlani/nullable-class-constraint
breaK with ExitCodes Async rename. change to `T:class?` constraint for nulls
2 parents 8953415 + b19b7fd commit 2565c1d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+100
-102
lines changed

CommandDotNet.DataAnnotations/DataAnnotationsMiddleware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private static Task<int> DataAnnotationsValidation(CommandContext ctx, Execution
6262
console.Error.WriteLine();
6363
}
6464

65-
return ExitCodes.ValidationError;
65+
return ExitCodes.ValidationErrorAsync;
6666
}
6767

6868
return next(ctx);

CommandDotNet.DocExamples/Diagnostics/Exceptions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private static int ErrorHandler(CommandContext? ctx, Exception exception)
3434
// if the exception occurred before a command could be parsed
3535
ctx?.PrintHelp();
3636

37-
return ExitCodes.Error.Result;
37+
return ExitCodes.ErrorAsync.Result;
3838
}
3939

4040
public void Throw(string message)
@@ -64,7 +64,7 @@ static int Main(string[] args)
6464
.UseErrorHandler((ctx, ex) =>
6565
{
6666
(ctx?.Console.Error ?? Console.Error).WriteLine(ex.Message);
67-
return ExitCodes.Error.Result;
67+
return ExitCodes.ErrorAsync.Result;
6868
})
6969
.Run(args);
7070
}
@@ -97,7 +97,7 @@ static int Main(string[] args)
9797
catch (Exception ex)
9898
{
9999
Console.Error.WriteLine(ex.Message);
100-
return ExitCodes.Error.Result;
100+
return ExitCodes.ErrorAsync.Result;
101101
}
102102
}
103103
// end-snippet
@@ -146,7 +146,7 @@ private static int ErrorHandler(CommandContext? ctx, Exception exception)
146146
// if the exception occurred before a command could be parsed
147147
ctx?.PrintHelp();
148148

149-
return ExitCodes.Error.Result;
149+
return ExitCodes.ErrorAsync.Result;
150150
}
151151

152152
public void Throw(string message)

CommandDotNet.Example/Commands/Prompts.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ public Task<int> Intercept(InterceptorExecutionDelegate next,
2727
if (username == null)
2828
{
2929
console.Out.WriteLine("username not provided");
30-
return ExitCodes.Error;
30+
return ExitCodes.ErrorAsync;
3131
}
3232

3333
var pwd = password?.GetPassword();
3434
if (string.IsNullOrWhiteSpace(pwd))
3535
{
3636
console.Out.WriteLine("password not provided");
37-
return ExitCodes.Error;
37+
return ExitCodes.ErrorAsync;
3838
}
3939

4040
console.Out.WriteLine($"authenticated as user:{username} with password:{password} (actual password:{pwd})");

CommandDotNet.FluentValidation/FluentValidationMiddleware.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ private static Task<int> FluentValidationForModels(CommandContext ctx, Execution
9999
console.Error.WriteLine();
100100
}
101101

102-
return ExitCodes.ValidationError;
102+
return ExitCodes.ValidationErrorAsync;
103103
}
104104
}
105105
catch (InvalidValidatorException e)
106106
{
107107
ctx.Console.Error.WriteLine(e.ToString());
108-
return ExitCodes.Error;
108+
return ExitCodes.ErrorAsync;
109109
}
110110

111111
return next(ctx);

CommandDotNet.NewerReleasesAlerts/AlertOnNewerReleaseMiddleware.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics.CodeAnalysis;
23
using System.Net.Http;
34
using System.Threading.Tasks;
45
using CommandDotNet.Builders;
@@ -99,10 +100,8 @@ private static Task<int> AlertOnNewVersion(CommandContext context, ExecutionDele
99100
return next(context);
100101
}
101102

102-
private static bool TryGetCurrentVersion(out SemVersion semVersion)
103-
{
104-
return SemVersion.TryParse(AppInfo.Instance.Version, out semVersion);
105-
}
103+
private static bool TryGetCurrentVersion([NotNullWhen(true)] out SemVersion? semVersion) =>
104+
SemVersion.TryParse(AppInfo.Instance.Version, out semVersion);
106105

107106
private static bool TryGetLatestReleaseVersion(CommandContext context, NewerReleaseConfig config, out SemVersion? semVersion)
108107
{

CommandDotNet.TestTools/AppRunnerTestExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static AppRunner CaptureState(this AppRunner runner, Action<CommandContex
2525
{
2626
capture(context);
2727
return exitAfterCapture
28-
? ExitCodes.Success
28+
? ExitCodes.SuccessAsync
2929
: next(context);
3030
}, middlewareStage, orderWithinStage));
3131
}

CommandDotNet.TestTools/AssertFailedException.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,5 @@
44
namespace CommandDotNet.TestTools
55
{
66
[Serializable]
7-
public class AssertFailedException : Exception
8-
{
9-
public AssertFailedException(string message)
10-
: base(message)
11-
{
12-
}
13-
14-
protected AssertFailedException(SerializationInfo info, StreamingContext context)
15-
: base(info, context)
16-
{
17-
}
18-
}
7+
public class AssertFailedException(string message) : Exception(message);
198
}

CommandDotNet.TestTools/InvocationInfo.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@
66

77
namespace CommandDotNet.TestTools
88
{
9-
public class InvocationInfo<T> : InvocationInfo where T: class
9+
public class InvocationInfo<T>(CommandContext commandContext, InvocationStep invocationStep)
10+
: InvocationInfo(commandContext, invocationStep)
11+
where T : class
1012
{
1113
public new T? Instance => (T?)base.Instance;
12-
13-
public InvocationInfo(CommandContext commandContext, InvocationStep invocationStep)
14-
: base(commandContext, invocationStep)
15-
{
16-
}
1714
}
1815

1916
public class InvocationInfo

CommandDotNet.TestTools/TestDependencyResolver.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ public void Add(object service)
3333
_services.Add(service.GetType(), service);
3434
}
3535

36-
public void Add<T>(T? service) where T: class
36+
public void Add<T>(T? service) where T: class?
3737
{
3838
_services.Add(typeof(T), service);
3939
}
4040

41-
public void AddOrUpdate<T>(T? service) where T : class
41+
public void AddOrUpdate<T>(T? service) where T : class?
4242
{
4343
_services[typeof(T)] = service;
4444
}

CommandDotNet.TestTools/TrackingInvocation.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,21 @@
55

66
namespace CommandDotNet.TestTools
77
{
8-
internal class TrackingInvocation : IInvocation
8+
internal class TrackingInvocation(IInvocation backingInvocation) : IInvocation
99
{
10-
private readonly IInvocation _backingInvocation;
10+
private readonly IInvocation _backingInvocation = backingInvocation ?? throw new ArgumentNullException(nameof(backingInvocation));
1111

1212
public bool WasInvoked { get; private set; }
1313
public bool Errored => InvocationError != null;
1414
public Exception? InvocationError { get; private set; }
1515

1616
public IReadOnlyCollection<IArgument> Arguments => _backingInvocation.Arguments;
1717
public IReadOnlyCollection<ParameterInfo> Parameters => _backingInvocation.Parameters;
18-
public object[] ParameterValues => _backingInvocation.ParameterValues;
18+
public object?[] ParameterValues => _backingInvocation.ParameterValues;
1919
public MethodInfo MethodInfo => _backingInvocation.MethodInfo;
2020
public bool IsInterceptor => _backingInvocation.IsInterceptor;
2121
public IReadOnlyCollection<IArgumentModel> FlattenedArgumentModels => _backingInvocation.FlattenedArgumentModels;
2222

23-
public TrackingInvocation(IInvocation backingInvocation)
24-
{
25-
_backingInvocation = backingInvocation ?? throw new ArgumentNullException(nameof(backingInvocation));
26-
}
27-
2823
public object? Invoke(CommandContext commandContext, object instance, ExecutionDelegate next)
2924
{
3025
WasInvoked = true;

0 commit comments

Comments
 (0)