-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding System.CommandLine template (#18)
* WIP command line app * Updating to latest System.CommandLine * Version 1.3.0 * Updating READMEs
- Loading branch information
Showing
19 changed files
with
767 additions
and
5 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
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
dotnet new uninstall Keboo.Dotnet.Templates | ||
Remove-Item -Path "Keboo.Dotnet.Templates.*.nupkg" | ||
|
||
dotnet pack -o . | ||
|
||
dotnet new install Keboo.Dotnet.Templates.1.0.0.nupkg | ||
dotnet new install $(Get-ChildItem -Path "Keboo.Dotnet.Templates.*.nupkg").Name |
Large diffs are not rendered by default.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
templates/Console/ConsoleApp/.template.config/template.json
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,63 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/template", | ||
"author": "Keboo", | ||
"classifications": [ | ||
"Common", | ||
"CommandLine" | ||
], | ||
"identity": "Keboo.Console.ConsoleApp", | ||
"name": "Keboo CLI Application", | ||
"shortName": "keboo.console", | ||
"tags": { | ||
"language": "C#", | ||
"type": "solution" | ||
}, | ||
"preferNameDirectory":true, | ||
"sourceName": "ConsoleApp", | ||
"symbols":{ | ||
"createdDate": { | ||
"type": "generated", | ||
"generator": "now", | ||
"parameters": { | ||
"format": "yyyy" | ||
}, | ||
"replaces":"1970" | ||
}, | ||
"user_secrets_id":{ | ||
"type": "generated", | ||
"generator": "guid", | ||
"replaces": "12345678-9abc-0123-4567-890abcdef123", | ||
"parameters": { | ||
"defaultFormat":"d" | ||
} | ||
}, | ||
"no-sln": { | ||
"type": "parameter", | ||
"dataType":"bool", | ||
"defaultValue": "false" | ||
}, | ||
"no-tests": { | ||
"type": "parameter", | ||
"dataType":"bool", | ||
"defaultValue": "false" | ||
} | ||
}, | ||
"sources": [ | ||
{ | ||
"modifiers": [ | ||
{ | ||
"condition": "(no-sln)", | ||
"exclude": [ | ||
"ConsoleApp.sln" | ||
] | ||
}, | ||
{ | ||
"condition": "(no-tests)", | ||
"exclude": [ | ||
"ConsoleApp.Tests/*" | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
28 changes: 28 additions & 0 deletions
28
templates/Console/ConsoleApp/ConsoleApp.Tests/ConsoleApp.Tests.csproj
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,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" /> | ||
<PackageReference Include="Moq" /> | ||
<PackageReference Include="Moq.AutoMock" /> | ||
<PackageReference Include="System.CommandLine" /> | ||
<PackageReference Include="xunit" /> | ||
<PackageReference Include="xunit.runner.visualstudio" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ConsoleApp\ConsoleApp.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit" /> | ||
<Using Include="Moq.AutoMock" /> | ||
</ItemGroup> | ||
|
||
</Project> |
33 changes: 33 additions & 0 deletions
33
templates/Console/ConsoleApp/ConsoleApp.Tests/ProgramTests.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,33 @@ | ||
using System.CommandLine; | ||
|
||
namespace ConsoleApp.Tests; | ||
|
||
public class ProgramTests | ||
{ | ||
[Fact] | ||
public async Task Invoke_WithHelpOption_DisplaysHelp() | ||
{ | ||
using StringWriter stdOut = new(); | ||
int exitCode = await Invoke("--help", stdOut); | ||
|
||
Assert.Equal(0, exitCode); | ||
Assert.Contains("--help", stdOut.ToString()); | ||
} | ||
|
||
[Fact] | ||
public async Task Invoke_AddWithTwoNumbers_DisplaysResult() | ||
{ | ||
using StringWriter stdOut = new(); | ||
int exitCode = await Invoke("add 4 2", stdOut); | ||
|
||
Assert.Equal(0, exitCode); | ||
Assert.Contains("The result is 6", stdOut.ToString()); | ||
} | ||
|
||
private static Task<int> Invoke(string commandLine, StringWriter console) | ||
{ | ||
CliConfiguration configuration = Program.GetConfiguration(); | ||
configuration.Output = console; | ||
return configuration.InvokeAsync(commandLine); | ||
} | ||
} |
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,40 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31903.59 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp", "ConsoleApp\ConsoleApp.csproj", "{55D459AD-9D92-4A4A-ADAB-D0143BA39451}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp.Tests", "ConsoleApp.Tests\ConsoleApp.Tests.csproj", "{E0A57BAE-FFD5-46A6-9A93-33DF9195362B}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D88D7F20-19C5-42B4-8561-874CC78B134A}" | ||
ProjectSection(SolutionItems) = preProject | ||
.editorconfig = .editorconfig | ||
Directory.Build.props = Directory.Build.props | ||
Directory.Build.targets = Directory.Build.targets | ||
Directory.Packages.props = Directory.Packages.props | ||
NuGet.config = NuGet.config | ||
EndProjectSection | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{55D459AD-9D92-4A4A-ADAB-D0143BA39451}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{55D459AD-9D92-4A4A-ADAB-D0143BA39451}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{55D459AD-9D92-4A4A-ADAB-D0143BA39451}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{55D459AD-9D92-4A4A-ADAB-D0143BA39451}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{E0A57BAE-FFD5-46A6-9A93-33DF9195362B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{E0A57BAE-FFD5-46A6-9A93-33DF9195362B}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{E0A57BAE-FFD5-46A6-9A93-33DF9195362B}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{E0A57BAE-FFD5-46A6-9A93-33DF9195362B}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {DF353750-2089-4072-9508-65E9DC66DF2D} | ||
EndGlobalSection | ||
EndGlobal |
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,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="System.CommandLine" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,42 @@ | ||
using System.CommandLine; | ||
|
||
namespace ConsoleApp; | ||
|
||
public sealed class Program | ||
{ | ||
private static Task<int> Main(string[] args) | ||
{ | ||
CliConfiguration configuration = GetConfiguration(); | ||
return configuration.InvokeAsync(args); | ||
} | ||
|
||
public static CliConfiguration GetConfiguration() | ||
{ | ||
CliArgument<int> number1 = new("number1") | ||
{ | ||
Description = "The first number to add" | ||
}; | ||
CliArgument<int> number2 = new("number2") | ||
{ | ||
Description = "The second number to add" | ||
}; | ||
CliCommand addCommand = new("add", "Add two numbers together") | ||
{ | ||
number1, | ||
number2 | ||
}; | ||
addCommand.SetAction((ParseResult parseResult) => | ||
{ | ||
int value1 = parseResult.CommandResult.GetValue(number1); | ||
int value2 = parseResult.CommandResult.GetValue(number2); | ||
int result = value1 + value2; | ||
parseResult.Configuration.Output.WriteLine($"The result is {result}"); | ||
}); | ||
|
||
CliRootCommand rootCommand = new("A starter console app by Keboo") | ||
{ | ||
addCommand | ||
}; | ||
return new CliConfiguration(rootCommand); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
templates/Console/ConsoleApp/ConsoleApp/Properties/launchSettings.json
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,11 @@ | ||
{ | ||
"profiles": { | ||
"ConsoleApp": { | ||
"commandName": "Project" | ||
}, | ||
"Display Help": { | ||
"commandName": "Project", | ||
"commandLineArgs": "--help" | ||
} | ||
} | ||
} |
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,26 @@ | ||
<!-- | ||
This file allow for customizing your build process. | ||
See: https://learn.microsoft.com/visualstudio/msbuild/customize-your-build | ||
--> | ||
<Project> | ||
<!-- | ||
Uncomment if you need to enable inclusion of another Directory.Build.props file from a parent directory | ||
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" /> | ||
--> | ||
|
||
<PropertyGroup> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<LangVersion>11</LangVersion> | ||
</PropertyGroup> | ||
|
||
<!-- | ||
This allows all projects to share the same user secrets file. | ||
If you want project to have their own, set it to a different GUID on each project. | ||
See: https://learn.microsoft.com/dotnet/architecture/microservices/secure-net-microservices-web-applications/developer-app-secrets-storage | ||
--> | ||
<PropertyGroup Label="User Secrets"> | ||
<UserSecretsId>12345678-9abc-0123-4567-890abcdef123</UserSecretsId> | ||
</PropertyGroup> | ||
|
||
</Project> |
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,10 @@ | ||
<!-- | ||
This file allow for customizing your build process. | ||
See: https://learn.microsoft.com/visualstudio/msbuild/customize-your-build | ||
--> | ||
<Project> | ||
<!-- | ||
Uncomment if you need to enable inclusion of another Directory.Build.targets file from a parent directory | ||
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" /> | ||
--> | ||
</Project> |
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,36 @@ | ||
<!-- | ||
This enabled central package management. | ||
This allows for controling all NuGet packages within the Directory.Packages.props file | ||
See https://learn.microsoft.com/nuget/consume-packages/Central-Package-Management | ||
--> | ||
<Project> | ||
<!-- | ||
Uncomment if you need to enable inclusion of another Directory.Packages.props file from a parent directory | ||
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Packages.props, $(MSBuildThisFileDirectory)..))" /> | ||
--> | ||
<!-- This property enables the Central Package Management feature --> | ||
<PropertyGroup> | ||
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> | ||
</PropertyGroup> | ||
<!-- | ||
This defines the set of centrally managed packages. | ||
This would typically list all NuGet packages used within this solution. | ||
--> | ||
<ItemGroup> | ||
<PackageVersion Include="coverlet.collector" Version="3.2.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageVersion> | ||
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" /> | ||
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="7.0.1" /> | ||
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.5.0" /> | ||
<PackageVersion Include="Moq" Version="4.18.4" /> | ||
<PackageVersion Include="Moq.AutoMock" Version="3.5.0" /> | ||
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.23219.2" /> | ||
<PackageVersion Include="xunit" Version="2.4.2" /> | ||
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageVersion> | ||
</ItemGroup> | ||
</Project> |
Oops, something went wrong.