mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Cleanup
This commit is contained in:
@@ -19,7 +19,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption(null)]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
@@ -38,7 +38,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption(""foo"")]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
@@ -57,7 +57,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption(""foo"")]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandOption(""foo"")]
|
||||
public string Bar { get; set; }
|
||||
|
||||
@@ -41,7 +41,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption(""foo"")]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandOption(""bar"")]
|
||||
public string Bar { get; set; }
|
||||
|
||||
@@ -63,7 +63,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandOption('f')]
|
||||
public string Bar { get; set; }
|
||||
|
||||
@@ -41,7 +41,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandOption('b')]
|
||||
public string Bar { get; set; }
|
||||
|
||||
@@ -63,7 +63,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandOption('F')]
|
||||
public string Bar { get; set; }
|
||||
|
||||
@@ -85,7 +85,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption(""foo"")]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption(""foo"", Converter = typeof(MyConverter))]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
@@ -48,7 +48,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption(""foo"", Converter = typeof(MyConverter))]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
@@ -67,7 +67,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption(""foo"")]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption(""f"")]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
@@ -38,7 +38,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption(""1foo"")]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
@@ -57,7 +57,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption(""foo"")]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
@@ -76,7 +76,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption('1')]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
@@ -38,7 +38,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
@@ -57,7 +57,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption(""foo"")]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption(""foo"", Validators = new[] {typeof(MyValidator)})]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
@@ -48,7 +48,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption(""foo"", Validators = new[] {typeof(MyValidator)})]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
@@ -67,7 +67,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandOption(""foo"")]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ public class ParameterMustBeLastIfNonScalarAnalyzerSpecs
|
||||
private static DiagnosticAnalyzer Analyzer { get; } = new ParameterMustBeLastIfNonScalarAnalyzer();
|
||||
|
||||
[Fact]
|
||||
public void Analyzer_reports_an_error_if_a_non_scalar_parameter_is_not_last_in_order()
|
||||
public void Analyzer_reports_an_error_if_a_non_scalar_parameter_is_not_the_last_in_order()
|
||||
{
|
||||
// Arrange
|
||||
// language=cs
|
||||
@@ -19,7 +19,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandParameter(0)]
|
||||
public string[] Foo { get; set; }
|
||||
|
||||
|
||||
[CommandParameter(1)]
|
||||
public string Bar { get; set; }
|
||||
|
||||
@@ -31,7 +31,7 @@ public class MyCommand : ICommand
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Analyzer_does_not_report_an_error_if_a_non_scalar_parameter_is_last_in_order()
|
||||
public void Analyzer_does_not_report_an_error_if_a_non_scalar_parameter_is_the_last_in_order()
|
||||
{
|
||||
// Arrange
|
||||
// language=cs
|
||||
@@ -41,7 +41,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandParameter(0)]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandParameter(1)]
|
||||
public string[] Bar { get; set; }
|
||||
|
||||
@@ -63,7 +63,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandParameter(0)]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandParameter(1)]
|
||||
public string Bar { get; set; }
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ public class ParameterMustBeLastIfNotRequiredAnalyzerSpecs
|
||||
private static DiagnosticAnalyzer Analyzer { get; } = new ParameterMustBeLastIfNotRequiredAnalyzer();
|
||||
|
||||
[Fact]
|
||||
public void Analyzer_reports_an_error_if_a_parameter_is_not_required_and_is_not_last_parameter()
|
||||
public void Analyzer_reports_an_error_if_a_non_required_parameter_is_not_the_last_in_order()
|
||||
{
|
||||
// Arrange
|
||||
// language=cs
|
||||
@@ -19,7 +19,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandParameter(0, Name = ""foo"", IsRequired = false)]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandParameter(1, Name = ""bar"", IsRequired = false)]
|
||||
public string Bar { get; set; }
|
||||
|
||||
@@ -31,7 +31,7 @@ public class MyCommand : ICommand
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Analyzer_does_not_report_an_error_if_isRequired_is_false_on_last_parameter()
|
||||
public void Analyzer_does_not_report_an_error_if_a_non_required_parameter_is_the_last_in_order()
|
||||
{
|
||||
// Arrange
|
||||
// language=cs
|
||||
@@ -41,7 +41,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandParameter(0, Name = ""foo"", IsRequired = true)]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandParameter(1, Name = ""bar"", IsRequired = false)]
|
||||
public string Bar { get; set; }
|
||||
|
||||
@@ -53,7 +53,7 @@ public class MyCommand : ICommand
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Analyzer_does_not_report_an_error_on_a_property_when_isRequired_is_not_set()
|
||||
public void Analyzer_does_not_report_an_error_if_no_non_required_parameters_are_defined()
|
||||
{
|
||||
// Arrange
|
||||
// language=cs
|
||||
@@ -63,8 +63,8 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandParameter(0, Name = ""foo"")]
|
||||
public string Foo { get; set; }
|
||||
|
||||
[CommandParameter(1, Name = ""bar"")]
|
||||
|
||||
[CommandParameter(1, Name = ""bar"", IsRequired = true)]
|
||||
public string Bar { get; set; }
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
@@ -73,4 +73,22 @@ public class MyCommand : ICommand
|
||||
// Act & assert
|
||||
Analyzer.Should().NotProduceDiagnostics(code);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Analyzer_does_not_report_an_error_on_a_property_that_is_not_a_parameter()
|
||||
{
|
||||
// Arrange
|
||||
// language=cs
|
||||
const string code = @"
|
||||
[Command]
|
||||
public class MyCommand : ICommand
|
||||
{
|
||||
public string Foo { get; set; }
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
// Act & assert
|
||||
Analyzer.Should().NotProduceDiagnostics(code);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandParameter(0)]
|
||||
public string[] Foo { get; set; }
|
||||
|
||||
|
||||
[CommandParameter(1)]
|
||||
public string[] Bar { get; set; }
|
||||
|
||||
@@ -41,7 +41,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandParameter(0)]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandParameter(1)]
|
||||
public string[] Bar { get; set; }
|
||||
|
||||
@@ -63,7 +63,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandParameter(0)]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandParameter(1)]
|
||||
public string Bar { get; set; }
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandParameter(0, Name = ""foo"")]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandParameter(1, Name = ""foo"")]
|
||||
public string Bar { get; set; }
|
||||
|
||||
@@ -41,7 +41,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandParameter(0, Name = ""foo"")]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandParameter(1, Name = ""bar"")]
|
||||
public string Bar { get; set; }
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandParameter(0)]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandParameter(0)]
|
||||
public string Bar { get; set; }
|
||||
|
||||
@@ -41,7 +41,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandParameter(0)]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandParameter(1)]
|
||||
public string Bar { get; set; }
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandParameter(0, Converter = typeof(MyConverter))]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
@@ -48,7 +48,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandParameter(0, Converter = typeof(MyConverter))]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
@@ -67,7 +67,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandParameter(0)]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandParameter(0, Validators = new[] {typeof(MyValidator)})]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
@@ -48,7 +48,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandParameter(0, Validators = new[] {typeof(MyValidator)})]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
@@ -67,7 +67,7 @@ public class MyCommand : ICommand
|
||||
{
|
||||
[CommandParameter(0)]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}";
|
||||
|
||||
|
||||
@@ -71,10 +71,9 @@ internal partial class CommandOptionSymbol
|
||||
{
|
||||
var attribute = TryGetOptionAttribute(property);
|
||||
|
||||
if (attribute is null)
|
||||
return null;
|
||||
|
||||
return FromAttribute(attribute);
|
||||
return attribute is not null
|
||||
? FromAttribute(attribute)
|
||||
: null;
|
||||
}
|
||||
|
||||
public static bool IsOptionProperty(IPropertySymbol property) =>
|
||||
|
||||
@@ -10,9 +10,9 @@ internal partial class CommandParameterSymbol
|
||||
public int Order { get; }
|
||||
|
||||
public string? Name { get; }
|
||||
|
||||
|
||||
public bool? IsRequired { get; }
|
||||
|
||||
|
||||
public ITypeSymbol? ConverterType { get; }
|
||||
|
||||
public IReadOnlyList<ITypeSymbol> ValidatorTypes { get; }
|
||||
@@ -41,7 +41,7 @@ internal partial class CommandParameterSymbol
|
||||
|
||||
private static CommandParameterSymbol FromAttribute(AttributeData attribute)
|
||||
{
|
||||
var order = (int) attribute
|
||||
var order = (int)attribute
|
||||
.ConstructorArguments
|
||||
.Select(a => a.Value)
|
||||
.First()!;
|
||||
@@ -51,7 +51,7 @@ internal partial class CommandParameterSymbol
|
||||
.Where(a => a.Key == "Name")
|
||||
.Select(a => a.Value.Value)
|
||||
.FirstOrDefault() as string;
|
||||
|
||||
|
||||
var isRequired = attribute
|
||||
.NamedArguments
|
||||
.Where(a => a.Key == "IsRequired")
|
||||
|
||||
@@ -12,8 +12,8 @@ public class ParameterMustBeLastIfNonScalarAnalyzer : AnalyzerBase
|
||||
{
|
||||
public ParameterMustBeLastIfNonScalarAnalyzer()
|
||||
: base(
|
||||
"Parameters of non-scalar types must be last in order",
|
||||
"This parameter has a non-scalar type so it must be last in order (its order must be highest within the command).")
|
||||
"Parameters of non-scalar types must be the last in order",
|
||||
"This parameter has a non-scalar type so it must be the last in order (its order must be highest within the command).")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using CliFx.Analyzers.ObjectModel;
|
||||
using CliFx.Analyzers.Utils.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
@@ -13,8 +12,8 @@ public class ParameterMustBeLastIfNotRequiredAnalyzer : AnalyzerBase
|
||||
{
|
||||
public ParameterMustBeLastIfNotRequiredAnalyzer()
|
||||
: base(
|
||||
"Only last parameter can be optional",
|
||||
"IsRequired can only be set to false on the last parameter.")
|
||||
"Parameters marked as non-required must be the last in order",
|
||||
"This parameter is non-required so it must be the last in order (its order must be highest within the command).")
|
||||
{
|
||||
}
|
||||
|
||||
@@ -27,10 +26,12 @@ public class ParameterMustBeLastIfNotRequiredAnalyzer : AnalyzerBase
|
||||
return;
|
||||
|
||||
var parameter = CommandParameterSymbol.TryResolve(property);
|
||||
|
||||
if (parameter is null || parameter.IsRequired != false)
|
||||
if (parameter is null)
|
||||
return;
|
||||
|
||||
|
||||
if (parameter.IsRequired != false)
|
||||
return;
|
||||
|
||||
var otherProperties = property
|
||||
.ContainingType
|
||||
.GetMembers()
|
||||
@@ -44,7 +45,7 @@ public class ParameterMustBeLastIfNotRequiredAnalyzer : AnalyzerBase
|
||||
if (otherParameter is null)
|
||||
continue;
|
||||
|
||||
if (parameter.IsRequired is false && parameter.Order < otherParameter.Order)
|
||||
if (otherParameter.Order > parameter.Order)
|
||||
{
|
||||
context.ReportDiagnostic(CreateDiagnostic(propertyDeclaration.GetLocation()));
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public bool Foo { get; set; }
|
||||
|
||||
|
||||
[CommandOption('b')]
|
||||
public bool Bar { get; set; }
|
||||
|
||||
@@ -379,7 +379,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public int? Foo { get; set; }
|
||||
|
||||
|
||||
[CommandOption('b')]
|
||||
public int? Bar { get; set; }
|
||||
|
||||
@@ -427,7 +427,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public CustomEnum? Foo { get; set; }
|
||||
|
||||
|
||||
[CommandOption('b')]
|
||||
public CustomEnum? Bar { get; set; }
|
||||
|
||||
@@ -471,7 +471,7 @@ public class Command : ICommand
|
||||
public class CustomType
|
||||
{
|
||||
public string Value { get; }
|
||||
|
||||
|
||||
public CustomType(string value) => Value = value;
|
||||
}
|
||||
|
||||
@@ -480,7 +480,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public CustomType Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
console.Output.WriteLine(Foo.Value);
|
||||
@@ -516,9 +516,9 @@ public class Command : ICommand
|
||||
public class CustomTypeA
|
||||
{
|
||||
public string Value { get; }
|
||||
|
||||
|
||||
private CustomTypeA(string value) => Value = value;
|
||||
|
||||
|
||||
public static CustomTypeA Parse(string value) =>
|
||||
new CustomTypeA(value);
|
||||
}
|
||||
@@ -526,9 +526,9 @@ public class CustomTypeA
|
||||
public class CustomTypeB
|
||||
{
|
||||
public string Value { get; }
|
||||
|
||||
|
||||
private CustomTypeB(string value) => Value = value;
|
||||
|
||||
|
||||
public static CustomTypeB Parse(string value, IFormatProvider formatProvider) =>
|
||||
new CustomTypeB(value);
|
||||
}
|
||||
@@ -538,10 +538,10 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public CustomTypeA Foo { get; set; }
|
||||
|
||||
|
||||
[CommandOption('b')]
|
||||
public CustomTypeB Bar { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
console.Output.WriteLine(""Foo = "" + Foo.Value);
|
||||
@@ -590,7 +590,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption('f', Converter = typeof(CustomConverter))]
|
||||
public int Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
console.Output.WriteLine(Foo);
|
||||
@@ -628,7 +628,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public string[] Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
foreach (var i in Foo)
|
||||
@@ -672,7 +672,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public IReadOnlyList<string> Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
foreach (var i in Foo)
|
||||
@@ -716,7 +716,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public List<string> Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
foreach (var i in Foo)
|
||||
@@ -760,7 +760,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public int[] Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
foreach (var i in Foo)
|
||||
@@ -804,7 +804,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public int Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}
|
||||
");
|
||||
@@ -840,7 +840,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public CustomType Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}
|
||||
");
|
||||
@@ -872,7 +872,7 @@ public class Command : ICommand
|
||||
public class CustomType : IEnumerable<object>
|
||||
{
|
||||
public IEnumerator<object> GetEnumerator() => Enumerable.Empty<object>().GetEnumerator();
|
||||
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
}
|
||||
|
||||
@@ -881,7 +881,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public CustomType Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}
|
||||
");
|
||||
@@ -925,7 +925,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption('f', Validators = new[] {typeof(ValidatorA), typeof(ValidatorB)})]
|
||||
public int Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}
|
||||
");
|
||||
@@ -957,9 +957,9 @@ public class Command : ICommand
|
||||
public class CustomType
|
||||
{
|
||||
public string Value { get; }
|
||||
|
||||
|
||||
private CustomType(string value) => Value = value;
|
||||
|
||||
|
||||
public static CustomType Parse(string value) => throw new Exception(""Hello world"");
|
||||
}
|
||||
|
||||
@@ -968,7 +968,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public CustomType Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}
|
||||
");
|
||||
|
||||
@@ -31,7 +31,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption(""foo"", IsRequired = true, EnvironmentVariable = ""ENV_FOO"")]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
console.Output.WriteLine(Foo);
|
||||
@@ -73,7 +73,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption(""foo"", EnvironmentVariable = ""ENV_FOO"")]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
console.Output.WriteLine(Foo);
|
||||
@@ -115,12 +115,12 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption(""foo"", EnvironmentVariable = ""ENV_FOO"")]
|
||||
public IReadOnlyList<string> Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
foreach (var i in Foo)
|
||||
console.Output.WriteLine(i);
|
||||
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
@@ -162,7 +162,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption(""foo"", EnvironmentVariable = ""ENV_FOO"")]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
console.Output.WriteLine(Foo);
|
||||
@@ -204,7 +204,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption(""foo"", EnvironmentVariable = ""ENV_FOO"")]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
console.Output.WriteLine(Foo);
|
||||
|
||||
@@ -339,13 +339,13 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandParameter(0)]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandParameter(1)]
|
||||
public string Bar { get; set; }
|
||||
|
||||
|
||||
[CommandParameter(2)]
|
||||
public IReadOnlyList<string> Baz { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}
|
||||
");
|
||||
@@ -396,7 +396,7 @@ public class Command : CommandBase
|
||||
|
||||
[CommandParameter(1)]
|
||||
public string Bar { get; set; }
|
||||
|
||||
|
||||
public override ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}
|
||||
");
|
||||
@@ -434,13 +434,13 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption(""foo"", IsRequired = true)]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandOption(""bar"")]
|
||||
public string Bar { get; set; }
|
||||
|
||||
|
||||
[CommandOption(""baz"", IsRequired = true)]
|
||||
public IReadOnlyList<string> Baz { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}
|
||||
");
|
||||
@@ -478,10 +478,10 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandParameter(0, Name = ""foo"", Description = ""Description of foo."")]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandOption(""bar"", Description = ""Description of bar."")]
|
||||
public string Bar { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}
|
||||
");
|
||||
@@ -597,10 +597,10 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandParameter(0)]
|
||||
public CustomEnum Foo { get; set; }
|
||||
|
||||
|
||||
[CommandOption(""bar"")]
|
||||
public CustomEnum Bar { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}
|
||||
");
|
||||
@@ -732,10 +732,10 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption(""foo"", EnvironmentVariable = ""ENV_FOO"")]
|
||||
public CustomEnum Foo { get; set; }
|
||||
|
||||
|
||||
[CommandOption(""bar"", EnvironmentVariable = ""ENV_BAR"")]
|
||||
public CustomEnum Bar { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}
|
||||
");
|
||||
@@ -794,10 +794,10 @@ public class Command : ICommand
|
||||
|
||||
[CommandOption(""lol"")]
|
||||
public CustomEnum Lol { get; set; } = CustomEnum.Two;
|
||||
|
||||
|
||||
[CommandOption(""hmm"", IsRequired = true)]
|
||||
public string Hmm { get; set; } = ""not printed"";
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}
|
||||
");
|
||||
|
||||
@@ -28,7 +28,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption(""foo"")]
|
||||
public bool Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
console.Output.WriteLine(Foo);
|
||||
@@ -66,7 +66,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public bool Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
console.Output.WriteLine(Foo);
|
||||
@@ -104,10 +104,10 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption(""foo"")]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandOption(""bar"")]
|
||||
public string Bar { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
console.Output.WriteLine(""Foo = "" + Foo);
|
||||
@@ -150,10 +150,10 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandOption('b')]
|
||||
public string Bar { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
console.Output.WriteLine(""Foo = "" + Foo);
|
||||
@@ -196,10 +196,10 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandOption('b')]
|
||||
public string Bar { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
console.Output.WriteLine(""Foo = "" + Foo);
|
||||
@@ -242,7 +242,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption(""Foo"")]
|
||||
public IReadOnlyList<string> Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
foreach (var i in Foo)
|
||||
@@ -286,7 +286,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public IReadOnlyList<string> Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
foreach (var i in Foo)
|
||||
@@ -330,7 +330,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption(""foo"")]
|
||||
public IReadOnlyList<string> Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
foreach (var i in Foo)
|
||||
@@ -374,7 +374,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption('f')]
|
||||
public IReadOnlyList<string> Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
foreach (var i in Foo)
|
||||
@@ -418,7 +418,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption(""foo"", 'f')]
|
||||
public IReadOnlyList<string> Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
foreach (var i in Foo)
|
||||
@@ -462,10 +462,10 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption(""foo"")]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandOption(""bar"")]
|
||||
public string Bar { get; set; } = ""hello"";
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
console.Output.WriteLine(""Foo = "" + Foo);
|
||||
@@ -506,7 +506,7 @@ public class Command : ICommand
|
||||
public static class SharedContext
|
||||
{
|
||||
public static int Foo { get; set; }
|
||||
|
||||
|
||||
public static bool Bar { get; set; }
|
||||
}
|
||||
|
||||
@@ -585,7 +585,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption(""foo"")]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
console.Output.WriteLine(Foo);
|
||||
@@ -624,7 +624,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption(""foo"", IsRequired = true)]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}");
|
||||
|
||||
@@ -658,7 +658,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption(""foo"", IsRequired = true)]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}");
|
||||
|
||||
@@ -692,7 +692,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption(""foo"", IsRequired = true)]
|
||||
public IReadOnlyList<string> Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}");
|
||||
|
||||
@@ -726,7 +726,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption(""foo"")]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}");
|
||||
|
||||
@@ -760,7 +760,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandOption(""foo"")]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}");
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandParameter(0)]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandParameter(1)]
|
||||
public string Bar { get; set; }
|
||||
|
||||
@@ -35,7 +35,7 @@ public class Command : ICommand
|
||||
{
|
||||
console.Output.WriteLine(""Foo = "" + Foo);
|
||||
console.Output.WriteLine(""Bar = "" + Bar);
|
||||
|
||||
|
||||
return default;
|
||||
}
|
||||
}");
|
||||
@@ -73,13 +73,13 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandParameter(0)]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandParameter(1)]
|
||||
public string Bar { get; set; }
|
||||
|
||||
|
||||
[CommandParameter(2)]
|
||||
public IReadOnlyList<string> Baz { get; set; }
|
||||
|
||||
|
||||
[CommandOption(""boo"")]
|
||||
public string Boo { get; set; }
|
||||
|
||||
@@ -87,10 +87,10 @@ public class Command : ICommand
|
||||
{
|
||||
console.Output.WriteLine(""Foo = "" + Foo);
|
||||
console.Output.WriteLine(""Bar = "" + Bar);
|
||||
|
||||
|
||||
foreach (var i in Baz)
|
||||
console.Output.WriteLine(""Baz = "" + i);
|
||||
|
||||
|
||||
return default;
|
||||
}
|
||||
}");
|
||||
@@ -131,7 +131,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandParameter(0)]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandParameter(1)]
|
||||
public string Bar { get; set; }
|
||||
|
||||
@@ -168,10 +168,10 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandParameter(0)]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandParameter(1)]
|
||||
public IReadOnlyList<string> Bar { get; set; }
|
||||
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||
}");
|
||||
|
||||
@@ -205,7 +205,7 @@ public class Command : ICommand
|
||||
{
|
||||
[CommandParameter(0)]
|
||||
public string Foo { get; set; }
|
||||
|
||||
|
||||
[CommandParameter(1)]
|
||||
public string Bar { get; set; }
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public sealed class CommandOptionAttribute : Attribute
|
||||
public char? ShortName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether this option is required.
|
||||
/// Whether this option is required (default: <c>false</c>).
|
||||
/// If an option is required, the user will get an error if they don't set it.
|
||||
/// </summary>
|
||||
public bool IsRequired { get; set; }
|
||||
|
||||
@@ -11,23 +11,24 @@ public sealed class CommandParameterAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Parameter order.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Higher order means the parameter appears later, lower order means
|
||||
/// it appears earlier.
|
||||
///
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// All parameters in a command must have unique order.
|
||||
///
|
||||
/// Parameter whose type is a non-scalar (e.g. array), must always be the last in order.
|
||||
/// Only one non-scalar parameter is allowed in a command.
|
||||
/// </remarks>
|
||||
public int Order { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Whether this parameter is required. (default: true)
|
||||
/// Whether this parameter is required (default: <c>true</c>).
|
||||
/// If a parameter is required, the user will get an error if they don't set it.
|
||||
/// Only the last parameter in order can be optional.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Parameter marked as non-required must always be the last in order.
|
||||
/// Only one non-required parameter is allowed in a command.
|
||||
/// </remarks>
|
||||
public bool IsRequired { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -82,7 +82,7 @@ public interface IConsole
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
CancellationToken RegisterCancellationHandler();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Clears the console buffer and corresponding console window of display information.
|
||||
/// </summary>
|
||||
|
||||
@@ -33,7 +33,7 @@ internal class BindablePropertyDescriptor : IPropertyDescriptor
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
var underlyingType = GetUnderlyingType(Type);
|
||||
|
||||
// We can only get valid values for enums
|
||||
|
||||
@@ -13,27 +13,28 @@ internal partial class ParameterSchema : IMemberSchema
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public string? Description { get; }
|
||||
|
||||
public bool IsRequired { get; }
|
||||
|
||||
|
||||
public string? Description { get; }
|
||||
|
||||
public Type? ConverterType { get; }
|
||||
|
||||
public IReadOnlyList<Type> ValidatorTypes { get; }
|
||||
|
||||
public ParameterSchema(IPropertyDescriptor property,
|
||||
public ParameterSchema(
|
||||
IPropertyDescriptor property,
|
||||
int order,
|
||||
string name,
|
||||
string? description,
|
||||
bool isRequired,
|
||||
string? description,
|
||||
Type? converterType,
|
||||
IReadOnlyList<Type> validatorTypes)
|
||||
{
|
||||
Property = property;
|
||||
Order = order;
|
||||
Name = name;
|
||||
Description = description;
|
||||
IsRequired = isRequired;
|
||||
Description = description;
|
||||
ConverterType = converterType;
|
||||
ValidatorTypes = validatorTypes;
|
||||
}
|
||||
@@ -58,8 +59,8 @@ internal partial class ParameterSchema
|
||||
new BindablePropertyDescriptor(property),
|
||||
attribute.Order,
|
||||
name,
|
||||
description,
|
||||
attribute.IsRequired,
|
||||
description,
|
||||
attribute.Converter,
|
||||
attribute.Validators
|
||||
);
|
||||
|
||||
@@ -32,7 +32,6 @@ internal static partial class PolyfillExtensions
|
||||
stream.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
|
||||
|
||||
namespace System.Linq
|
||||
{
|
||||
internal static class PolyfillExtensions
|
||||
|
||||
@@ -226,7 +226,7 @@ Similarly, unseparated arguments in the form of `myapp -ofile` will be treated a
|
||||
|
||||
Because of these rules, order of arguments is semantically important and must always follow this pattern:
|
||||
|
||||
```ini
|
||||
```txt
|
||||
[directives] [command name] [parameters] [options]
|
||||
```
|
||||
|
||||
@@ -596,7 +596,7 @@ public async Task ConcatCommand_executes_successfully()
|
||||
|
||||
// Act
|
||||
await command.ExecuteAsync(console);
|
||||
|
||||
|
||||
var stdOut = console.ReadOutputString();
|
||||
|
||||
// Assert
|
||||
@@ -624,7 +624,7 @@ public async Task ConcatCommand_executes_successfully()
|
||||
|
||||
// Act
|
||||
await app.RunAsync(args, envVars);
|
||||
|
||||
|
||||
var stdOut = console.ReadOutputString();
|
||||
|
||||
// Assert
|
||||
|
||||
Reference in New Issue
Block a user