Skip to content

Commit acbd60f

Browse files
cleanup
1 parent 5f0b87d commit acbd60f

File tree

6 files changed

+114
-56
lines changed

6 files changed

+114
-56
lines changed

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

+3-3
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
/*
@@ -56,9 +56,9 @@ public void Help_display_can_be_disabled()
5656
5757
var result = rootCommand.Parse("oops", config);
5858
59-
if (result.Action is CliDiagnosticAction CliDiagnostic)
59+
if (result.Action is CliDiagnosticAction cliDiagnostic)
6060
{
61-
CliDiagnostic.ShowHelp = false;
61+
cliDiagnostic.ShowHelp = false;
6262
}
6363
6464
result.Invoke();

src/System.CommandLine/Parsing/CliDiagnostic.cs

+12-52
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,14 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System.Collections.Immutable;
5-
using System.Diagnostics.CodeAnalysis;
65

76
namespace System.CommandLine.Parsing;
87

9-
/*
10-
* Pattern based on:
11-
* https://github.com/mhutch/MonoDevelop.MSBuildEditor/blob/main/MonoDevelop.MSBuild/Analysis/MSBuildDiagnostic.cs
12-
* https://github.com/mhutch/MonoDevelop.MSBuildEditor/blob/main/MonoDevelop.MSBuild/Analysis/MSBuildDiagnosticDescriptor.cs
13-
* https://github.com/dotnet/roslyn/blob/main/src/Compilers/Core/Portable/Diagnostic/DiagnosticDescriptor.cs
14-
* https://github.com/dotnet/roslyn/blob/main/src/Compilers/Core/Portable/Diagnostic/Diagnostic.cs
15-
* https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/sarif-v2.1.0-errata01-os-complete.html#_Toc141791086
16-
*/
17-
internal static class ParseDiagnostics
18-
{
19-
public const string DirectiveIsNotDefinedId = "CMD0001";
20-
public static readonly CliDiagnosticDescriptor DirectiveIsNotDefined =
21-
new(
22-
DirectiveIsNotDefinedId,
23-
//TODO: use localized strings
24-
"Directive is not defined",
25-
"The directive '{0}' is not defined.",
26-
CliDiagnosticSeverity.Error,
27-
null);
28-
}
29-
30-
public sealed class CliDiagnosticDescriptor
31-
{
32-
public CliDiagnosticDescriptor(string id, string title, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string messageFormat, CliDiagnosticSeverity severity, string? helpUri)
33-
{
34-
Id = id;
35-
Title = title;
36-
MessageFormat = messageFormat;
37-
Severity = severity;
38-
HelpUri = helpUri;
39-
}
40-
41-
public string Id { get; }
42-
public string Title { get; }
43-
[StringSyntax(StringSyntaxAttribute.CompositeFormat)]
44-
public string MessageFormat { get; }
45-
public CliDiagnosticSeverity Severity { get; }
46-
public string? HelpUri { get; }
47-
}
48-
49-
public enum CliDiagnosticSeverity
50-
{
51-
Hidden = 0,
52-
Info,
53-
Warning,
54-
Error
55-
}
56-
578
/// <summary>
589
/// Describes an error that occurs while parsing command line input.
5910
/// </summary>
6011
public sealed class CliDiagnostic
6112
{
62-
// TODO: reevaluate whether we should be exposing a SymbolResult here
63-
// TODO: Rename to CliError
64-
6513
/// <summary>
6614
/// Initializes a new instance of the <see cref="CliDiagnostic"/> class.
6715
/// </summary>
@@ -70,6 +18,14 @@ public sealed class CliDiagnostic
7018
/// <param name="properties">Properties to be associated with the diagnostic.</param>
7119
/// <param name="cliSymbolResult">Contains information about a single value entered.</param>
7220
/// <param name="location">The location of the error.</param>
21+
/*
22+
* Pattern based on:
23+
* https://github.com/mhutch/MonoDevelop.MSBuildEditor/blob/main/MonoDevelop.MSBuild/Analysis/MSBuildDiagnostic.cs
24+
* https://github.com/mhutch/MonoDevelop.MSBuildEditor/blob/main/MonoDevelop.MSBuild/Analysis/MSBuildDiagnosticDescriptor.cs
25+
* https://github.com/dotnet/roslyn/blob/main/src/Compilers/Core/Portable/Diagnostic/DiagnosticDescriptor.cs
26+
* https://github.com/dotnet/roslyn/blob/main/src/Compilers/Core/Portable/Diagnostic/Diagnostic.cs
27+
* https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/sarif-v2.1.0-errata01-os-complete.html#_Toc141791086
28+
*/
7329
public CliDiagnostic(
7430
CliDiagnosticDescriptor descriptor,
7531
object?[]? messageArgs,
@@ -80,6 +36,8 @@ public CliDiagnostic(
8036
Descriptor = descriptor;
8137
MessageArgs = messageArgs;
8238
Properties = properties;
39+
CliSymbolResult = cliSymbolResult;
40+
Location = location;
8341
}
8442

8543
/// <summary>
@@ -105,6 +63,8 @@ public string Message
10563

10664
public CliSymbolResult? CliSymbolResult { get; }
10765

66+
public Location? Location { get; }
67+
10868
/// <inheritdoc />
10969
public override string ToString() => Message;
11070
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.Diagnostics.CodeAnalysis;
5+
6+
namespace System.CommandLine.Parsing;
7+
8+
/// <summary>
9+
/// Provides a description of a <see cref="CliDiagnostic"/>.
10+
/// </summary>
11+
public sealed class CliDiagnosticDescriptor
12+
{
13+
public CliDiagnosticDescriptor(string id, string title, [StringSyntax(StringSyntaxAttribute.CompositeFormat)] string messageFormat, CliDiagnosticSeverity severity, string? helpUri)
14+
{
15+
Id = id;
16+
Title = title;
17+
MessageFormat = messageFormat;
18+
Severity = severity;
19+
HelpUri = helpUri;
20+
}
21+
22+
/// <summary>
23+
/// A unique identifier for the diagnostic.
24+
/// </summary>
25+
public string Id { get; }
26+
27+
/// <summary>
28+
/// A short title describing the diagnostic.
29+
/// </summary>
30+
public string Title { get; }
31+
32+
/// <summary>
33+
/// A composite format string, which can be passed to <see cref="string.Format(string, object[])"/> to create a message.
34+
/// </summary>
35+
[StringSyntax(StringSyntaxAttribute.CompositeFormat)]
36+
public string MessageFormat { get; }
37+
38+
/// <summary>
39+
/// The severity of the diagnostic.
40+
/// </summary>
41+
public CliDiagnosticSeverity Severity { get; }
42+
43+
/// <summary>
44+
/// An optional hyperlink that provides more information about the diagnostic.
45+
/// </summary>
46+
public string? HelpUri { get; }
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace System.CommandLine.Parsing;
5+
6+
/// <summary>
7+
/// Describes how severe a <see cref="CliDiagnostic"/> is."/>
8+
/// </summary>
9+
// Pattern based on: https://github.com/dotnet/roslyn/blob/1cca63b5d8ea170f8d8e88e1574aa3ebe354c23b/src/Compilers/Core/Portable/Diagnostic/DiagnosticSeverity.cs.
10+
public enum CliDiagnosticSeverity
11+
{
12+
/// <summary>
13+
/// Something that is not surfaced through normal means.
14+
/// </summary>
15+
Hidden = 0,
16+
17+
/// <summary>
18+
/// Information that does not indicate a problem (i.e. not prescriptive).
19+
/// </summary>
20+
Info,
21+
22+
/// <summary>
23+
/// Something suspicious but allowed.
24+
/// </summary>
25+
Warning,
26+
27+
/// <summary>
28+
/// Something that is definitely wrong and needs fixing.
29+
/// </summary>
30+
Error
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace System.CommandLine.Parsing;
5+
6+
internal static class ParseDiagnostics
7+
{
8+
public const string DirectiveIsNotDefinedId = "CMD0001";
9+
public static readonly CliDiagnosticDescriptor DirectiveIsNotDefined =
10+
new(
11+
DirectiveIsNotDefinedId,
12+
//TODO: use localized strings
13+
"Directive is not defined",
14+
"The directive '{0}' is not defined.",
15+
CliDiagnosticSeverity.Error,
16+
null);
17+
}

src/System.CommandLine/System.CommandLine.csproj

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<IsPackable>true</IsPackable>
@@ -29,7 +29,10 @@
2929
<Compile Include="CliValueSymbol.cs" />
3030
<Compile Include="ICliValueSymbol.cs" />
3131
<Compile Include="Parsing\CliCommandResult.cs" />
32+
<Compile Include="Parsing\CliDiagnosticDescriptor.cs" />
33+
<Compile Include="Parsing\CliDiagnosticSeverity.cs" />
3234
<Compile Include="Parsing\CliSymbolResult.cs" />
35+
<Compile Include="Parsing\ParseDiagnostics.cs" />
3336
<Compile Include="Parsing\SymbolLookupByName.cs" />
3437
<Compile Include="Parsing\ValueResultOutcome.cs" />
3538
<Compile Include="Binding\ArgumentConversionResultType.cs" />

0 commit comments

Comments
 (0)