-
-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose raw arguments on the command context
- Loading branch information
1 parent
de04619
commit 95bff47
Showing
6 changed files
with
62 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/Spectre.Console.Cli/Internal/Extensions/EnumerableExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Spectre.Console.Cli; | ||
|
||
internal static class EnumerableExtensions | ||
{ | ||
public static IReadOnlyList<T> ToSafeReadOnlyList<T>(this IEnumerable<T> source) | ||
{ | ||
return source switch | ||
{ | ||
null => new List<T>(), | ||
IReadOnlyList<T> list => list, | ||
_ => source.ToList(), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
test/Spectre.Console.Cli.Tests/Unit/CommandAppTests.Context.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace Spectre.Console.Tests.Unit.Cli; | ||
|
||
public sealed partial class CommandAppTests | ||
{ | ||
[Fact] | ||
[Expectation("Should_Expose_Raw_Arguments")] | ||
public void Should_Return_Correct_Text_When_Command_Is_Unknown() | ||
{ | ||
// Given | ||
var app = new CommandAppTester(); | ||
app.Configure(config => | ||
{ | ||
config.AddCommand<EmptyCommand>("test"); | ||
}); | ||
|
||
// When | ||
var result = app.Run("test", "--foo", "32", "--lol"); | ||
|
||
// Then | ||
result.Context.ShouldNotBeNull(); | ||
result.Context.Arguments.ShouldBe(new[] { "test", "--foo", "32", "--lol" }); | ||
} | ||
} |