Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5f0b87d

Browse files
Rebasing on powderhouse
1 parent05bd9eb commit5f0b87d

17 files changed

+61
-127
lines changed

‎src/System.CommandLine.Subsystems.Tests/ErrorReportingFunctionalTests.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public void Help_display_can_be_disabled()
5656
5757
var result = rootCommand.Parse("oops", config);
5858
59-
if (result.Action isParseErrorAction parseError)
59+
if (result.Action isCliDiagnosticAction CliDiagnostic)
6060
{
61-
parseError.ShowHelp = false;
61+
CliDiagnostic.ShowHelp = false;
6262
}
6363
6464
result.Invoke();

‎src/System.CommandLine.Subsystems.Tests/ErrorReportingSubsystemTests.cs‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
usingSystem.CommandLine.Parsing;
45
usingFluentAssertions;
56
usingXunit;
6-
usingSystem.CommandLine.Parsing;
77

88
namespaceSystem.CommandLine.Subsystems.Tests;
99

@@ -12,8 +12,8 @@ public class ErrorReportingSubsystemTests
1212
[Fact]
1313
publicvoidReport_when_single_error_writes_to_console_hack()
1414
{
15-
varerror=newParseError("a sweet error message");
16-
varerrors=newList<ParseError>{error};
15+
varerror=newCliDiagnostic(new("","","a sweet error message",CliDiagnosticSeverity.Warning,null),[]);
16+
varerrors=newList<CliDiagnostic>{error};
1717
varerrorSubsystem=newErrorReportingSubsystem();
1818
varconsoleHack=newConsoleHack().RedirectToBuffer(true);
1919

@@ -25,9 +25,9 @@ public void Report_when_single_error_writes_to_console_hack()
2525
[Fact]
2626
publicvoidReport_when_multiple_error_writes_to_console_hack()
2727
{
28-
varerror=newParseError("a sweet error message");
29-
varanotherError=newParseError("another sweet error message");
30-
varerrors=newList<ParseError>{error,anotherError};
28+
varerror=newCliDiagnostic(new("","","a sweet error message",CliDiagnosticSeverity.Warning,null),[]);
29+
varanotherError=newCliDiagnostic(new("","","another sweet error message",CliDiagnosticSeverity.Warning,null),[]);
30+
varerrors=newList<CliDiagnostic>{error,anotherError};
3131
varerrorSubsystem=newErrorReportingSubsystem();
3232
varconsoleHack=newConsoleHack().RedirectToBuffer(true);
3333

@@ -39,7 +39,7 @@ public void Report_when_multiple_error_writes_to_console_hack()
3939
[Fact]
4040
publicvoidReport_when_no_errors_writes_nothing_to_console_hack()
4141
{
42-
varerrors=newList<ParseError>{};
42+
varerrors=newList<CliDiagnostic>{};
4343
varerrorSubsystem=newErrorReportingSubsystem();
4444
varconsoleHack=newConsoleHack().RedirectToBuffer(true);
4545

@@ -53,7 +53,7 @@ public void Report_when_no_errors_writes_nothing_to_console_hack()
5353
[InlineData("-non_existant_option")]
5454
publicvoidGetIsActivated_GivenInvalidInput_SubsystemIsActive(stringinput)
5555
{
56-
varrootCommand=newCliRootCommand{newCliOption<bool>("-v")};
56+
varrootCommand=newCliRootCommand{newCliOption<bool>("-v")};
5757
varconfiguration=newCliConfiguration(rootCommand);
5858
varerrorSubsystem=newErrorReportingSubsystem();
5959
IReadOnlyList<string>args=[""];

‎src/System.CommandLine.Subsystems/ErrorReportingSubsystem.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public override void Execute(PipelineResult pipelineResult)
3333
pipelineResult.SetSuccess();
3434
}
3535

36-
publicvoidReport(ConsoleHackconsoleHack,IReadOnlyList<ParseError>errors)
36+
publicvoidReport(ConsoleHackconsoleHack,IReadOnlyList<CliDiagnostic>errors)
3737
{
3838
ConsoleHelpers.ResetTerminalForegroundColor();
3939
ConsoleHelpers.SetTerminalForegroundRed();

‎src/System.CommandLine.Subsystems/PipelineResult.cs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation and contributors. All rights reserved.
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
usingSystem.CommandLine.Parsing;
@@ -9,8 +9,8 @@ namespace System.CommandLine;
99
publicclassPipelineResult
1010
{
1111
// TODO: Try to build workflow so it is illegal to create this without a ParseResult
12-
privatereadonlyList<ParseError>errors=[];
13-
privateValueProvidervalueProvider{get;}
12+
privatereadonlyList<CliDiagnostic>errors=[];
13+
privateValueProvidervalueProvider{get;}
1414

1515
publicPipelineResult(ParseResultparseResult,stringrawInput,Pipeline?pipeline,ConsoleHack?consoleHack=null)
1616
{
@@ -44,18 +44,18 @@ public PipelineResult(ParseResult parseResult, string rawInput, Pipeline? pipeli
4444
=>ParseResult.GetValueResult(valueSymbol);
4545

4646

47-
publicvoidAddErrors(IEnumerable<ParseError>errors)
47+
publicvoidAddErrors(IEnumerable<CliDiagnostic>errors)
4848
{
4949
if(errorsis notnull)
5050
{
5151
this.errors.AddRange(errors);
5252
}
5353
}
5454

55-
publicvoidAddError(ParseErrorerror)
55+
publicvoidAddError(CliDiagnosticerror)
5656
=>errors.Add(error);
5757

58-
publicIEnumerable<ParseError>GetErrors(boolexcludeParseErrors=false)
58+
publicIEnumerable<CliDiagnostic>GetErrors(boolexcludeParseErrors=false)
5959
=>excludeParseErrors||ParseResultisnull
6060
?errors
6161
:ParseResult.Errors.Concat(errors);

‎src/System.CommandLine.Subsystems/Validation/InclusiveGroupValidator.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public override void Validate(CliCommandResult commandResult,
4444
// TODO: Rework to allow localization
4545
varpluralToBe="are";
4646
varsingularToBe="is";
47-
validationContext.AddError(newParseError($"The members{string.Join(", ",groupMembers.Select(m=>m.Name))} "+
48-
$"must all be used if one is used.{string.Join(", ",missingMembers.Select(m=>m.Name))} "+
49-
$"{(missingMembers.Skip(1).Any()?pluralToBe:singularToBe)} missing."));
47+
validationContext.AddError(newCliDiagnostic(new("","","The members {groupMembers} "+
48+
"must all be used if one is used. {missingMembers} "+
49+
"{toBe} missing.",severity:CliDiagnosticSeverity.Error,null),[string.Join(", ",groupMembers.Select(m=>m.Name)),string.Join(", ",missingMembers.Select(m=>m.Name)),(missingMembers.Skip(1).Any()?pluralToBe:singularToBe)]));
5050
}
5151
}
5252
}

‎src/System.CommandLine.Subsystems/Validation/RangeValidator.cs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ public override void Validate(object? value, CliValueSymbol valueSymbol,
2424
}
2525
if(valueCondition.MustHaveValidator)
2626
{
27-
validationContext.AddError(newParseError($"Range validator missing for{valueSymbol.Name}"));
27+
validationContext.AddError(newCliDiagnostic(new("","","Range validator missing for {valueSymbol}",severity:CliDiagnosticSeverity.Error,null),[valueSymbol.Name],cliSymbolResult:valueResult));
2828
}
2929
}
30-
31-
3230
}

‎src/System.CommandLine.Subsystems/Validation/ValidationContext.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
usingSystem.CommandLine.Parsing;
55
usingSystem.CommandLine.ValueSources;
6-
usingstaticSystem.Runtime.InteropServices.JavaScript.JSType;
76

87
namespaceSystem.CommandLine.Validation;
98

@@ -24,7 +23,7 @@ internal ValidationContext(PipelineResult pipelineResult, ValidationSubsystem va
2423
/// Adds an error to the PipelineContext.
2524
/// </summary>
2625
/// <param name="error">The <see cref="ParseError"/> to add</param>
27-
publicvoidAddError(ParseErrorerror)
26+
publicvoidAddError(CliDiagnosticerror)
2827
=>pipelineResult.AddError(error);
2928

3029
/// <summary>

‎src/System.CommandLine.Subsystems/Validation/Validator.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ internal Validator(string name, Type valueConditionType, params Type[] moreValue
3131
/// <remarks>
3232
/// This method needs to be evolved as we replace ParseError with CliError
3333
/// </remarks>
34-
protectedstaticList<ParseError>AddValidationError(refList<ParseError>?parseErrors,stringmessage,IEnumerable<object?>errorValues)
34+
protectedstaticList<CliDiagnostic>AddValidationError(refList<CliDiagnostic>?parseErrors,stringmessage,IEnumerable<object?>errorValues)
3535
{
3636
// TODO: Review the handling of errors. They are currently transient and returned by the Validate method, and to avoid allocating in the case of no errors (the common case) this method is used. This adds complexity to creating a new validator.
37-
parseErrors??=newList<ParseError>();
38-
parseErrors.Add(newParseError(message));
37+
parseErrors??=newList<CliDiagnostic>();
38+
parseErrors.Add(newCliDiagnostic(new("","",message,severity:CliDiagnosticSeverity.Error,null),[]));
3939
returnparseErrors;
4040
}
4141

‎src/System.CommandLine.Subsystems/ValidationSubsystem.cs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ private void ValidateValue(CliValueSymbol valueSymbol, ValidationContext validat
8181
varvalue=validationContext.GetValue(valueSymbol);
8282
varvalueResult=validationContext.GetValueResult(valueSymbol);
8383

84-
do{
84+
do
85+
{
8586
ValidateValueCondition(value,valueSymbol,valueResult,enumerator.Current,validationContext);
8687
}while(enumerator.MoveNext());
8788
}
@@ -123,9 +124,9 @@ private void ValidateValueCondition(object? value, CliValueSymbol valueSymbol, C
123124
{
124125
if(condition.MustHaveValidator)
125126
{
126-
validationContext.AddError(newParseError($"{valueSymbol.Name} must have{condition.Name} validator."));
127+
validationContext.AddError(newCliDiagnostic(new("","","{valueSymbol} must have {condition} validator.",severity:CliDiagnosticSeverity.Error,null),[valueSymbol.Name,condition.Name],cliSymbolResult:valueResult));
127128
}
128-
return;
129+
return;
129130
}
130131
validator.Validate(value,valueSymbol,valueResult,condition,validationContext);
131132

@@ -169,7 +170,7 @@ private void ValidateCommandCondition(CliCommandResult commandResult, CommandCon
169170
{
170171
if(condition.MustHaveValidator)
171172
{
172-
validationContext.AddError(newParseError($"{commandResult.Command.Name} must have{condition.Name} validator."));
173+
validationContext.AddError(newCliDiagnostic(new("","","{commandResult} must have {condition} validator.",severity:CliDiagnosticSeverity.Error,null),[commandResult.Command.Name,condition.Name]));
173174
}
174175
return;
175176
}

‎src/System.CommandLine.Subsystems/ValueConditions/Range.cs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ internal Range(ValueSource<T>? lowerBound, ValueSource<T>? upperBound, RangeBoun
4040
LowerBound=lowerBound;
4141
UpperBound=upperBound;
4242
RangeBound=rangeBound;
43-
}
44-
43+
}
44+
4545
/// <inheritdoc/>
4646
publicvoidValidate(object?value,
4747
CliValueSymbolvalueSymbol,
@@ -59,15 +59,15 @@ public void Validate(object? value,
5959
&&validationContext.TryGetTypedValue(LowerBound,outvarlowerValue)
6060
&&comparableValue.CompareTo(lowerValue)<0)
6161
{
62-
validationContext.AddError(newParseError($"The value for '{valueSymbol.Name}' is below the lower bound of{LowerBound}"));
62+
validationContext.AddError(newCliDiagnostic(new("","","The value for '{valueSymbol}' is below the lower bound of {lowerBound}",severity:CliDiagnosticSeverity.Error,null),[valueSymbol.Name,LowerBound],cliSymbolResult:valueResult));
6363
}
6464

6565

6666
if(UpperBoundis notnull
6767
&&validationContext.TryGetTypedValue(UpperBound,outvarupperValue)
6868
&&comparableValue.CompareTo(upperValue)>0)
6969
{
70-
validationContext.AddError(newParseError($"The value for '{valueSymbol.Name}' is above the upper bound of{UpperBound}"));
70+
validationContext.AddError(newCliDiagnostic(new("","","The value for '{valueSymbol}' is above the upper bound of {upperBound}",severity:CliDiagnosticSeverity.Error,null),[valueSymbol.Name,UpperBound],cliSymbolResult:valueResult));
7171
}
7272
}
7373

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp