diff --git a/.github/workflows/cd-build.yml b/.github/workflows/cd-build.yml index 9e720df..8371e76 100644 --- a/.github/workflows/cd-build.yml +++ b/.github/workflows/cd-build.yml @@ -10,9 +10,9 @@ jobs: steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2 - name: Setup .NET - uses: actions/setup-dotnet@c2fa09f4bde5ebb9d1777cf28262a3eb3db3ced7 #v5.2.0 + uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 #v6.0.0 with: - dotnet-version: 8.0.x + dotnet-version: 10.0.x - name: Restore dependencies run: dotnet restore src/MinimalCli.sln diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index 2c231d8..dee037c 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -10,9 +10,9 @@ jobs: steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2 - name: Setup .NET - uses: actions/setup-dotnet@c2fa09f4bde5ebb9d1777cf28262a3eb3db3ced7 #v5.2.0 + uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 #v6.0.0 with: - dotnet-version: 8.0.x + dotnet-version: 10.0.x - name: Restore dependencies run: dotnet restore src/MinimalCli.sln diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 07934f6..f3883b6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,9 +10,12 @@ jobs: steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2 - name: Setup .NET - uses: actions/setup-dotnet@c2fa09f4bde5ebb9d1777cf28262a3eb3db3ced7 #v5.2.0 + uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 #v6.0.0 with: - dotnet-version: 8.0.x + dotnet-version: | + 8.0.x + 9.0.x + 10.0.x - name: Restore dependencies run: dotnet restore src/MinimalCli.sln diff --git a/src/MinimalCli.Core/CommandBuilder.cs b/src/MinimalCli.Core/CommandBuilder.cs index 93e5518..3a20b78 100644 --- a/src/MinimalCli.Core/CommandBuilder.cs +++ b/src/MinimalCli.Core/CommandBuilder.cs @@ -158,8 +158,9 @@ public void SetHandler(Delegate handler) if (returnType == typeof(Task)) { - var task = (Task)_delegateHandler.DynamicInvoke(dynamicArguments.ToArray()); - return task; + Task? returnTask = _delegateHandler.DynamicInvoke(dynamicArguments.ToArray()) as Task; + return returnTask + ?? Task.FromException(new InvalidOperationException("Invoke of command failed.")); } else if (returnType == typeof(void)) { diff --git a/src/MinimalCli.Core/CommandBuilderOfT.cs b/src/MinimalCli.Core/CommandBuilderOfT.cs index 6fa7304..7c1cbdb 100644 --- a/src/MinimalCli.Core/CommandBuilderOfT.cs +++ b/src/MinimalCli.Core/CommandBuilderOfT.cs @@ -7,7 +7,7 @@ namespace MinimalCli; public class CommandBuilder where THandler : notnull { - IServiceProvider _serviceProvider; + readonly IServiceProvider _serviceProvider; internal Command Command; internal CommandBuilder(Command cmd, @@ -95,7 +95,9 @@ internal async Task handlerActivator(ParseResult parseResult) if (returnType == typeof(Task)) { - var task = (Task)dlgt.DynamicInvoke(dynamicArguments.ToArray()); + Task? task = dlgt.DynamicInvoke(dynamicArguments.ToArray()) as Task + ?? throw new InvalidOperationException("Invoke of command failed."); + await task.ConfigureAwait(false); } else if (returnType == typeof(void)) diff --git a/src/MinimalCli.Core/CommandExecutorShell.cs b/src/MinimalCli.Core/CommandExecutorShell.cs index 961478b..25c00d6 100644 --- a/src/MinimalCli.Core/CommandExecutorShell.cs +++ b/src/MinimalCli.Core/CommandExecutorShell.cs @@ -89,7 +89,7 @@ public int Execute(RootCommand rootCommand, string[] args) private static bool GetInput(RootCommand rootCommand, string prompt, string[] exitCommands, out ParseResult? result) { Console.Write(prompt + "> "); - string commandString = Console.ReadLine(); + string? commandString = Console.ReadLine() ?? ""; foreach (string exitCmd in exitCommands) { diff --git a/src/MinimalCli.Core/MinimalCli.Core.csproj b/src/MinimalCli.Core/MinimalCli.Core.csproj index 9229c8a..78a3649 100644 --- a/src/MinimalCli.Core/MinimalCli.Core.csproj +++ b/src/MinimalCli.Core/MinimalCli.Core.csproj @@ -1,7 +1,7 @@  - net8.0;netstandard2.0 + net8.0;net9.0;net10.0;netstandard2.0 latest enable MinimalCli.Core diff --git a/src/MinimalCli.Core/MinimalCommandLineApp.cs b/src/MinimalCli.Core/MinimalCommandLineApp.cs index 83ea857..a95142d 100644 --- a/src/MinimalCli.Core/MinimalCommandLineApp.cs +++ b/src/MinimalCli.Core/MinimalCommandLineApp.cs @@ -197,7 +197,8 @@ public void SetRootHandler(Delegate handler) if (returnType == typeof(Task)) { - var task = (Task)_delegateHandler.DynamicInvoke(dynamicArguments.ToArray()); + Task task = _delegateHandler.DynamicInvoke(dynamicArguments.ToArray()) as Task + ?? throw new InvalidOperationException("Invoke of command failed."); return task; } else if (returnType == typeof(void)) diff --git a/src/MinimalCli.Templates/content/console/MinimalCliApp.csproj b/src/MinimalCli.Templates/content/console/MinimalCliApp.csproj index cbeac75..d5f58e2 100644 --- a/src/MinimalCli.Templates/content/console/MinimalCliApp.csproj +++ b/src/MinimalCli.Templates/content/console/MinimalCliApp.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/MinimalCli/MinimalCli.csproj b/src/MinimalCli/MinimalCli.csproj index ec181dc..1fb7546 100644 --- a/src/MinimalCli/MinimalCli.csproj +++ b/src/MinimalCli/MinimalCli.csproj @@ -1,7 +1,7 @@  - net8.0;netstandard2.0 + net8.0;net9.0;net10.0;netstandard2.0 latest enable MinimalCli @@ -27,9 +27,11 @@ - + + + - +