mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Use raw string literals
This commit is contained in:
@@ -13,11 +13,13 @@ public class CommandMustBeAnnotatedAnalyzerSpecs
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public class MyCommand : ICommand
|
"""
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
{
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -28,12 +30,14 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public abstract class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public abstract class MyCommand : ICommand
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
{
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -44,11 +48,13 @@ public abstract class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public abstract class MyCommand : ICommand
|
"""
|
||||||
{
|
public abstract class MyCommand : ICommand
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
{
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -59,11 +65,13 @@ public abstract class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public class Foo
|
"""
|
||||||
{
|
public class Foo
|
||||||
public int Bar { get; set; } = 5;
|
{
|
||||||
}";
|
public int Bar { get; set; } = 5;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
|
|||||||
@@ -13,12 +13,14 @@ public class CommandMustImplementInterfaceAnalyzerSpecs
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand
|
[Command]
|
||||||
{
|
public class MyCommand
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
{
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -29,12 +31,14 @@ public class MyCommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
{
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -45,11 +49,13 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public class Foo
|
"""
|
||||||
{
|
public class Foo
|
||||||
public int Bar { get; set; } = 5;
|
{
|
||||||
}";
|
public int Bar { get; set; } = 5;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
|
|||||||
@@ -13,12 +13,14 @@ public class OptionMustBeInsideCommandAnalyzerSpecs
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public class MyClass
|
"""
|
||||||
{
|
public class MyClass
|
||||||
[CommandOption(""foo"")]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption("foo")]
|
||||||
}";
|
public string Foo { get; set; }
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -29,15 +31,17 @@ public class MyClass
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption(""foo"")]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption("foo")]
|
||||||
|
public string Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
}";
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -48,12 +52,14 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public abstract class MyCommand
|
"""
|
||||||
{
|
public abstract class MyCommand
|
||||||
[CommandOption(""foo"")]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption("foo")]
|
||||||
}";
|
public string Foo { get; set; }
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -64,14 +70,16 @@ public abstract class MyCommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public string Foo { get; set; }
|
{
|
||||||
|
public string Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
}";
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
|
|||||||
@@ -13,15 +13,17 @@ public class OptionMustHaveNameOrShortNameAnalyzerSpecs
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption(null)]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption(null)]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -32,15 +34,17 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption(""foo"")]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption("foo")]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -51,15 +55,17 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption('f')]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption('f')]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -70,14 +76,16 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public string Foo { get; set; }
|
{
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
|
|||||||
@@ -13,18 +13,20 @@ public class OptionMustHaveUniqueNameAnalyzerSpecs
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption(""foo"")]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption("foo")]
|
||||||
|
public string Foo { get; set; }
|
||||||
[CommandOption(""foo"")]
|
|
||||||
public string Bar { get; set; }
|
[CommandOption("foo")]
|
||||||
|
public string Bar { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -35,18 +37,20 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption(""foo"")]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption("foo")]
|
||||||
|
public string Foo { get; set; }
|
||||||
[CommandOption(""bar"")]
|
|
||||||
public string Bar { get; set; }
|
[CommandOption("bar")]
|
||||||
|
public string Bar { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -57,15 +61,17 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption('f')]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption('f')]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -76,14 +82,16 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public string Foo { get; set; }
|
{
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
|
|||||||
@@ -13,18 +13,20 @@ public class OptionMustHaveUniqueShortNameAnalyzerSpecs
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption('f')]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption('f')]
|
||||||
|
public string Foo { get; set; }
|
||||||
[CommandOption('f')]
|
|
||||||
public string Bar { get; set; }
|
[CommandOption('f')]
|
||||||
|
public string Bar { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -35,18 +37,20 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption('f')]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption('f')]
|
||||||
|
public string Foo { get; set; }
|
||||||
[CommandOption('b')]
|
|
||||||
public string Bar { get; set; }
|
[CommandOption('b')]
|
||||||
|
public string Bar { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -57,18 +61,20 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption('f')]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption('f')]
|
||||||
|
public string Foo { get; set; }
|
||||||
[CommandOption('F')]
|
|
||||||
public string Bar { get; set; }
|
[CommandOption('F')]
|
||||||
|
public string Bar { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -79,15 +85,17 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption(""foo"")]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption("foo")]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -98,14 +106,16 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public string Foo { get; set; }
|
{
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
|
|||||||
@@ -13,20 +13,22 @@ public class OptionMustHaveValidConverterAnalyzerSpecs
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public class MyConverter
|
"""
|
||||||
{
|
public class MyConverter
|
||||||
public string Convert(string rawValue) => rawValue;
|
{
|
||||||
}
|
public string Convert(string rawValue) => rawValue;
|
||||||
|
}
|
||||||
[Command]
|
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption(""foo"", Converter = typeof(MyConverter))]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption("foo", Converter = typeof(MyConverter))]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -37,20 +39,22 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public class MyConverter : BindingConverter<int>
|
"""
|
||||||
{
|
public class MyConverter : BindingConverter<int>
|
||||||
public override int Convert(string rawValue) => 42;
|
{
|
||||||
}
|
public override int Convert(string rawValue) => 42;
|
||||||
|
}
|
||||||
[Command]
|
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption(""foo"", Converter = typeof(MyConverter))]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption("foo", Converter = typeof(MyConverter))]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -61,20 +65,22 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public class MyConverter : BindingConverter<string>
|
"""
|
||||||
{
|
public class MyConverter : BindingConverter<string>
|
||||||
public override string Convert(string rawValue) => rawValue;
|
{
|
||||||
}
|
public override string Convert(string rawValue) => rawValue;
|
||||||
|
}
|
||||||
[Command]
|
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption(""foo"", Converter = typeof(MyConverter))]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption("foo", Converter = typeof(MyConverter))]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -85,20 +91,22 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public class MyConverter : BindingConverter<int>
|
"""
|
||||||
{
|
public class MyConverter : BindingConverter<int>
|
||||||
public override int Convert(string rawValue) => 42;
|
{
|
||||||
}
|
public override int Convert(string rawValue) => 42;
|
||||||
|
}
|
||||||
[Command]
|
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption(""foo"", Converter = typeof(MyConverter))]
|
{
|
||||||
public int? Foo { get; set; }
|
[CommandOption("foo", Converter = typeof(MyConverter))]
|
||||||
|
public int? Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -109,20 +117,22 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public class MyConverter : BindingConverter<string>
|
"""
|
||||||
{
|
public class MyConverter : BindingConverter<string>
|
||||||
public override string Convert(string rawValue) => rawValue;
|
{
|
||||||
}
|
public override string Convert(string rawValue) => rawValue;
|
||||||
|
}
|
||||||
[Command]
|
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption(""foo"", Converter = typeof(MyConverter))]
|
{
|
||||||
public IReadOnlyList<string> Foo { get; set; }
|
[CommandOption("foo", Converter = typeof(MyConverter))]
|
||||||
|
public IReadOnlyList<string> Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -133,15 +143,17 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption(""foo"")]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption("foo")]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -152,14 +164,16 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public string Foo { get; set; }
|
{
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
|
|||||||
@@ -13,15 +13,17 @@ public class OptionMustHaveValidNameAnalyzerSpecs
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption(""f"")]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption("f")]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -32,15 +34,17 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption(""1foo"")]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption("1foo")]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -51,15 +55,17 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption(""foo"")]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption("foo")]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -70,15 +76,17 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption('f')]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption('f')]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -89,14 +97,16 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public string Foo { get; set; }
|
{
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
|
|||||||
@@ -13,15 +13,17 @@ public class OptionMustHaveValidShortNameAnalyzerSpecs
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption('1')]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption('1')]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -32,15 +34,17 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption('f')]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption('f')]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -51,15 +55,17 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption(""foo"")]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption("foo")]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -70,14 +76,16 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public string Foo { get; set; }
|
{
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
|
|||||||
@@ -13,20 +13,22 @@ public class OptionMustHaveValidValidatorsAnalyzerSpecs
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public class MyValidator
|
"""
|
||||||
{
|
public class MyValidator
|
||||||
public void Validate(string value) {}
|
{
|
||||||
}
|
public void Validate(string value) {}
|
||||||
|
}
|
||||||
[Command]
|
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption(""foo"", Validators = new[] {typeof(MyValidator)})]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption("foo", Validators = new[] {typeof(MyValidator)})]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -37,20 +39,22 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public class MyValidator : BindingValidator<int>
|
"""
|
||||||
{
|
public class MyValidator : BindingValidator<int>
|
||||||
public override BindingValidationError Validate(int value) => Ok();
|
{
|
||||||
}
|
public override BindingValidationError Validate(int value) => Ok();
|
||||||
|
}
|
||||||
[Command]
|
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption(""foo"", Validators = new[] {typeof(MyValidator)})]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption("foo", Validators = new[] {typeof(MyValidator)})]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -61,20 +65,22 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public class MyValidator : BindingValidator<string>
|
"""
|
||||||
{
|
public class MyValidator : BindingValidator<string>
|
||||||
public override BindingValidationError Validate(string value) => Ok();
|
{
|
||||||
}
|
public override BindingValidationError Validate(string value) => Ok();
|
||||||
|
}
|
||||||
[Command]
|
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption(""foo"", Validators = new[] {typeof(MyValidator)})]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption("foo", Validators = new[] {typeof(MyValidator)})]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -85,15 +91,17 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption(""foo"")]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandOption("foo")]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -104,14 +112,16 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public string Foo { get; set; }
|
{
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
|
|||||||
@@ -13,12 +13,14 @@ public class ParameterMustBeInsideCommandAnalyzerSpecs
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public class MyClass
|
"""
|
||||||
{
|
public class MyClass
|
||||||
[CommandParameter(0)]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0)]
|
||||||
}";
|
public string Foo { get; set; }
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -29,15 +31,17 @@ public class MyClass
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0)]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0)]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -48,12 +52,14 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public abstract class MyCommand
|
"""
|
||||||
{
|
public abstract class MyCommand
|
||||||
[CommandParameter(0)]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0)]
|
||||||
}";
|
public string Foo { get; set; }
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -64,14 +70,16 @@ public abstract class MyCommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public string Foo { get; set; }
|
{
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
|
|||||||
@@ -13,18 +13,20 @@ public class ParameterMustBeLastIfNonRequiredAnalyzerSpecs
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0, Name = ""foo"", IsRequired = false)]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0, Name = "foo", IsRequired = false)]
|
||||||
|
public string Foo { get; set; }
|
||||||
[CommandParameter(1, Name = ""bar"")]
|
|
||||||
public string Bar { get; set; }
|
[CommandParameter(1, Name = "bar")]
|
||||||
|
public string Bar { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -35,18 +37,20 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0, Name = ""foo"")]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0, Name = "foo")]
|
||||||
|
public string Foo { get; set; }
|
||||||
[CommandParameter(1, Name = ""bar"", IsRequired = false)]
|
|
||||||
public string Bar { get; set; }
|
[CommandParameter(1, Name = "bar", IsRequired = false)]
|
||||||
|
public string Bar { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -57,18 +61,20 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0, Name = ""foo"")]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0, Name = "foo")]
|
||||||
|
public string Foo { get; set; }
|
||||||
[CommandParameter(1, Name = ""bar"", IsRequired = true)]
|
|
||||||
public string Bar { get; set; }
|
[CommandParameter(1, Name = "bar", IsRequired = true)]
|
||||||
|
public string Bar { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -79,14 +85,16 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public string Foo { get; set; }
|
{
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
|
|||||||
@@ -13,18 +13,20 @@ public class ParameterMustBeLastIfNonScalarAnalyzerSpecs
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0)]
|
{
|
||||||
public string[] Foo { get; set; }
|
[CommandParameter(0)]
|
||||||
|
public string[] Foo { get; set; }
|
||||||
[CommandParameter(1)]
|
|
||||||
public string Bar { get; set; }
|
[CommandParameter(1)]
|
||||||
|
public string Bar { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -35,18 +37,20 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0)]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0)]
|
||||||
|
public string Foo { get; set; }
|
||||||
[CommandParameter(1)]
|
|
||||||
public string[] Bar { get; set; }
|
[CommandParameter(1)]
|
||||||
|
public string[] Bar { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -57,18 +61,20 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0)]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0)]
|
||||||
|
public string Foo { get; set; }
|
||||||
[CommandParameter(1)]
|
|
||||||
public string Bar { get; set; }
|
[CommandParameter(1)]
|
||||||
|
public string Bar { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -79,14 +85,16 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public string Foo { get; set; }
|
{
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
|
|||||||
@@ -13,18 +13,20 @@ public class ParameterMustBeSingleIfNonRequiredAnalyzerSpecs
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0, IsRequired = false)]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0, IsRequired = false)]
|
||||||
|
public string Foo { get; set; }
|
||||||
[CommandParameter(1, IsRequired = false)]
|
|
||||||
public string Bar { get; set; }
|
[CommandParameter(1, IsRequired = false)]
|
||||||
|
public string Bar { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -35,18 +37,20 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0)]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0)]
|
||||||
|
public string Foo { get; set; }
|
||||||
[CommandParameter(1, IsRequired = false)]
|
|
||||||
public string Bar { get; set; }
|
[CommandParameter(1, IsRequired = false)]
|
||||||
|
public string Bar { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -57,18 +61,20 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0)]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0)]
|
||||||
|
public string Foo { get; set; }
|
||||||
[CommandParameter(1, IsRequired = true)]
|
|
||||||
public string Bar { get; set; }
|
[CommandParameter(1, IsRequired = true)]
|
||||||
|
public string Bar { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -79,14 +85,16 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public string Foo { get; set; }
|
{
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
|
|||||||
@@ -13,18 +13,20 @@ public class ParameterMustBeSingleIfNonScalarAnalyzerSpecs
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0)]
|
{
|
||||||
public string[] Foo { get; set; }
|
[CommandParameter(0)]
|
||||||
|
public string[] Foo { get; set; }
|
||||||
[CommandParameter(1)]
|
|
||||||
public string[] Bar { get; set; }
|
[CommandParameter(1)]
|
||||||
|
public string[] Bar { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -35,18 +37,20 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0)]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0)]
|
||||||
|
public string Foo { get; set; }
|
||||||
[CommandParameter(1)]
|
|
||||||
public string[] Bar { get; set; }
|
[CommandParameter(1)]
|
||||||
|
public string[] Bar { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -57,18 +61,20 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0)]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0)]
|
||||||
|
public string Foo { get; set; }
|
||||||
[CommandParameter(1)]
|
|
||||||
public string Bar { get; set; }
|
[CommandParameter(1)]
|
||||||
|
public string Bar { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -79,14 +85,16 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public string Foo { get; set; }
|
{
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
|
|||||||
@@ -13,18 +13,20 @@ public class ParameterMustHaveUniqueNameAnalyzerSpecs
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0, Name = ""foo"")]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0, Name = "foo")]
|
||||||
|
public string Foo { get; set; }
|
||||||
[CommandParameter(1, Name = ""foo"")]
|
|
||||||
public string Bar { get; set; }
|
[CommandParameter(1, Name = "foo")]
|
||||||
|
public string Bar { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -35,18 +37,20 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0, Name = ""foo"")]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0, Name = "foo")]
|
||||||
|
public string Foo { get; set; }
|
||||||
[CommandParameter(1, Name = ""bar"")]
|
|
||||||
public string Bar { get; set; }
|
[CommandParameter(1, Name = "bar")]
|
||||||
|
public string Bar { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -57,14 +61,16 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public string Foo { get; set; }
|
{
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
|
|||||||
@@ -13,18 +13,20 @@ public class ParameterMustHaveUniqueOrderAnalyzerSpecs
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0)]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0)]
|
||||||
|
public string Foo { get; set; }
|
||||||
[CommandParameter(0)]
|
|
||||||
public string Bar { get; set; }
|
[CommandParameter(0)]
|
||||||
|
public string Bar { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -35,18 +37,20 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0)]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0)]
|
||||||
|
public string Foo { get; set; }
|
||||||
[CommandParameter(1)]
|
|
||||||
public string Bar { get; set; }
|
[CommandParameter(1)]
|
||||||
|
public string Bar { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -57,14 +61,16 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public string Foo { get; set; }
|
{
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
|
|||||||
@@ -13,20 +13,22 @@ public class ParameterMustHaveValidConverterAnalyzerSpecs
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public class MyConverter
|
"""
|
||||||
{
|
public class MyConverter
|
||||||
public string Convert(string rawValue) => rawValue;
|
{
|
||||||
}
|
public string Convert(string rawValue) => rawValue;
|
||||||
|
}
|
||||||
[Command]
|
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0, Converter = typeof(MyConverter))]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0, Converter = typeof(MyConverter))]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -37,20 +39,22 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public class MyConverter : BindingConverter<int>
|
"""
|
||||||
{
|
public class MyConverter : BindingConverter<int>
|
||||||
public override int Convert(string rawValue) => 42;
|
{
|
||||||
}
|
public override int Convert(string rawValue) => 42;
|
||||||
|
}
|
||||||
[Command]
|
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0, Converter = typeof(MyConverter))]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0, Converter = typeof(MyConverter))]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
@@ -62,20 +66,22 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public class MyConverter : BindingConverter<string>
|
"""
|
||||||
{
|
public class MyConverter : BindingConverter<string>
|
||||||
public override string Convert(string rawValue) => rawValue;
|
{
|
||||||
}
|
public override string Convert(string rawValue) => rawValue;
|
||||||
|
}
|
||||||
[Command]
|
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0, Converter = typeof(MyConverter))]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0, Converter = typeof(MyConverter))]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -86,20 +92,22 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public class MyConverter : BindingConverter<int>
|
"""
|
||||||
{
|
public class MyConverter : BindingConverter<int>
|
||||||
public override int Convert(string rawValue) => 42;
|
{
|
||||||
}
|
public override int Convert(string rawValue) => 42;
|
||||||
|
}
|
||||||
[Command]
|
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandOption(""foo"", Converter = typeof(MyConverter))]
|
{
|
||||||
public int? Foo { get; set; }
|
[CommandOption("foo", Converter = typeof(MyConverter))]
|
||||||
|
public int? Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -110,20 +118,22 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public class MyConverter : BindingConverter<string>
|
"""
|
||||||
{
|
public class MyConverter : BindingConverter<string>
|
||||||
public override string Convert(string rawValue) => rawValue;
|
{
|
||||||
}
|
public override string Convert(string rawValue) => rawValue;
|
||||||
|
}
|
||||||
[Command]
|
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0, Converter = typeof(MyConverter))]
|
{
|
||||||
public IReadOnlyList<string> Foo { get; set; }
|
[CommandParameter(0, Converter = typeof(MyConverter))]
|
||||||
|
public IReadOnlyList<string> Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -134,15 +144,17 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0)]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0)]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -153,14 +165,16 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public string Foo { get; set; }
|
{
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
|
|||||||
@@ -13,20 +13,22 @@ public class ParameterMustHaveValidValidatorsAnalyzerSpecs
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public class MyValidator
|
"""
|
||||||
{
|
public class MyValidator
|
||||||
public void Validate(string value) {}
|
{
|
||||||
}
|
public void Validate(string value) {}
|
||||||
|
}
|
||||||
[Command]
|
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0, Validators = new[] {typeof(MyValidator)})]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0, Validators = new[] {typeof(MyValidator)})]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -37,20 +39,22 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public class MyValidator : BindingValidator<int>
|
"""
|
||||||
{
|
public class MyValidator : BindingValidator<int>
|
||||||
public override BindingValidationError Validate(int value) => Ok();
|
{
|
||||||
}
|
public override BindingValidationError Validate(int value) => Ok();
|
||||||
|
}
|
||||||
[Command]
|
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0, Validators = new[] {typeof(MyValidator)})]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0, Validators = new[] {typeof(MyValidator)})]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -61,20 +65,22 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
public class MyValidator : BindingValidator<string>
|
"""
|
||||||
{
|
public class MyValidator : BindingValidator<string>
|
||||||
public override BindingValidationError Validate(string value) => Ok();
|
{
|
||||||
}
|
public override BindingValidationError Validate(string value) => Ok();
|
||||||
|
}
|
||||||
[Command]
|
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0, Validators = new[] {typeof(MyValidator)})]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0, Validators = new[] {typeof(MyValidator)})]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -85,15 +91,17 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
[CommandParameter(0)]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0)]
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -104,14 +112,16 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public string Foo { get; set; }
|
{
|
||||||
|
public string Foo { get; set; }
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
|
|||||||
@@ -13,16 +13,18 @@ public class SystemConsoleShouldBeAvoidedAnalyzerSpecs
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
{
|
||||||
{
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
Console.WriteLine(""Hello world"");
|
{
|
||||||
return default;
|
Console.WriteLine("Hello world");
|
||||||
}
|
return default;
|
||||||
}";
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -33,16 +35,19 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
{
|
||||||
{
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
Console.ForegroundColor = ConsoleColor.Black;
|
{
|
||||||
return default;
|
Console.ForegroundColor = ConsoleColor.Black;
|
||||||
}
|
return default;
|
||||||
}";
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
}
|
}
|
||||||
@@ -52,16 +57,18 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
{
|
||||||
{
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
Console.Error.WriteLine(""Hello world"");
|
{
|
||||||
return default;
|
Console.Error.WriteLine("Hello world");
|
||||||
}
|
return default;
|
||||||
}";
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().ProduceDiagnostics(code);
|
Analyzer.Should().ProduceDiagnostics(code);
|
||||||
@@ -72,16 +79,18 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
{
|
||||||
{
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
console.Output.WriteLine(""Hello world"");
|
{
|
||||||
return default;
|
console.Output.WriteLine("Hello world");
|
||||||
}
|
return default;
|
||||||
}";
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -92,14 +101,16 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public void SomeOtherMethod() => Console.WriteLine(""Test"");
|
{
|
||||||
|
public void SomeOtherMethod() => Console.WriteLine("Test");
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}";
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
@@ -110,15 +121,17 @@ public class MyCommand : ICommand
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
// language=cs
|
// language=cs
|
||||||
const string code = @"
|
const string code =
|
||||||
[Command]
|
"""
|
||||||
public class MyCommand : ICommand
|
[Command]
|
||||||
{
|
public class MyCommand : ICommand
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
{
|
||||||
{
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
return default;
|
{
|
||||||
}
|
return default;
|
||||||
}";
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
// Act & assert
|
// Act & assert
|
||||||
Analyzer.Should().NotProduceDiagnostics(code);
|
Analyzer.Should().NotProduceDiagnostics(code);
|
||||||
|
|||||||
@@ -21,28 +21,30 @@ public class CancellationSpecs : SpecsBase
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
public async ValueTask ExecuteAsync(IConsole console)
|
public async ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Task.Delay(
|
await Task.Delay(
|
||||||
TimeSpan.FromSeconds(3),
|
TimeSpan.FromSeconds(3),
|
||||||
console.RegisterCancellationHandler()
|
console.RegisterCancellationHandler()
|
||||||
);
|
);
|
||||||
|
|
||||||
console.Output.WriteLine(""Completed successfully"");
|
console.Output.WriteLine("Completed successfully");
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""Cancelled"");
|
console.Output.WriteLine("Cancelled");
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
|
|||||||
@@ -48,27 +48,28 @@ public class ConsoleSpecs : SpecsBase
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.ResetColor();
|
console.ResetColor();
|
||||||
console.ForegroundColor = ConsoleColor.DarkMagenta;
|
console.ForegroundColor = ConsoleColor.DarkMagenta;
|
||||||
console.BackgroundColor = ConsoleColor.DarkMagenta;
|
console.BackgroundColor = ConsoleColor.DarkMagenta;
|
||||||
console.WindowWidth = 100;
|
console.WindowWidth = 100;
|
||||||
console.WindowHeight = 25;
|
console.WindowHeight = 25;
|
||||||
console.CursorLeft = 42;
|
console.CursorLeft = 42;
|
||||||
console.CursorTop = 24;
|
console.CursorTop = 24;
|
||||||
|
|
||||||
console.Output.WriteLine(""Hello "");
|
console.Output.WriteLine("Hello ");
|
||||||
console.Error.WriteLine(""world!"");
|
console.Error.WriteLine("world!");
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
");
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -108,20 +109,21 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
var input = console.Input.ReadToEnd();
|
var input = console.Input.ReadToEnd();
|
||||||
console.Output.WriteLine(input);
|
console.Output.WriteLine(input);
|
||||||
console.Error.WriteLine(input);
|
console.Error.WriteLine(input);
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
");
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -151,20 +153,21 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(console.ReadKey().Key);
|
console.Output.WriteLine(console.ReadKey().Key);
|
||||||
console.Output.WriteLine(console.ReadKey().Key);
|
console.Output.WriteLine(console.ReadKey().Key);
|
||||||
console.Output.WriteLine(console.ReadKey().Key);
|
console.Output.WriteLine(console.ReadKey().Key);
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
");
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
|
|||||||
@@ -21,20 +21,22 @@ public class ConversionSpecs : SpecsBase
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public string Foo { get; set; }
|
public string Foo { get; set; }
|
||||||
|
|
||||||
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
|
{
|
||||||
|
console.Output.WriteLine(Foo);
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
|
||||||
{
|
|
||||||
console.Output.WriteLine(Foo);
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
");
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
.UseConsole(FakeConsole)
|
.UseConsole(FakeConsole)
|
||||||
@@ -59,20 +61,22 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public object Foo { get; set; }
|
public object Foo { get; set; }
|
||||||
|
|
||||||
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
|
{
|
||||||
|
console.Output.WriteLine(Foo);
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
|
||||||
{
|
|
||||||
console.Output.WriteLine(Foo);
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
");
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
.UseConsole(FakeConsole)
|
.UseConsole(FakeConsole)
|
||||||
@@ -97,25 +101,27 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public bool Foo { get; set; }
|
public bool Foo { get; set; }
|
||||||
|
|
||||||
[CommandOption('b')]
|
[CommandOption('b')]
|
||||||
public bool Bar { get; set; }
|
public bool Bar { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""Foo = "" + Foo);
|
console.Output.WriteLine("Foo = " + Foo);
|
||||||
console.Output.WriteLine(""Bar = "" + Bar);
|
console.Output.WriteLine("Bar = " + Bar);
|
||||||
|
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
");
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
.UseConsole(FakeConsole)
|
.UseConsole(FakeConsole)
|
||||||
@@ -143,20 +149,22 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public bool Foo { get; set; }
|
public bool Foo { get; set; }
|
||||||
|
|
||||||
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
|
{
|
||||||
|
console.Output.WriteLine(Foo);
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
|
||||||
{
|
|
||||||
console.Output.WriteLine(Foo);
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
");
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
.UseConsole(FakeConsole)
|
.UseConsole(FakeConsole)
|
||||||
@@ -181,20 +189,22 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public int Foo { get; set; }
|
public int Foo { get; set; }
|
||||||
|
|
||||||
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
|
{
|
||||||
|
console.Output.WriteLine(Foo);
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
|
||||||
{
|
|
||||||
console.Output.WriteLine(Foo);
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
");
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
.UseConsole(FakeConsole)
|
.UseConsole(FakeConsole)
|
||||||
@@ -219,20 +229,22 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public double Foo { get; set; }
|
public double Foo { get; set; }
|
||||||
|
|
||||||
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
|
{
|
||||||
|
console.Output.WriteLine(Foo.ToString(CultureInfo.InvariantCulture));
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
|
||||||
{
|
|
||||||
console.Output.WriteLine(Foo.ToString(CultureInfo.InvariantCulture));
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
");
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
.UseConsole(FakeConsole)
|
.UseConsole(FakeConsole)
|
||||||
@@ -257,20 +269,22 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public DateTimeOffset Foo { get; set; }
|
public DateTimeOffset Foo { get; set; }
|
||||||
|
|
||||||
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
|
{
|
||||||
|
console.Output.WriteLine(Foo.ToString("u", CultureInfo.InvariantCulture));
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
|
||||||
{
|
|
||||||
console.Output.WriteLine(Foo.ToString(""u"", CultureInfo.InvariantCulture));
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
");
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
.UseConsole(FakeConsole)
|
.UseConsole(FakeConsole)
|
||||||
@@ -295,20 +309,22 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public TimeSpan Foo { get; set; }
|
public TimeSpan Foo { get; set; }
|
||||||
|
|
||||||
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
|
{
|
||||||
|
console.Output.WriteLine(Foo.ToString(null, CultureInfo.InvariantCulture));
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
|
||||||
{
|
|
||||||
console.Output.WriteLine(Foo.ToString(null, CultureInfo.InvariantCulture));
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
");
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
.UseConsole(FakeConsole)
|
.UseConsole(FakeConsole)
|
||||||
@@ -333,22 +349,24 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
public enum CustomEnum { One = 1, Two = 2, Three = 3 }
|
public enum CustomEnum { One = 1, Two = 2, Three = 3 }
|
||||||
|
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public CustomEnum Foo { get; set; }
|
public CustomEnum Foo { get; set; }
|
||||||
|
|
||||||
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
|
{
|
||||||
|
console.Output.WriteLine((int) Foo);
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
|
||||||
{
|
|
||||||
console.Output.WriteLine((int) Foo);
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
");
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
.UseConsole(FakeConsole)
|
.UseConsole(FakeConsole)
|
||||||
@@ -373,25 +391,27 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public int? Foo { get; set; }
|
public int? Foo { get; set; }
|
||||||
|
|
||||||
[CommandOption('b')]
|
[CommandOption('b')]
|
||||||
public int? Bar { get; set; }
|
public int? Bar { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""Foo = "" + Foo);
|
console.Output.WriteLine("Foo = " + Foo);
|
||||||
console.Output.WriteLine(""Bar = "" + Bar);
|
console.Output.WriteLine("Bar = " + Bar);
|
||||||
|
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
");
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
.UseConsole(FakeConsole)
|
.UseConsole(FakeConsole)
|
||||||
@@ -419,27 +439,29 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
public enum CustomEnum { One = 1, Two = 2, Three = 3 }
|
public enum CustomEnum { One = 1, Two = 2, Three = 3 }
|
||||||
|
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public CustomEnum? Foo { get; set; }
|
public CustomEnum? Foo { get; set; }
|
||||||
|
|
||||||
[CommandOption('b')]
|
[CommandOption('b')]
|
||||||
public CustomEnum? Bar { get; set; }
|
public CustomEnum? Bar { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""Foo = "" + (int?) Foo);
|
console.Output.WriteLine("Foo = " + (int?) Foo);
|
||||||
console.Output.WriteLine(""Bar = "" + (int?) Bar);
|
console.Output.WriteLine("Bar = " + (int?) Bar);
|
||||||
|
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
");
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
.UseConsole(FakeConsole)
|
.UseConsole(FakeConsole)
|
||||||
@@ -467,27 +489,29 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
public class CustomType
|
public class CustomType
|
||||||
{
|
{
|
||||||
public string Value { get; }
|
public string Value { get; }
|
||||||
|
|
||||||
public CustomType(string value) => Value = value;
|
public CustomType(string value) => Value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public CustomType Foo { get; set; }
|
public CustomType Foo { get; set; }
|
||||||
|
|
||||||
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
|
{
|
||||||
|
console.Output.WriteLine(Foo.Value);
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
|
||||||
{
|
|
||||||
console.Output.WriteLine(Foo.Value);
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
");
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
.UseConsole(FakeConsole)
|
.UseConsole(FakeConsole)
|
||||||
@@ -512,45 +536,47 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
public class CustomTypeA
|
public class CustomTypeA
|
||||||
{
|
{
|
||||||
public string Value { get; }
|
public string Value { get; }
|
||||||
|
|
||||||
private CustomTypeA(string value) => Value = value;
|
private CustomTypeA(string value) => Value = value;
|
||||||
|
|
||||||
public static CustomTypeA Parse(string value) =>
|
public static CustomTypeA Parse(string value) =>
|
||||||
new CustomTypeA(value);
|
new CustomTypeA(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CustomTypeB
|
public class CustomTypeB
|
||||||
{
|
{
|
||||||
public string Value { get; }
|
public string Value { get; }
|
||||||
|
|
||||||
private CustomTypeB(string value) => Value = value;
|
private CustomTypeB(string value) => Value = value;
|
||||||
|
|
||||||
public static CustomTypeB Parse(string value, IFormatProvider formatProvider) =>
|
public static CustomTypeB Parse(string value, IFormatProvider formatProvider) =>
|
||||||
new CustomTypeB(value);
|
new CustomTypeB(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public CustomTypeA Foo { get; set; }
|
public CustomTypeA Foo { get; set; }
|
||||||
|
|
||||||
[CommandOption('b')]
|
[CommandOption('b')]
|
||||||
public CustomTypeB Bar { get; set; }
|
public CustomTypeB Bar { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""Foo = "" + Foo.Value);
|
console.Output.WriteLine("Foo = " + Foo.Value);
|
||||||
console.Output.WriteLine(""Bar = "" + Bar.Value);
|
console.Output.WriteLine("Bar = " + Bar.Value);
|
||||||
|
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
");
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
.UseConsole(FakeConsole)
|
.UseConsole(FakeConsole)
|
||||||
@@ -578,26 +604,28 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
public class CustomConverter : BindingConverter<int>
|
public class CustomConverter : BindingConverter<int>
|
||||||
{
|
{
|
||||||
public override int Convert(string rawValue) =>
|
public override int Convert(string rawValue) =>
|
||||||
rawValue.Length;
|
rawValue.Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f', Converter = typeof(CustomConverter))]
|
[CommandOption('f', Converter = typeof(CustomConverter))]
|
||||||
public int Foo { get; set; }
|
public int Foo { get; set; }
|
||||||
|
|
||||||
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
|
{
|
||||||
|
console.Output.WriteLine(Foo);
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
|
||||||
{
|
|
||||||
console.Output.WriteLine(Foo);
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
");
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
.UseConsole(FakeConsole)
|
.UseConsole(FakeConsole)
|
||||||
@@ -622,22 +650,24 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public string[] Foo { get; set; }
|
public string[] Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
foreach (var i in Foo)
|
foreach (var i in Foo)
|
||||||
console.Output.WriteLine(i);
|
console.Output.WriteLine(i);
|
||||||
|
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
");
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
.UseConsole(FakeConsole)
|
.UseConsole(FakeConsole)
|
||||||
@@ -666,22 +696,24 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public IReadOnlyList<string> Foo { get; set; }
|
public IReadOnlyList<string> Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
foreach (var i in Foo)
|
foreach (var i in Foo)
|
||||||
console.Output.WriteLine(i);
|
console.Output.WriteLine(i);
|
||||||
|
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
");
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
.UseConsole(FakeConsole)
|
.UseConsole(FakeConsole)
|
||||||
@@ -710,22 +742,24 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public List<string> Foo { get; set; }
|
public List<string> Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
foreach (var i in Foo)
|
foreach (var i in Foo)
|
||||||
console.Output.WriteLine(i);
|
console.Output.WriteLine(i);
|
||||||
|
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
");
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
.UseConsole(FakeConsole)
|
.UseConsole(FakeConsole)
|
||||||
@@ -754,22 +788,24 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public int[] Foo { get; set; }
|
public int[] Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
foreach (var i in Foo)
|
foreach (var i in Foo)
|
||||||
console.Output.WriteLine(i);
|
console.Output.WriteLine(i);
|
||||||
|
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
");
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
.UseConsole(FakeConsole)
|
.UseConsole(FakeConsole)
|
||||||
@@ -798,16 +834,18 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public int Foo { get; set; }
|
public int Foo { get; set; }
|
||||||
|
|
||||||
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}
|
|
||||||
");
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
.UseConsole(FakeConsole)
|
.UseConsole(FakeConsole)
|
||||||
@@ -832,18 +870,20 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
public class CustomType {}
|
public class CustomType {}
|
||||||
|
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public CustomType Foo { get; set; }
|
public CustomType Foo { get; set; }
|
||||||
|
|
||||||
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}
|
|
||||||
");
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
.UseConsole(FakeConsole)
|
.UseConsole(FakeConsole)
|
||||||
@@ -868,23 +908,25 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
public class CustomType : IEnumerable<object>
|
public class CustomType : IEnumerable<object>
|
||||||
{
|
{
|
||||||
public IEnumerator<object> GetEnumerator() => Enumerable.Empty<object>().GetEnumerator();
|
public IEnumerator<object> GetEnumerator() => Enumerable.Empty<object>().GetEnumerator();
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public CustomType Foo { get; set; }
|
public CustomType Foo { get; set; }
|
||||||
|
|
||||||
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}
|
|
||||||
");
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
.UseConsole(FakeConsole)
|
.UseConsole(FakeConsole)
|
||||||
@@ -909,26 +951,28 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
public class ValidatorA : BindingValidator<int>
|
public class ValidatorA : BindingValidator<int>
|
||||||
{
|
{
|
||||||
public override BindingValidationError Validate(int value) => Ok();
|
public override BindingValidationError Validate(int value) => Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ValidatorB : BindingValidator<int>
|
public class ValidatorB : BindingValidator<int>
|
||||||
{
|
{
|
||||||
public override BindingValidationError Validate(int value) => Error(""Hello world"");
|
public override BindingValidationError Validate(int value) => Error("Hello world");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f', Validators = new[] {typeof(ValidatorA), typeof(ValidatorB)})]
|
[CommandOption('f', Validators = new[] {typeof(ValidatorA), typeof(ValidatorB)})]
|
||||||
public int Foo { get; set; }
|
public int Foo { get; set; }
|
||||||
|
|
||||||
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}
|
|
||||||
");
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
.UseConsole(FakeConsole)
|
.UseConsole(FakeConsole)
|
||||||
@@ -953,25 +997,27 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
public class CustomType
|
public class CustomType
|
||||||
{
|
{
|
||||||
public string Value { get; }
|
public string Value { get; }
|
||||||
|
|
||||||
private CustomType(string value) => Value = value;
|
private CustomType(string value) => Value = value;
|
||||||
|
|
||||||
public static CustomType Parse(string value) => throw new Exception(""Hello world"");
|
public static CustomType Parse(string value) => throw new Exception("Hello world");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public CustomType Foo { get; set; }
|
public CustomType Foo { get; set; }
|
||||||
|
|
||||||
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}
|
|
||||||
");
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
.UseConsole(FakeConsole)
|
.UseConsole(FakeConsole)
|
||||||
|
|||||||
@@ -75,13 +75,14 @@ public class DirectivesSpecs : SpecsBase
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command(""cmd"")]
|
[Command("cmd")]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
}
|
}
|
||||||
");
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
|
|||||||
@@ -25,20 +25,21 @@ public class EnvironmentSpecs : SpecsBase
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption(""foo"", IsRequired = true, EnvironmentVariable = ""ENV_FOO"")]
|
[CommandOption("foo", IsRequired = true, EnvironmentVariable = "ENV_FOO")]
|
||||||
public string Foo { get; set; }
|
public string Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(Foo);
|
console.Output.WriteLine(Foo);
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
");
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -67,20 +68,21 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption(""foo"", EnvironmentVariable = ""ENV_FOO"")]
|
[CommandOption("foo", EnvironmentVariable = "ENV_FOO")]
|
||||||
public string Foo { get; set; }
|
public string Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(Foo);
|
console.Output.WriteLine(Foo);
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
");
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -109,22 +111,23 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption(""foo"", EnvironmentVariable = ""ENV_FOO"")]
|
[CommandOption("foo", EnvironmentVariable = "ENV_FOO")]
|
||||||
public IReadOnlyList<string> Foo { get; set; }
|
public IReadOnlyList<string> Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
foreach (var i in Foo)
|
foreach (var i in Foo)
|
||||||
console.Output.WriteLine(i);
|
console.Output.WriteLine(i);
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
");
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -156,20 +159,21 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption(""foo"", EnvironmentVariable = ""ENV_FOO"")]
|
[CommandOption("foo", EnvironmentVariable = "ENV_FOO")]
|
||||||
public string Foo { get; set; }
|
public string Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(Foo);
|
console.Output.WriteLine(Foo);
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
");
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -198,20 +202,21 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption(""foo"", EnvironmentVariable = ""ENV_FOO"")]
|
[CommandOption("foo", EnvironmentVariable = "ENV_FOO")]
|
||||||
public string Foo { get; set; }
|
public string Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(Foo);
|
console.Output.WriteLine(Foo);
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
");
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
|
|||||||
@@ -22,14 +22,15 @@ public class ErrorReportingSpecs : SpecsBase
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console) =>
|
public ValueTask ExecuteAsync(IConsole console) =>
|
||||||
throw new Exception(""Something went wrong"");
|
throw new Exception("Something went wrong");
|
||||||
}
|
}
|
||||||
");
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -60,14 +61,15 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console) =>
|
public ValueTask ExecuteAsync(IConsole console) =>
|
||||||
throw new Exception(""Something went wrong"", new Exception(""Another exception""));
|
throw new Exception("Something went wrong", new Exception("Another exception"));
|
||||||
}
|
}
|
||||||
");
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -99,14 +101,15 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console) =>
|
public ValueTask ExecuteAsync(IConsole console) =>
|
||||||
throw new CommandException(""Something went wrong"", 69);
|
throw new CommandException("Something went wrong", 69);
|
||||||
}
|
}
|
||||||
");
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -134,14 +137,15 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console) =>
|
public ValueTask ExecuteAsync(IConsole console) =>
|
||||||
throw new CommandException("""", 69);
|
throw new CommandException("", 69);
|
||||||
}
|
}
|
||||||
");
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -172,14 +176,15 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console) =>
|
public ValueTask ExecuteAsync(IConsole console) =>
|
||||||
throw new CommandException(""Something went wrong"", 69, true);
|
throw new CommandException("Something went wrong", 69, true);
|
||||||
}
|
}
|
||||||
");
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
|
|||||||
@@ -44,13 +44,14 @@ public class HelpTextSpecs : SpecsBase
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class DefaultCommand : ICommand
|
public class DefaultCommand : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
}
|
}
|
||||||
");
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -77,19 +78,20 @@ public class DefaultCommand : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandTypes = DynamicCommandBuilder.CompileMany(
|
var commandTypes = DynamicCommandBuilder.CompileMany(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command(""cmd"")]
|
[Command("cmd")]
|
||||||
public class NamedCommand : ICommand
|
public class NamedCommand : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command(""cmd child"")]
|
[Command("cmd child")]
|
||||||
public class NamedChildCommand : ICommand
|
public class NamedChildCommand : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
}
|
}
|
||||||
");
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommands(commandTypes)
|
.AddCommands(commandTypes)
|
||||||
@@ -116,25 +118,26 @@ public class NamedChildCommand : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandTypes = DynamicCommandBuilder.CompileMany(
|
var commandTypes = DynamicCommandBuilder.CompileMany(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class DefaultCommand : ICommand
|
public class DefaultCommand : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command(""cmd"", Description = ""Description of a named command."")]
|
[Command("cmd", Description = "Description of a named command.")]
|
||||||
public class NamedCommand : ICommand
|
public class NamedCommand : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command(""cmd child"")]
|
[Command("cmd child")]
|
||||||
public class NamedChildCommand : ICommand
|
public class NamedChildCommand : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
}
|
}
|
||||||
");
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommands(commandTypes)
|
.AddCommands(commandTypes)
|
||||||
@@ -160,25 +163,26 @@ public class NamedChildCommand : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandTypes = DynamicCommandBuilder.CompileMany(
|
var commandTypes = DynamicCommandBuilder.CompileMany(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class DefaultCommand : ICommand
|
public class DefaultCommand : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command(""cmd"")]
|
[Command("cmd")]
|
||||||
public class NamedCommand : ICommand
|
public class NamedCommand : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command(""cmd child"", Description = ""Description of a named child command."")]
|
[Command("cmd child", Description = "Description of a named child command.")]
|
||||||
public class NamedChildCommand : ICommand
|
public class NamedChildCommand : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
}
|
}
|
||||||
");
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommands(commandTypes)
|
.AddCommands(commandTypes)
|
||||||
@@ -257,13 +261,15 @@ public class NamedChildCommand : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command(Description = ""Description of the default command."")]
|
|
||||||
public class DefaultCommand : ICommand
|
[Command(Description = "Description of the default command.")]
|
||||||
{
|
public class DefaultCommand : ICommand
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
{
|
||||||
}
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
");
|
}
|
||||||
|
|
||||||
|
""");
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -292,19 +298,21 @@ public class DefaultCommand : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandTypes = DynamicCommandBuilder.CompileMany(
|
var commandTypes = DynamicCommandBuilder.CompileMany(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
|
||||||
public class DefaultCommand : ICommand
|
[Command]
|
||||||
{
|
public class DefaultCommand : ICommand
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
{
|
||||||
}
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Command("cmd")]
|
||||||
|
public class NamedCommand : ICommand
|
||||||
|
{
|
||||||
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
|
||||||
[Command(""cmd"")]
|
""");
|
||||||
public class NamedCommand : ICommand
|
|
||||||
{
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}
|
|
||||||
");
|
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommands(commandTypes)
|
.AddCommands(commandTypes)
|
||||||
@@ -333,22 +341,24 @@ public class NamedCommand : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
|
||||||
public class Command : ICommand
|
[Command]
|
||||||
{
|
public class Command : ICommand
|
||||||
[CommandParameter(0)]
|
{
|
||||||
public string Foo { get; set; }
|
[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;
|
||||||
|
}
|
||||||
|
|
||||||
[CommandParameter(1)]
|
""");
|
||||||
public string Bar { get; set; }
|
|
||||||
|
|
||||||
[CommandParameter(2)]
|
|
||||||
public IReadOnlyList<string> Baz { get; set; }
|
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}
|
|
||||||
");
|
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -378,28 +388,30 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
// Base members appear last in reflection order
|
|
||||||
public abstract class CommandBase : ICommand
|
// Base members appear last in reflection order
|
||||||
{
|
public abstract class CommandBase : ICommand
|
||||||
[CommandParameter(0)]
|
{
|
||||||
public string Foo { get; set; }
|
[CommandParameter(0)]
|
||||||
|
public string Foo { get; set; }
|
||||||
|
|
||||||
|
public abstract ValueTask ExecuteAsync(IConsole console);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Command]
|
||||||
|
public class Command : CommandBase
|
||||||
|
{
|
||||||
|
[CommandParameter(2)]
|
||||||
|
public IReadOnlyList<string> Baz { get; set; }
|
||||||
|
|
||||||
|
[CommandParameter(1)]
|
||||||
|
public string Bar { get; set; }
|
||||||
|
|
||||||
|
public override ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract ValueTask ExecuteAsync(IConsole console);
|
""");
|
||||||
}
|
|
||||||
|
|
||||||
[Command]
|
|
||||||
public class Command : CommandBase
|
|
||||||
{
|
|
||||||
[CommandParameter(2)]
|
|
||||||
public IReadOnlyList<string> Baz { get; set; }
|
|
||||||
|
|
||||||
[CommandParameter(1)]
|
|
||||||
public string Bar { get; set; }
|
|
||||||
|
|
||||||
public override ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}
|
|
||||||
");
|
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -428,22 +440,24 @@ public class Command : CommandBase
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
|
||||||
public class Command : ICommand
|
[Command]
|
||||||
{
|
public class Command : ICommand
|
||||||
[CommandOption(""foo"", IsRequired = true)]
|
{
|
||||||
public string Foo { get; set; }
|
[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;
|
||||||
|
}
|
||||||
|
|
||||||
[CommandOption(""bar"")]
|
""");
|
||||||
public string Bar { get; set; }
|
|
||||||
|
|
||||||
[CommandOption(""baz"", IsRequired = true)]
|
|
||||||
public IReadOnlyList<string> Baz { get; set; }
|
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}
|
|
||||||
");
|
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -472,19 +486,21 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
|
||||||
public class Command : ICommand
|
[Command]
|
||||||
{
|
public class Command : ICommand
|
||||||
[CommandParameter(0, Name = ""foo"", Description = ""Description of foo."")]
|
{
|
||||||
public string Foo { get; set; }
|
[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;
|
||||||
|
}
|
||||||
|
|
||||||
[CommandOption(""bar"", Description = ""Description of bar."")]
|
""");
|
||||||
public string Bar { get; set; }
|
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}
|
|
||||||
");
|
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -515,13 +531,15 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
|
||||||
public class Command : ICommand
|
[Command]
|
||||||
{
|
public class Command : ICommand
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
{
|
||||||
}
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
");
|
}
|
||||||
|
|
||||||
|
""");
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -551,13 +569,15 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command(""cmd"")]
|
|
||||||
public class Command : ICommand
|
[Command("cmd")]
|
||||||
{
|
public class Command : ICommand
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
{
|
||||||
}
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
");
|
}
|
||||||
|
|
||||||
|
""");
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -589,21 +609,23 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
public enum CustomEnum { One, Two, Three }
|
|
||||||
|
public enum CustomEnum { One, Two, Three }
|
||||||
|
|
||||||
|
[Command]
|
||||||
|
public class Command : ICommand
|
||||||
|
{
|
||||||
|
[CommandParameter(0)]
|
||||||
|
public CustomEnum Foo { get; set; }
|
||||||
|
|
||||||
|
[CommandOption("bar")]
|
||||||
|
public CustomEnum Bar { get; set; }
|
||||||
|
|
||||||
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
|
||||||
[Command]
|
""");
|
||||||
public class Command : ICommand
|
|
||||||
{
|
|
||||||
[CommandParameter(0)]
|
|
||||||
public CustomEnum Foo { get; set; }
|
|
||||||
|
|
||||||
[CommandOption(""bar"")]
|
|
||||||
public CustomEnum Bar { get; set; }
|
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}
|
|
||||||
");
|
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -634,21 +656,23 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
public enum CustomEnum { One, Two, Three }
|
|
||||||
|
public enum CustomEnum { One, Two, Three }
|
||||||
|
|
||||||
|
[Command]
|
||||||
|
public class Command : ICommand
|
||||||
|
{
|
||||||
|
[CommandParameter(0)]
|
||||||
|
public IReadOnlyList<CustomEnum> Foo { get; set; }
|
||||||
|
|
||||||
|
[CommandOption("bar")]
|
||||||
|
public IReadOnlyList<CustomEnum> Bar { get; set; }
|
||||||
|
|
||||||
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
|
||||||
[Command]
|
""");
|
||||||
public class Command : ICommand
|
|
||||||
{
|
|
||||||
[CommandParameter(0)]
|
|
||||||
public IReadOnlyList<CustomEnum> Foo { get; set; }
|
|
||||||
|
|
||||||
[CommandOption(""bar"")]
|
|
||||||
public IReadOnlyList<CustomEnum> Bar { get; set; }
|
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}
|
|
||||||
");
|
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -679,21 +703,23 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
public enum CustomEnum { One, Two, Three }
|
|
||||||
|
public enum CustomEnum { One, Two, Three }
|
||||||
|
|
||||||
|
[Command]
|
||||||
|
public class Command : ICommand
|
||||||
|
{
|
||||||
|
[CommandParameter(0)]
|
||||||
|
public CustomEnum? Foo { get; set; }
|
||||||
|
|
||||||
|
[CommandOption("bar")]
|
||||||
|
public IReadOnlyList<CustomEnum?> Bar { get; set; }
|
||||||
|
|
||||||
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
|
||||||
[Command]
|
""");
|
||||||
public class Command : ICommand
|
|
||||||
{
|
|
||||||
[CommandParameter(0)]
|
|
||||||
public CustomEnum? Foo { get; set; }
|
|
||||||
|
|
||||||
[CommandOption(""bar"")]
|
|
||||||
public IReadOnlyList<CustomEnum?> Bar { get; set; }
|
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}
|
|
||||||
");
|
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -724,21 +750,23 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
public enum CustomEnum { One, Two, Three }
|
|
||||||
|
public enum CustomEnum { One, Two, Three }
|
||||||
|
|
||||||
|
[Command]
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
[Command]
|
""");
|
||||||
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;
|
|
||||||
}
|
|
||||||
");
|
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -768,39 +796,41 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
public enum CustomEnum { One, Two, Three }
|
|
||||||
|
public enum CustomEnum { One, Two, Three }
|
||||||
|
|
||||||
|
[Command]
|
||||||
|
public class Command : ICommand
|
||||||
|
{
|
||||||
|
[CommandOption("foo")]
|
||||||
|
public object Foo { get; set; } = 42;
|
||||||
|
|
||||||
|
[CommandOption("bar")]
|
||||||
|
public string Bar { get; set; } = "hello";
|
||||||
|
|
||||||
|
[CommandOption("baz")]
|
||||||
|
public IReadOnlyList<string> Baz { get; set; } = new[] {"one", "two", "three"};
|
||||||
|
|
||||||
|
[CommandOption("qwe")]
|
||||||
|
public bool Qwe { get; set; } = true;
|
||||||
|
|
||||||
|
[CommandOption("qop")]
|
||||||
|
public int? Qop { get; set; } = 1337;
|
||||||
|
|
||||||
|
[CommandOption("zor")]
|
||||||
|
public TimeSpan Zor { get; set; } = TimeSpan.FromMinutes(123);
|
||||||
|
|
||||||
|
[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;
|
||||||
|
}
|
||||||
|
|
||||||
[Command]
|
""");
|
||||||
public class Command : ICommand
|
|
||||||
{
|
|
||||||
[CommandOption(""foo"")]
|
|
||||||
public object Foo { get; set; } = 42;
|
|
||||||
|
|
||||||
[CommandOption(""bar"")]
|
|
||||||
public string Bar { get; set; } = ""hello"";
|
|
||||||
|
|
||||||
[CommandOption(""baz"")]
|
|
||||||
public IReadOnlyList<string> Baz { get; set; } = new[] {""one"", ""two"", ""three""};
|
|
||||||
|
|
||||||
[CommandOption(""qwe"")]
|
|
||||||
public bool Qwe { get; set; } = true;
|
|
||||||
|
|
||||||
[CommandOption(""qop"")]
|
|
||||||
public int? Qop { get; set; } = 1337;
|
|
||||||
|
|
||||||
[CommandOption(""zor"")]
|
|
||||||
public TimeSpan Zor { get; set; } = TimeSpan.FromMinutes(123);
|
|
||||||
|
|
||||||
[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;
|
|
||||||
}
|
|
||||||
");
|
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -836,25 +866,27 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandTypes = DynamicCommandBuilder.CompileMany(
|
var commandTypes = DynamicCommandBuilder.CompileMany(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command(""cmd1"", Description = ""Description of one command."")]
|
|
||||||
public class FirstCommand : ICommand
|
[Command("cmd1", Description = "Description of one command.")]
|
||||||
{
|
public class FirstCommand : ICommand
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
{
|
||||||
}
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Command("cmd2", Description = "Description of another command.")]
|
||||||
|
public class SecondCommand : ICommand
|
||||||
|
{
|
||||||
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Command("cmd2 child", Description = "Description of another command's child command.")]
|
||||||
|
public class SecondCommandChildCommand : ICommand
|
||||||
|
{
|
||||||
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
|
||||||
[Command(""cmd2"", Description = ""Description of another command."")]
|
""");
|
||||||
public class SecondCommand : ICommand
|
|
||||||
{
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Command(""cmd2 child"", Description = ""Description of another command's child command."")]
|
|
||||||
public class SecondCommandChildCommand : ICommand
|
|
||||||
{
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}
|
|
||||||
");
|
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommands(commandTypes)
|
.AddCommands(commandTypes)
|
||||||
@@ -890,37 +922,39 @@ public class SecondCommandChildCommand : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandTypes = DynamicCommandBuilder.CompileMany(
|
var commandTypes = DynamicCommandBuilder.CompileMany(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command(""cmd1"")]
|
|
||||||
public class FirstCommand : ICommand
|
[Command("cmd1")]
|
||||||
{
|
public class FirstCommand : ICommand
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
{
|
||||||
}
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Command("cmd1 child1")]
|
||||||
|
public class FirstCommandFirstChildCommand : ICommand
|
||||||
|
{
|
||||||
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Command("cmd2")]
|
||||||
|
public class SecondCommand : ICommand
|
||||||
|
{
|
||||||
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Command("cmd2 child11")]
|
||||||
|
public class SecondCommandFirstChildCommand : ICommand
|
||||||
|
{
|
||||||
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Command("cmd2 child2")]
|
||||||
|
public class SecondCommandSecondChildCommand : ICommand
|
||||||
|
{
|
||||||
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
|
||||||
[Command(""cmd1 child1"")]
|
""");
|
||||||
public class FirstCommandFirstChildCommand : ICommand
|
|
||||||
{
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Command(""cmd2"")]
|
|
||||||
public class SecondCommand : ICommand
|
|
||||||
{
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Command(""cmd2 child11"")]
|
|
||||||
public class SecondCommandFirstChildCommand : ICommand
|
|
||||||
{
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Command(""cmd2 child2"")]
|
|
||||||
public class SecondCommandSecondChildCommand : ICommand
|
|
||||||
{
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}
|
|
||||||
");
|
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommands(commandTypes)
|
.AddCommands(commandTypes)
|
||||||
@@ -950,25 +984,27 @@ public class SecondCommandSecondChildCommand : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandTypes = DynamicCommandBuilder.CompileMany(
|
var commandTypes = DynamicCommandBuilder.CompileMany(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command(""cmd1"")]
|
|
||||||
public class FirstCommand : ICommand
|
[Command("cmd1")]
|
||||||
{
|
public class FirstCommand : ICommand
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
{
|
||||||
}
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Command("cmd2 child1")]
|
||||||
|
public class SecondCommandFirstChildCommand : ICommand
|
||||||
|
{
|
||||||
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Command("cmd2 child2")]
|
||||||
|
public class SecondCommandSecondChildCommand : ICommand
|
||||||
|
{
|
||||||
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
|
}
|
||||||
|
|
||||||
[Command(""cmd2 child1"")]
|
""");
|
||||||
public class SecondCommandFirstChildCommand : ICommand
|
|
||||||
{
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Command(""cmd2 child2"")]
|
|
||||||
public class SecondCommandSecondChildCommand : ICommand
|
|
||||||
{
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
|
||||||
}
|
|
||||||
");
|
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommands(commandTypes)
|
.AddCommands(commandTypes)
|
||||||
|
|||||||
@@ -22,19 +22,21 @@ public class OptionBindingSpecs : SpecsBase
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption(""foo"")]
|
[CommandOption("foo")]
|
||||||
public bool Foo { get; set; }
|
public bool Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(Foo);
|
console.Output.WriteLine(Foo);
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -60,19 +62,21 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public bool Foo { get; set; }
|
public bool Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(Foo);
|
console.Output.WriteLine(Foo);
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -98,24 +102,26 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption(""foo"")]
|
[CommandOption("foo")]
|
||||||
public string Foo { get; set; }
|
public string Foo { get; set; }
|
||||||
|
|
||||||
[CommandOption(""bar"")]
|
[CommandOption("bar")]
|
||||||
public string Bar { get; set; }
|
public string Bar { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""Foo = "" + Foo);
|
console.Output.WriteLine("Foo = " + Foo);
|
||||||
console.Output.WriteLine(""Bar = "" + Bar);
|
console.Output.WriteLine("Bar = " + Bar);
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -144,24 +150,26 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public string Foo { get; set; }
|
public string Foo { get; set; }
|
||||||
|
|
||||||
[CommandOption('b')]
|
[CommandOption('b')]
|
||||||
public string Bar { get; set; }
|
public string Bar { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""Foo = "" + Foo);
|
console.Output.WriteLine("Foo = " + Foo);
|
||||||
console.Output.WriteLine(""Bar = "" + Bar);
|
console.Output.WriteLine("Bar = " + Bar);
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -190,24 +198,26 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public string Foo { get; set; }
|
public string Foo { get; set; }
|
||||||
|
|
||||||
[CommandOption('b')]
|
[CommandOption('b')]
|
||||||
public string Bar { get; set; }
|
public string Bar { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""Foo = "" + Foo);
|
console.Output.WriteLine("Foo = " + Foo);
|
||||||
console.Output.WriteLine(""Bar = "" + Bar);
|
console.Output.WriteLine("Bar = " + Bar);
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -236,21 +246,23 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption(""Foo"")]
|
[CommandOption("Foo")]
|
||||||
public IReadOnlyList<string> Foo { get; set; }
|
public IReadOnlyList<string> Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
foreach (var i in Foo)
|
foreach (var i in Foo)
|
||||||
console.Output.WriteLine(i);
|
console.Output.WriteLine(i);
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -280,21 +292,23 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public IReadOnlyList<string> Foo { get; set; }
|
public IReadOnlyList<string> Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
foreach (var i in Foo)
|
foreach (var i in Foo)
|
||||||
console.Output.WriteLine(i);
|
console.Output.WriteLine(i);
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -324,21 +338,23 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption(""foo"")]
|
[CommandOption("foo")]
|
||||||
public IReadOnlyList<string> Foo { get; set; }
|
public IReadOnlyList<string> Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
foreach (var i in Foo)
|
foreach (var i in Foo)
|
||||||
console.Output.WriteLine(i);
|
console.Output.WriteLine(i);
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -368,21 +384,23 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption('f')]
|
[CommandOption('f')]
|
||||||
public IReadOnlyList<string> Foo { get; set; }
|
public IReadOnlyList<string> Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
foreach (var i in Foo)
|
foreach (var i in Foo)
|
||||||
console.Output.WriteLine(i);
|
console.Output.WriteLine(i);
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -412,21 +430,23 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption(""foo"", 'f')]
|
[CommandOption("foo", 'f')]
|
||||||
public IReadOnlyList<string> Foo { get; set; }
|
public IReadOnlyList<string> Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
foreach (var i in Foo)
|
foreach (var i in Foo)
|
||||||
console.Output.WriteLine(i);
|
console.Output.WriteLine(i);
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -456,24 +476,26 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption(""foo"")]
|
[CommandOption("foo")]
|
||||||
public string Foo { get; set; }
|
public string Foo { get; set; }
|
||||||
|
|
||||||
[CommandOption(""bar"")]
|
[CommandOption("bar")]
|
||||||
public string Bar { get; set; } = ""hello"";
|
public string Bar { get; set; } = "hello";
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""Foo = "" + Foo);
|
console.Output.WriteLine("Foo = " + Foo);
|
||||||
console.Output.WriteLine(""Bar = "" + Bar);
|
console.Output.WriteLine("Bar = " + Bar);
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -502,55 +524,56 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
public static class SharedContext
|
public static class SharedContext
|
||||||
{
|
{
|
||||||
public static int Foo { get; set; }
|
public static int Foo { get; set; }
|
||||||
|
|
||||||
public static bool Bar { get; set; }
|
public static bool Bar { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IHasFoo : ICommand
|
public interface IHasFoo : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption(""foo"")]
|
[CommandOption("foo")]
|
||||||
public int Foo
|
public int Foo
|
||||||
{
|
{
|
||||||
get => SharedContext.Foo;
|
get => SharedContext.Foo;
|
||||||
set => SharedContext.Foo = value;
|
set => SharedContext.Foo = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IHasBar : ICommand
|
public interface IHasBar : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption(""bar"")]
|
[CommandOption("bar")]
|
||||||
public bool Bar
|
public bool Bar
|
||||||
{
|
{
|
||||||
get => SharedContext.Bar;
|
get => SharedContext.Bar;
|
||||||
set => SharedContext.Bar = value;
|
set => SharedContext.Bar = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IHasBaz : ICommand
|
public interface IHasBaz : ICommand
|
||||||
{
|
{
|
||||||
public string Baz { get; set; }
|
public string Baz { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : IHasFoo, IHasBar, IHasBaz
|
public class Command : IHasFoo, IHasBar, IHasBaz
|
||||||
{
|
{
|
||||||
[CommandOption(""baz"")]
|
[CommandOption("baz")]
|
||||||
public string Baz { get; set; }
|
public string Baz { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""Foo = "" + SharedContext.Foo);
|
console.Output.WriteLine("Foo = " + SharedContext.Foo);
|
||||||
console.Output.WriteLine(""Bar = "" + SharedContext.Bar);
|
console.Output.WriteLine("Bar = " + SharedContext.Bar);
|
||||||
console.Output.WriteLine(""Baz = "" + Baz);
|
console.Output.WriteLine("Baz = " + Baz);
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
");
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -579,20 +602,22 @@ public class Command : IHasFoo, IHasBar, IHasBaz
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption(""foo"")]
|
[CommandOption("foo")]
|
||||||
public string Foo { get; set; }
|
public string Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(Foo);
|
console.Output.WriteLine(Foo);
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -618,15 +643,17 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption(""foo"", IsRequired = true)]
|
[CommandOption("foo", IsRequired = true)]
|
||||||
public string Foo { get; set; }
|
public string Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -652,15 +679,17 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption(""foo"", IsRequired = true)]
|
[CommandOption("foo", IsRequired = true)]
|
||||||
public string Foo { get; set; }
|
public string Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -686,15 +715,17 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption(""foo"", IsRequired = true)]
|
[CommandOption("foo", IsRequired = true)]
|
||||||
public IReadOnlyList<string> Foo { get; set; }
|
public IReadOnlyList<string> Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -720,15 +751,17 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption(""foo"")]
|
[CommandOption("foo")]
|
||||||
public string Foo { get; set; }
|
public string Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -754,15 +787,17 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandOption(""foo"")]
|
[CommandOption("foo")]
|
||||||
public string Foo { get; set; }
|
public string Foo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
|
|||||||
@@ -21,24 +21,26 @@ public class ParameterBindingSpecs : SpecsBase
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandParameter(0)]
|
[CommandParameter(0)]
|
||||||
public string Foo { get; set; }
|
public string Foo { get; set; }
|
||||||
|
|
||||||
[CommandParameter(1)]
|
[CommandParameter(1)]
|
||||||
public string Bar { get; set; }
|
public string Bar { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""Foo = "" + Foo);
|
console.Output.WriteLine("Foo = " + Foo);
|
||||||
console.Output.WriteLine(""Bar = "" + Bar);
|
console.Output.WriteLine("Bar = " + Bar);
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -67,33 +69,35 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandParameter(0)]
|
[CommandParameter(0)]
|
||||||
public string Foo { get; set; }
|
public string Foo { get; set; }
|
||||||
|
|
||||||
[CommandParameter(1)]
|
[CommandParameter(1)]
|
||||||
public string Bar { get; set; }
|
public string Bar { get; set; }
|
||||||
|
|
||||||
[CommandParameter(2)]
|
[CommandParameter(2)]
|
||||||
public IReadOnlyList<string> Baz { get; set; }
|
public IReadOnlyList<string> Baz { get; set; }
|
||||||
|
|
||||||
[CommandOption(""boo"")]
|
[CommandOption("boo")]
|
||||||
public string Boo { get; set; }
|
public string Boo { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""Foo = "" + Foo);
|
console.Output.WriteLine("Foo = " + Foo);
|
||||||
console.Output.WriteLine(""Bar = "" + Bar);
|
console.Output.WriteLine("Bar = " + Bar);
|
||||||
|
|
||||||
foreach (var i in Baz)
|
foreach (var i in Baz)
|
||||||
console.Output.WriteLine(""Baz = "" + i);
|
console.Output.WriteLine("Baz = " + i);
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -125,24 +129,26 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandParameter(0)]
|
[CommandParameter(0)]
|
||||||
public string Foo { get; set; }
|
public string Foo { get; set; }
|
||||||
|
|
||||||
[CommandParameter(1, IsRequired = false)]
|
[CommandParameter(1, IsRequired = false)]
|
||||||
public string Bar { get; set; } = ""xyz"";
|
public string Bar { get; set; } = "xyz";
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""Foo = "" + Foo);
|
console.Output.WriteLine("Foo = " + Foo);
|
||||||
console.Output.WriteLine(""Bar = "" + Bar);
|
console.Output.WriteLine("Bar = " + Bar);
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -171,18 +177,20 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandParameter(0)]
|
[CommandParameter(0)]
|
||||||
public string Foo { get; set; }
|
public string Foo { get; set; }
|
||||||
|
|
||||||
[CommandParameter(1)]
|
[CommandParameter(1)]
|
||||||
public string Bar { get; set; }
|
public string Bar { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -208,18 +216,20 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandParameter(0)]
|
[CommandParameter(0)]
|
||||||
public string Foo { get; set; }
|
public string Foo { get; set; }
|
||||||
|
|
||||||
[CommandParameter(1)]
|
[CommandParameter(1)]
|
||||||
public IReadOnlyList<string> Bar { get; set; }
|
public IReadOnlyList<string> Bar { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -245,18 +255,20 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
[CommandParameter(0)]
|
[CommandParameter(0)]
|
||||||
public string Foo { get; set; }
|
public string Foo { get; set; }
|
||||||
|
|
||||||
[CommandParameter(1)]
|
[CommandParameter(1)]
|
||||||
public string Bar { get; set; }
|
public string Bar { get; set; }
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
|
|||||||
@@ -21,37 +21,38 @@ public class RoutingSpecs : SpecsBase
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandTypes = DynamicCommandBuilder.CompileMany(
|
var commandTypes = DynamicCommandBuilder.CompileMany(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class DefaultCommand : ICommand
|
public class DefaultCommand : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""default"");
|
console.Output.WriteLine("default");
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command(""cmd"")]
|
[Command("cmd")]
|
||||||
public class NamedCommand : ICommand
|
public class NamedCommand : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""cmd"");
|
console.Output.WriteLine("cmd");
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command(""cmd child"")]
|
[Command("cmd child")]
|
||||||
public class NamedChildCommand : ICommand
|
public class NamedChildCommand : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""cmd child"");
|
console.Output.WriteLine("cmd child");
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
");
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommands(commandTypes)
|
.AddCommands(commandTypes)
|
||||||
@@ -77,37 +78,38 @@ public class NamedChildCommand : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandTypes = DynamicCommandBuilder.CompileMany(
|
var commandTypes = DynamicCommandBuilder.CompileMany(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class DefaultCommand : ICommand
|
public class DefaultCommand : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""default"");
|
console.Output.WriteLine("default");
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command(""cmd"")]
|
[Command("cmd")]
|
||||||
public class NamedCommand : ICommand
|
public class NamedCommand : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""cmd"");
|
console.Output.WriteLine("cmd");
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command(""cmd child"")]
|
[Command("cmd child")]
|
||||||
public class NamedChildCommand : ICommand
|
public class NamedChildCommand : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""cmd child"");
|
console.Output.WriteLine("cmd child");
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
");
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommands(commandTypes)
|
.AddCommands(commandTypes)
|
||||||
@@ -133,37 +135,38 @@ public class NamedChildCommand : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandTypes = DynamicCommandBuilder.CompileMany(
|
var commandTypes = DynamicCommandBuilder.CompileMany(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class DefaultCommand : ICommand
|
public class DefaultCommand : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""default"");
|
console.Output.WriteLine("default");
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command(""cmd"")]
|
[Command("cmd")]
|
||||||
public class NamedCommand : ICommand
|
public class NamedCommand : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""cmd"");
|
console.Output.WriteLine("cmd");
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command(""cmd child"")]
|
[Command("cmd child")]
|
||||||
public class NamedChildCommand : ICommand
|
public class NamedChildCommand : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""cmd child"");
|
console.Output.WriteLine("cmd child");
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
");
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommands(commandTypes)
|
.AddCommands(commandTypes)
|
||||||
|
|||||||
@@ -23,16 +23,18 @@ public class TypeActivationSpecs : SpecsBase
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""foo"");
|
console.Output.WriteLine("foo");
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -59,14 +61,16 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
public Command(string foo) {}
|
public Command(string foo) {}
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console) => default;
|
public ValueTask ExecuteAsync(IConsole console) => default;
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -93,20 +97,22 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
private readonly string _foo;
|
private readonly string _foo;
|
||||||
|
|
||||||
public Command(string foo) => _foo = foo;
|
public Command(string foo) => _foo = foo;
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(_foo);
|
console.Output.WriteLine(_foo);
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
@@ -133,20 +139,22 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
private readonly string _foo;
|
private readonly string _foo;
|
||||||
|
|
||||||
public Command(string foo) => _foo = foo;
|
public Command(string foo) => _foo = foo;
|
||||||
|
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(_foo);
|
console.Output.WriteLine(_foo);
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var serviceProvider = new ServiceCollection()
|
var serviceProvider = new ServiceCollection()
|
||||||
.AddSingleton(commandType, Activator.CreateInstance(commandType, "Hello world")!)
|
.AddSingleton(commandType, Activator.CreateInstance(commandType, "Hello world")!)
|
||||||
@@ -177,16 +185,18 @@ public class Command : ICommand
|
|||||||
// Arrange
|
// Arrange
|
||||||
var commandType = DynamicCommandBuilder.Compile(
|
var commandType = DynamicCommandBuilder.Compile(
|
||||||
// language=cs
|
// language=cs
|
||||||
@"
|
"""
|
||||||
[Command]
|
[Command]
|
||||||
public class Command : ICommand
|
public class Command : ICommand
|
||||||
{
|
{
|
||||||
public ValueTask ExecuteAsync(IConsole console)
|
public ValueTask ExecuteAsync(IConsole console)
|
||||||
{
|
{
|
||||||
console.Output.WriteLine(""foo"");
|
console.Output.WriteLine("foo");
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}");
|
}
|
||||||
|
"""
|
||||||
|
);
|
||||||
|
|
||||||
var application = new CliApplicationBuilder()
|
var application = new CliApplicationBuilder()
|
||||||
.AddCommand(commandType)
|
.AddCommand(commandType)
|
||||||
|
|||||||
Reference in New Issue
Block a user