Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@
"version": 1,
"isRoot": true,
"tools": {
"dotnet-format": {
"version": "5.1.250801",
"commands": [
"dotnet-format"
]
},
"docfx": {
"version": "2.78.5",
"commands": [
"docfx"
]
}
}
}
}
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ csharp_style_expression_bodied_indexers = true
csharp_style_expression_bodied_accessors = true
csharp_style_throw_expression = true

# Remove unnecessary usings
dotnet_diagnostic.IDE0005.severity = warning

# Default severity for analyzer diagnostics with category 'Style' (escalated to build warnings)
# dotnet_analyzer_diagnostic.category-Style.severity = suggestion

Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/claude-code-review.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
name: Claude Code Review

on:
pull_request:
pull_request_target:
types: [opened, synchronize]

jobs:
claude-review:
# Only run on PRs from branches in the same repository, not from forks
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
permissions:
contents: read
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/claude.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ jobs:
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
) && (
github.event_name == 'issues' ||
github.event_name == 'issue_comment' ||
github.event.pull_request.head.repo.full_name == github.repository
)
runs-on: ubuntu-latest
permissions:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [Unreleased changes](https://github.com/natemcmaster/CommandLineUtils/compare/v5.0.1...main)

### Features
* [@Chris-Wolfgang]: Add support for keyed dependency injection via `[FromKeyedServices]` attribute ([#560])

[#560]: https://github.com/natemcmaster/CommandLineUtils/pull/560

## [v5.0.1](https://github.com/natemcmaster/CommandLineUtils/compare/v5.0.0...v5.0.1)

### Features
Expand Down
6 changes: 5 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</PropertyGroup>

<PropertyGroup>
<VersionPrefix>5.0.1</VersionPrefix>
<VersionPrefix>5.1.0</VersionPrefix>
<VersionSuffix>beta</VersionSuffix>
<IncludePreReleaseLabelInPackageVersion Condition="'$(IS_STABLE_BUILD)' != 'true'">true</IncludePreReleaseLabelInPackageVersion>
<BuildNumber Condition=" '$(BuildNumber)' == '' ">$(GITHUB_RUN_NUMBER)</BuildNumber>
Expand All @@ -60,6 +60,10 @@
<PackageReference Include="PolySharp" Version="1.15.0" PrivateAssets="All" />
</ItemGroup>

<PropertyGroup>
<PolySharpIncludeRuntimeSupportedAttributes>true</PolySharpIncludeRuntimeSupportedAttributes>
</PropertyGroup>

<Import Project="$(MSBuildProjectDirectory)/releasenotes.props"
Condition="Exists('$(MSBuildProjectDirectory)/releasenotes.props')" />

Expand Down
6 changes: 3 additions & 3 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ exec dotnet tool restore

[string[]] $formatArgs=@()
if ($ci) {
$formatArgs += '--check'
$formatArgs += '--verify-no-changes'
}

exec dotnet tool run dotnet-format -- -v detailed @formatArgs "$PSScriptRoot/CommandLineUtils.sln"
exec dotnet tool run dotnet-format -- -v detailed @formatArgs "$PSScriptRoot/docs/samples/samples.sln"
exec dotnet format -- @formatArgs "$PSScriptRoot/CommandLineUtils.sln"
exec dotnet format -- @formatArgs "$PSScriptRoot/docs/samples/samples.sln"
exec dotnet build --configuration $Configuration '-warnaserror:CS1591'
exec dotnet pack --no-build --configuration $Configuration -o $artifacts
exec dotnet build --configuration $Configuration "$PSScriptRoot/docs/samples/samples.sln"
Expand Down
2 changes: 1 addition & 1 deletion docs/samples/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<ItemGroup>
<PackageReference Remove="McMaster.Extensions.CommandLineUtils" />
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\src\CommandLineUtils\*.csproj" />
<ProjectReference Include="$(MSBuildThisFileDirectory)..\..\src\CommandLineUtils\McMaster.Extensions.CommandLineUtils.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<ItemGroup>
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.5" />
</ItemGroup>

</Project>
4 changes: 3 additions & 1 deletion docs/samples/dependency-injection/custom/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
// Copyright (c) Nate McMaster.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using McMaster.Extensions.CommandLineUtils;
using Microsoft.Extensions.DependencyInjection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.3" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.5" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.5" />
</ItemGroup>

<ItemGroup>
Expand Down
7 changes: 4 additions & 3 deletions docs/samples/dependency-injection/generic-host/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;
using System.Threading;
// Copyright (c) Nate McMaster.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Threading.Tasks;
using McMaster.Extensions.CommandLineUtils;
using McMaster.Extensions.Hosting.CommandLine;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
Expand Down
13 changes: 13 additions & 0 deletions docs/samples/dependency-injection/keyed/KeyedServices.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="5.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.5" />
</ItemGroup>

</Project>
58 changes: 58 additions & 0 deletions docs/samples/dependency-injection/keyed/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) Nate McMaster.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using McMaster.Extensions.CommandLineUtils;
using Microsoft.Extensions.DependencyInjection;

namespace KeyedServices
{
[Command(Name = "keyed-di", Description = "Keyed Dependency Injection sample project")]
[HelpOption]
class Program
{
public static int Main(string[] args)
{
var services = new ServiceCollection()
.AddKeyedSingleton<IGreeter, FormalGreeter>("formal")
.AddKeyedSingleton<IGreeter, CasualGreeter>("casual")
.AddSingleton<IConsole>(PhysicalConsole.Singleton)
.BuildServiceProvider();

var app = new CommandLineApplication<Program>();
app.Conventions.UseDefaultConventions()
.UseConstructorInjection(services);
return app.Execute(args);
}

[Option(Description = "The subject to greet")]
public string Subject { get; set; } = "world";

[Option(Description = "Use casual greeting")]
public bool Casual { get; set; }

private int OnExecute(
[FromKeyedServices("formal")] IGreeter formalGreeter,
[FromKeyedServices("casual")] IGreeter casualGreeter,
IConsole console)
{
var greeter = Casual ? casualGreeter : formalGreeter;
console.WriteLine(greeter.Greet(Subject));
return 0;
}
}

interface IGreeter
{
string Greet(string subject);
}

class FormalGreeter : IGreeter
{
public string Greet(string subject) => $"Good day, {subject}. How do you do?";
}

class CasualGreeter : IGreeter
{
public string Greet(string subject) => $"Hey {subject}!";
}
}
4 changes: 3 additions & 1 deletion docs/samples/dependency-injection/standard/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
// Copyright (c) Nate McMaster.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Threading.Tasks;
using McMaster.Extensions.CommandLineUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.3" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.5" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 4 additions & 1 deletion docs/samples/generic-host/AttributeApi/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
// Copyright (c) Nate McMaster.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Threading.Tasks;
using McMaster.Extensions.CommandLineUtils;
using Microsoft.Extensions.Hosting;
Expand Down
2 changes: 1 addition & 1 deletion docs/samples/generic-host/BuilderApi/BuilderApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.3" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.5" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 4 additions & 1 deletion docs/samples/generic-host/BuilderApi/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
// Copyright (c) Nate McMaster.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Threading.Tasks;
using McMaster.Extensions.CommandLineUtils;
using Microsoft.Extensions.DependencyInjection;
Expand Down
5 changes: 4 additions & 1 deletion docs/samples/helloworld-async/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
// Copyright (c) Nate McMaster.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Threading.Tasks;
using McMaster.Extensions.CommandLineUtils;

Expand Down
5 changes: 4 additions & 1 deletion docs/samples/helloworld-attributes/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
// Copyright (c) Nate McMaster.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using McMaster.Extensions.CommandLineUtils;

public class Program
Expand Down
3 changes: 3 additions & 0 deletions docs/samples/helloworld/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Nate McMaster.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using McMaster.Extensions.CommandLineUtils;

Expand Down
8 changes: 4 additions & 4 deletions docs/samples/interactive-prompts/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static void Main(string[] args)
promptColor: ConsoleColor.White,
promptBgColor: ConsoleColor.DarkGreen);

Console.WriteLine($"Hello, there { name ?? "anonymous console user"}.");
Console.WriteLine($"Hello, there {name ?? "anonymous console user"}.");

var age = Prompt.GetInt("How old are you?",
promptColor: ConsoleColor.White,
Expand All @@ -32,13 +32,13 @@ static void Main(string[] args)
Console.Write($"Your password contains {password.Length} characters. ");
switch (password.Length)
{
case int _ when (password.Length < 2):
case int _ when password.Length < 2:
Console.WriteLine("Your password is so short you might as well not have one.");
break;
case int _ when (password.Length < 4):
case int _ when password.Length < 4:
Console.WriteLine("Your password is too short. You should pick a better one");
break;
case int _ when (password.Length < 10):
case int _ when password.Length < 10:
Console.WriteLine("Your password is too okay, I guess.");
break;
default:
Expand Down
4 changes: 3 additions & 1 deletion docs/samples/pager/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
// Copyright (c) Nate McMaster.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using McMaster.Extensions.CommandLineUtils;

class Program
Expand Down
3 changes: 3 additions & 0 deletions docs/samples/passthru-args/attributes/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Nate McMaster.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Diagnostics;
using System.Linq;
Expand Down
3 changes: 3 additions & 0 deletions docs/samples/passthru-args/builder-api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Nate McMaster.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Diagnostics;
using System.Linq;
Expand Down
4 changes: 3 additions & 1 deletion docs/samples/response-file-parsing/attributes/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
// Copyright (c) Nate McMaster.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using McMaster.Extensions.CommandLineUtils;

namespace ResponseFileParsing
Expand Down
4 changes: 3 additions & 1 deletion docs/samples/response-file-parsing/builder-api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
// Copyright (c) Nate McMaster.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using McMaster.Extensions.CommandLineUtils;

namespace ResponseFileParsing
Expand Down
15 changes: 15 additions & 0 deletions docs/samples/samples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld", "helloworld\He
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorldAttributes", "helloworld-attributes\HelloWorldAttributes.csproj", "{81F83C18-B60C-4A3F-8896-4B280A8F06D6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KeyedServices", "dependency-injection\keyed\KeyedServices.csproj", "{30674755-09B2-41DC-8AAD-31AC4541E562}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -375,6 +377,18 @@ Global
{81F83C18-B60C-4A3F-8896-4B280A8F06D6}.Release|x64.Build.0 = Release|Any CPU
{81F83C18-B60C-4A3F-8896-4B280A8F06D6}.Release|x86.ActiveCfg = Release|Any CPU
{81F83C18-B60C-4A3F-8896-4B280A8F06D6}.Release|x86.Build.0 = Release|Any CPU
{30674755-09B2-41DC-8AAD-31AC4541E562}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{30674755-09B2-41DC-8AAD-31AC4541E562}.Debug|Any CPU.Build.0 = Debug|Any CPU
{30674755-09B2-41DC-8AAD-31AC4541E562}.Debug|x64.ActiveCfg = Debug|Any CPU
{30674755-09B2-41DC-8AAD-31AC4541E562}.Debug|x64.Build.0 = Debug|Any CPU
{30674755-09B2-41DC-8AAD-31AC4541E562}.Debug|x86.ActiveCfg = Debug|Any CPU
{30674755-09B2-41DC-8AAD-31AC4541E562}.Debug|x86.Build.0 = Debug|Any CPU
{30674755-09B2-41DC-8AAD-31AC4541E562}.Release|Any CPU.ActiveCfg = Release|Any CPU
{30674755-09B2-41DC-8AAD-31AC4541E562}.Release|Any CPU.Build.0 = Release|Any CPU
{30674755-09B2-41DC-8AAD-31AC4541E562}.Release|x64.ActiveCfg = Release|Any CPU
{30674755-09B2-41DC-8AAD-31AC4541E562}.Release|x64.Build.0 = Release|Any CPU
{30674755-09B2-41DC-8AAD-31AC4541E562}.Release|x86.ActiveCfg = Release|Any CPU
{30674755-09B2-41DC-8AAD-31AC4541E562}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -394,6 +408,7 @@ Global
{1EE15348-5FF4-4988-AEA4-3E267ED4C288} = {75E74B42-039E-4661-B39C-160363B6884A}
{A4F3D30A-4124-49B0-A888-F81CE682F491} = {13EC390A-3D6F-4A7E-A02C-D3CBA197FA40}
{B38FF032-9AFB-481F-A432-DFA7A5100C3A} = {13EC390A-3D6F-4A7E-A02C-D3CBA197FA40}
{30674755-09B2-41DC-8AAD-31AC4541E562} = {E03982B3-80F2-4D55-9501-378EACE93E5B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {43B81702-C1EF-43B6-B57D-C630AD1F555D}
Expand Down
Loading
Loading