Skip to content

Commit 7fabaf5

Browse files
authored
Merge pull request #6 from di-VISION-Dev/develop
Merge 0.1.0 changes from develop into main
2 parents 7413c90 + 6e96ceb commit 7fabaf5

10 files changed

+52
-30
lines changed

Common.Build.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
<PropertyGroup Condition="Exists('$(MSBuildProjectDirectory)\readme.md')">
1717
<PackageReadmeFile>readme.md</PackageReadmeFile>
1818
</PropertyGroup>
19-
<PropertyGroup Condition="!Exists('$(MSBuildProjectDirectory)\readme.md') And Exists('$(MSBuildThisFileDirectory)Readme.md')">
20-
<PackageReadmeFile>Readme.md</PackageReadmeFile>
19+
<PropertyGroup Condition="!Exists('$(MSBuildProjectDirectory)\readme.md') And Exists('$(MSBuildThisFileDirectory)README.md')">
20+
<PackageReadmeFile>README.md</PackageReadmeFile>
2121
</PropertyGroup>
2222

2323
<!-- <ItemGroup> -->
@@ -26,7 +26,7 @@
2626
<ItemGroup Condition="Exists('$(MSBuildProjectDirectory)\readme.md')">
2727
<None Include="readme.md" Pack="true" PackagePath="\"/>
2828
</ItemGroup>
29-
<ItemGroup Condition="!Exists('$(MSBuildProjectDirectory)\readme.md') And Exists('$(MSBuildThisFileDirectory)Readme.md')">
30-
<None Include="$(MSBuildThisFileDirectory)Readme.md" Pack="true" PackagePath="\"/>
29+
<ItemGroup Condition="!Exists('$(MSBuildProjectDirectory)\readme.md') And Exists('$(MSBuildThisFileDirectory)README.md')">
30+
<None Include="$(MSBuildThisFileDirectory)README.md" Pack="true" PackagePath="\"/>
3131
</ItemGroup>
3232
</Project>

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# command-line-x
22
![Tool](https://img.shields.io/badge/.Net-8-lightblue) [<img src="https://img.shields.io/github/v/release/di-VISION-Dev/command-line-x" title="Latest">](../../releases/latest)
33

4-
[System.CommandLine](https://github.com/dotnet/command-line-api) is a really handy .Net library for parsing command line arguments passed to an application. Unfortunately some useful features available in its beta stage were removed from the library's release candidates. CommandLineX brings back some of them: **hosting extensions** and **arguments model binding** including DI.
4+
[System.CommandLine](https://github.com/dotnet/command-line-api) is a really handy .Net library for parsing command line arguments passed to an application. Unfortunately a couple of useful features available in its beta stage were removed from the library's release candidates. CommandLineX brings back some of them: **hosting extensions** and **arguments model binding** including DI.
55

66
## Getting Started
77
### Creating Console App
@@ -75,7 +75,7 @@ dotnet add package diVISION.CommandLineX
7575
{
7676
Arity = new(1, 2)
7777
},
78-
new Option<DirectoryInfo>("-d", ["--directory"])
78+
new Option<DirectoryInfo>("--directory", "-d")
7979
{
8080
Description = "Some directory to use",
8181
DefaultValueFactory = (_) => new DirectoryInfo(".")

src/CommandLineX/CommandLineX.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<TargetFramework>net8.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
8-
<Version>0.1.0-rc02</Version>
8+
<Version>0.1.0</Version>
99
<Description>Hosting and model binding extensions for System.CommandLine</Description>
1010
</PropertyGroup>
1111

@@ -21,8 +21,8 @@
2121
</PropertyGroup>
2222

2323
<ItemGroup>
24-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.9" />
25-
<PackageReference Include="System.CommandLine" Version="2.0.0-rc.1.25451.107" />
24+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.0" />
25+
<PackageReference Include="System.CommandLine" Version="2.0.0" />
2626
</ItemGroup>
2727

2828
<ItemGroup>

src/CommandLineX/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# CommandLine Extensions
2+
[System.CommandLine](https://github.com/dotnet/command-line-api) is a really handy .Net library for parsing command line arguments passed to an application. Unfortunately a couple of useful features available in its beta stage were removed from the library's release candidates. CommandLineX brings back some of them: **hosting extensions** and **arguments model binding** including DI.
3+
4+
For more details please refer to [the project repository](https://github.com/di-VISION-Dev/command-line-x).

test/CommandLineX.Tests/AsyncBindingCommandLineActionTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public async Task InvokeAsync_NoArgsCommandAction_returning_default_given_Comman
2626
var command = new Command("simple")
2727
{
2828
new Argument<int>("nonce"),
29-
new Option<string>("-f", ["--foo"])
29+
new Option<string>("--foo", "-f")
3030
};
3131

3232
var action = new NoArgsCommandAction();
@@ -113,7 +113,7 @@ public async Task InvokeAsync_OneStringOptionCommandAction_returning_Option_leng
113113
{
114114
var command = new Command("oneopt")
115115
{
116-
new Option<string>("-o", ["--the-option"])
116+
new Option<string>("--the-option", "-o")
117117
};
118118
var action = new OneStringOptionCommandAction();
119119
var bindingAction = new AsyncBindingCommandLineAction<OneStringOptionCommandAction>(command, () => action);
@@ -144,7 +144,7 @@ public async Task InvokeAsync_ComplexArgAndOptionCommandAction_returning_Symbol_
144144
var command = new Command("argandopt")
145145
{
146146
new Argument<IEnumerable<Guid>>("guid-args"),
147-
new Option<FileInfo>("-f", ["--file-option"])
147+
new Option<FileInfo>("--file-option", "-f")
148148
};
149149
var action = new ComplexArgAndOptionCommandAction();
150150
var bindingAction = new AsyncBindingCommandLineAction<ComplexArgAndOptionCommandAction>(command, () => action);
@@ -162,7 +162,7 @@ public async Task InvokeAsync_ComplexArgAndOptionCommandAction_returning_Symbol_
162162
var command = new Command("argandopt")
163163
{
164164
new Argument<IEnumerable<Guid>>("guid-args"),
165-
new Option<FileInfo>("-f", ["--file-option"])
165+
new Option<FileInfo>("--file-option", "-f")
166166
};
167167
var action = new ComplexArgAndOptionCommandAction();
168168
var bindingAction = new AsyncBindingCommandLineAction<ComplexArgAndOptionCommandAction>(command, () => action);

test/CommandLineX.Tests/CommandActionBinderTest.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,32 @@ public void Create_binding_to_OneStringOptionCommandAction_with_string_Symbol_gi
8787
{
8888
var binder = CommandActionBinder<OneStringOptionCommandAction>.Create(new("oneopt")
8989
{
90-
new Option<string>("-o", ["--the-option"])
90+
new Option<string>("--the-option", "-o")
9191
}, () => new());
9292
binder.Should().NotBeNull();
9393
binder.TypeBindings.GetMappings().Should()
9494
.NotBeEmpty()
9595
.And.AllSatisfy(mapping =>
9696
{
97-
mapping.Key.Name.Should().Be("-o");
97+
mapping.Key.Name.Should().Be("--the-option");
98+
mapping.Value.Name.Should().Be("TheOption");
99+
});
100+
binder.TypeBindings.GetUnboundSymbols().Should().BeEmpty();
101+
}
102+
103+
[TestMethod]
104+
public void Create_binding_to_OneStringOptionCommandAction_with_string_Symbol_by_alias_given_Command_with_string_option()
105+
{
106+
var binder = CommandActionBinder<OneStringOptionCommandAction>.Create(new("oneopt")
107+
{
108+
new Option<string>("--very-fancy-option", "--the-option", "-o")
109+
}, () => new());
110+
binder.Should().NotBeNull();
111+
binder.TypeBindings.GetMappings().Should()
112+
.NotBeEmpty()
113+
.And.AllSatisfy(mapping =>
114+
{
115+
mapping.Key.Name.Should().Be("--very-fancy-option");
98116
mapping.Value.Name.Should().Be("TheOption");
99117
});
100118
binder.TypeBindings.GetUnboundSymbols().Should().BeEmpty();
@@ -123,14 +141,14 @@ public void Create_binding_to_ComplexArgAndOptionCommandAction_with_both_Symbols
123141
var binder = new CommandActionBinder<ComplexArgAndOptionCommandAction>(new("argandopt")
124142
{
125143
new Argument<IEnumerable<Guid>>("guid-args"),
126-
new Option<FileInfo>("-f", ["--file-option"])
144+
new Option<FileInfo>("--file-option", "-f")
127145
}, new());
128146
binder.Should().NotBeNull();
129147
binder.TypeBindings.GetMappings().Should()
130148
.NotBeEmpty()
131149
.And.Satisfy(
132150
mapping => "guid-args" == mapping.Key.Name && "GuidArgs" == mapping.Value.Name,
133-
mapping => "-f" == mapping.Key.Name && "FileOption" == mapping.Value.Name
151+
mapping => "--file-option" == mapping.Key.Name && "FileOption" == mapping.Value.Name
134152
);
135153
binder.TypeBindings.GetUnboundSymbols().Should().BeEmpty();
136154
}

test/CommandLineX.Tests/CommandLineHostedServiceTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public async Task StartAsync_logging_Exception_thrown_by_OneStringOptionCommandA
111111
var logger = new LoggerMock<CommandLineHostedService>();
112112
var command = new Command("oneopt")
113113
{
114-
new Option<string>("-o", ["--the-option"])
114+
new Option<string>("--the-option", "-o")
115115
};
116116
var invoker = SetupInvoker<OneStringOptionCommandAction>(command);
117117
var lifetime = new HostApplicationLifetimeMock();

test/CommandLineX.Tests/CommandLineX.Tests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
<LangVersion>latest</LangVersion>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
8-
<Version>0.1.0-rc02</Version>
8+
<Version>0.1.0</Version>
99
</PropertyGroup>
1010

1111
<ItemGroup>
1212
<PackageReference Include="coverlet.msbuild" Version="6.0.4">
1313
<PrivateAssets>all</PrivateAssets>
1414
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1515
</PackageReference>
16-
<PackageReference Include="FluentAssertions" Version="8.7.1" />
16+
<PackageReference Include="FluentAssertions" Version="8.8.0" />
1717
<PackageReference Include="coverlet.collector" Version="6.0.4">
1818
<PrivateAssets>all</PrivateAssets>
1919
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2020
</PackageReference>
21-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
22-
<PackageReference Include="MSTest" Version="3.11.0" />
21+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
22+
<PackageReference Include="MSTest" Version="4.0.2" />
2323
</ItemGroup>
2424

2525
<ItemGroup>

test/CommandLineX.Tests/CommmandLineHostingExtensionTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void RunCommandLine_returning_result_of_ComplexArgAndOptionCommandAction_
145145
.UseCommandWithAction<ComplexArgAndOptionCommandAction>(rootCommand, new("argandopt")
146146
{
147147
new Argument<IEnumerable<Guid>>("guid-args"),
148-
new Option<FileInfo>("-f", ["--file-option"])
148+
new Option<FileInfo>("--file-option", "-f")
149149
}, false);
150150
builder.Should().NotBeNull();
151151

@@ -180,7 +180,7 @@ public async Task RunCommandLineAsync_returning_result_of_ComplexArgAndOptionCom
180180
.UseCommandWithAction<ComplexArgAndOptionCommandAction>(rootCommand, new("argandopt")
181181
{
182182
new Argument<IEnumerable<Guid>>("guid-args"),
183-
new Option<FileInfo>("-f", ["--file-option"])
183+
new Option<FileInfo>("--file-option", "-f")
184184
}, false);
185185
builder.Should().NotBeNull();
186186

@@ -215,7 +215,7 @@ public void RunCommandLineHosted_returning_result_of_ComplexArgAndOptionCommandA
215215
.UseCommandWithAction<ComplexArgAndOptionCommandAction>(rootCommand, new("argandopt")
216216
{
217217
new Argument<IEnumerable<Guid>>("guid-args"),
218-
new Option<FileInfo>("-f", ["--file-option"])
218+
new Option<FileInfo>("--file-option", "-f")
219219
}, false);
220220
builder.Should().NotBeNull();
221221

@@ -250,7 +250,7 @@ public async Task RunCommandLineHostedAsync_returning_result_of_ComplexArgAndOpt
250250
.UseCommandWithAction<ComplexArgAndOptionCommandAction>(rootCommand, new("argandopt")
251251
{
252252
new Argument<IEnumerable<Guid>>("guid-args"),
253-
new Option<FileInfo>("-f", ["--file-option"])
253+
new Option<FileInfo>("--file-option", "-f")
254254
}, false);
255255
builder.Should().NotBeNull();
256256

test/CommandLineX.Tests/SyncBindingCommandLineActionTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void Invoke_NoArgsCommandAction_returning_default_given_Command_with_any_
2424
var command = new Command("simple")
2525
{
2626
new Argument<int>("nonce"),
27-
new Option<string>("-f", ["--foo"])
27+
new Option<string>("--foo", "-f")
2828
};
2929
var action = new NoArgsCommandAction();
3030
var bindingAction = new SyncBindingCommandLineAction<NoArgsCommandAction>(command, () => action);
@@ -94,7 +94,7 @@ public void Invoke_OneStringOptionCommandAction_returning_Option_length_given_Co
9494
{
9595
var command = new Command("oneopt")
9696
{
97-
new Option<string>("-o", ["--the-option"])
97+
new Option<string>("--the-option", "-o")
9898
};
9999
var action = new OneStringOptionCommandAction();
100100
var bindingAction = new SyncBindingCommandLineAction<OneStringOptionCommandAction>(command, () => action);
@@ -125,7 +125,7 @@ public void Invoke_ComplexArgAndOptionCommandAction_returning_Symbol_count_given
125125
var command = new Command("argandopt")
126126
{
127127
new Argument<IEnumerable<Guid>>("guid-args"),
128-
new Option<FileInfo>("-f", ["--file-option"])
128+
new Option<FileInfo>("--file-option", "-f")
129129
};
130130
var action = new ComplexArgAndOptionCommandAction();
131131
var bindingAction = new SyncBindingCommandLineAction<ComplexArgAndOptionCommandAction>(command, () => action);
@@ -143,7 +143,7 @@ public void Invoke_ComplexArgAndOptionCommandAction_returning_Symbol_count_given
143143
var command = new Command("argandopt")
144144
{
145145
new Argument<IEnumerable<Guid>>("guid-args"),
146-
new Option<FileInfo>("-f", ["--file-option"])
146+
new Option<FileInfo>("--file-option", "-f")
147147
};
148148
var action = new ComplexArgAndOptionCommandAction();
149149
var bindingAction = new SyncBindingCommandLineAction<ComplexArgAndOptionCommandAction>(command, () => action);

0 commit comments

Comments
 (0)