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: 8 additions & 0 deletions .github/workflows/cd-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ jobs:
# packs all nuget packages at once
- name: Pack Minimal Command Line Nuget Alpha
run: dotnet pack src/MinimalCli/MinimalCli.csproj -p:PackageVersion=2.0.0.${{github.run_number}}-alpha -o ./packages
- name: Pack Minimal Command Line Template Nuget Alpha
run: dotnet pack src/MinimalCli.Templates/MinimalCli.Templates.csproj -p:PackageVersion=2.0.0.${{github.run_number}}-alpha -o ./packages
- name: Pack Minimal Command Line Nuget
run: dotnet pack src/MinimalCli/MinimalCli.csproj -p:PackageVersion=2.0.0.${{github.run_number}} -o ./packages
- name: Pack Minimal Command Line Template Nuget
run: dotnet pack src/MinimalCli.Templates/MinimalCli.Templates.csproj -p:PackageVersion=2.0.0.${{github.run_number}} -o ./packages

- name: Publish Minimal Command Line Artifacts
uses: actions/upload-artifact@v4
Expand All @@ -52,6 +56,8 @@ jobs:
run: ls -R
- name: Push Minimal Command Line Nuget
run: dotnet nuget push ./MinimalCli.2.0.0.${{github.run_number}}-alpha.nupkg --api-key ${{secrets.NUGETKEY}} --source https://api.nuget.org/v3/index.json
- name: Push Minimal Command Line Template Nuget
run: dotnet nuget push ./MinimalCli.Templates.2.0.0.${{github.run_number}}-alpha.nupkg --api-key ${{secrets.NUGETKEY}} --source https://api.nuget.org/v3/index.json

production:
needs: integration
Expand All @@ -67,3 +73,5 @@ jobs:

- name: Push Minimal Command Line Nuget
run: dotnet nuget push ./MinimalCli.2.0.0.${{github.run_number}}.nupkg --api-key ${{secrets.NUGETKEY}} --source https://api.nuget.org/v3/index.json
- name: Push Minimal Command Line Template Nuget
run: dotnet nuget push ./MinimalCli.Templates.2.0.0.${{github.run_number}}.nupkg --api-key ${{secrets.NUGETKEY}} --source https://api.nuget.org/v3/index.json
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
> System.CommandLine and to create commands with minimal boilerplate. All you have to do
> to turn a function into a command is decorate it with the `[Handler]` attribute!

## Getting Started
# Getting Started

### Hello World:

Expand Down Expand Up @@ -48,7 +48,23 @@ await app.StartAsync();
This will map the HelloWorld class's `void Execute(..)` function to a command called `"hello"`, and it
will map the parameter `message` to a string Argument called `<Message>`.

## Installing MinimalCommandLine
# Installation

## Easy: using the project template

Simply run the following using the dotnet cli:

```
dotnet new install MinimalCli.Templates
```

Then you should be able to create a new MinimalCli project like this:

```
dotnet new minCli -n MyMinimalCliApp
```

## Advanced: Manually installing MinimalCli NuGet package

Add a reference to the nuget package `MinimalCommandLine`.

Expand All @@ -63,6 +79,8 @@ Add a reference to the nuget package `MinimalCommandLine`.
* Select the project you want to install it into
* Hit Install

# Examples

## Simple Examples:

### Simple Command - Defaults:
Expand Down
41 changes: 41 additions & 0 deletions src/MinimalCli.Templates/MinimalCli.Templates.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PackageId>MinimalCli.Templates</PackageId>
<Title>Minimal Command Line Application Template</Title>
<Authors>dotnetKyle</Authors>
<Description>A working project starting point for a MinimalCli console application.</Description>
<PackageTags>Command; Line; System.CommandLine; Minimal; Source Generator; Minimal CLI; CLI</PackageTags>
<PackageProjectUrl>https://github.com/dotnetKyle/MinimalCommandLine</PackageProjectUrl>
<RepositoryUrl>https://github.com/dotnetKyle/MinimalCommandLine</RepositoryUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>

<!-- see: https://learn.microsoft.com/en-us/dotnet/core/tools/custom-templates#pack-a-template-into-a-nuget-package-nupkg-file -->
<PackageType>Template</PackageType>
<TargetFramework>netstandard2.0</TargetFramework>
<IncludeContentInPack>true</IncludeContentInPack>
<IncludeBuildOutput>false</IncludeBuildOutput>
<ContentTargetFolders>content</ContentTargetFolders>

<NoWarn>$(NoWarn);NU5128</NoWarn>
<NoDefaultExcludes>true</NoDefaultExcludes>
</PropertyGroup>

<PropertyGroup>
<LocalizeTemplates>false</LocalizeTemplates>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.TemplateEngine.Tasks" Version="*" PrivateAssets="all" IsImplicitlyDefined="true"/>
</ItemGroup>

<ItemGroup>
<Content Include="content\**\*" Exclude="content\**\bin\**;content\**\obj\**" />
<Compile Remove="**\*" />
</ItemGroup>

<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions src/MinimalCli.Templates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

# Minimal CLI Project Template

A "dotnet new" project template to create a MinimalCli console app that uses the Minimal CLI source generator

Use `dotnet new install MinimalCli.Templates` to install this template and enable you to run `dotnet new minCli` to create ready to go new Minimal CLI projects.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "http://json.schemastore.org/template",
"author": "dotnetKyle",
"classifications": [ "Common", "Console" ],
"identity": "ExampleTemplate.AsyncProject",
"name": "MinimalCli Console App",
"shortName": "minCli",
"sourceName":"MinimalCliApp",
"tags": {
"language": "C#",
"type": "project"
}
}
15 changes: 15 additions & 0 deletions src/MinimalCli.Templates/content/console/Commands/EchoCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using MinimalCli;

namespace MinimalCliApp.Commands;

internal class EchoCommand
{
// creates a sub-command that can be called by using the 'echo-command' sub-command
[Handler("echo-command")]
public Task ExecuteAsync(string prompt)
{
Console.WriteLine("Echo: {0}", prompt);

return Task.CompletedTask;
}
}
21 changes: 21 additions & 0 deletions src/MinimalCli.Templates/content/console/Commands/GreetCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using MinimalCli;

namespace MinimalCliApp.Commands;

internal class GreetCommand
{
// this attribute creates the main command handler
[RootHandler]
public void Execute(string? yourName = null)
{
if(!string.IsNullOrEmpty(yourName))
{
Console.WriteLine("Hello {0}!", yourName);
return;
}
else
{
Console.WriteLine("Hello World!");
}
}
}
17 changes: 17 additions & 0 deletions src/MinimalCli.Templates/content/console/MinimalCliApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<PackAsTool>true</PackAsTool>
<ToolCommandName>MinimalCliApp</ToolCommandName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MinimalCli" Version="2.0.0.38" />
</ItemGroup>

</Project>
27 changes: 27 additions & 0 deletions src/MinimalCli.Templates/content/console/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// See https://github.com/dotnetKyle/MinimalCommandLine for more information
using MinimalCli;

var builder = new MinimalCommandLineBuilder(args);

// configure the root command's options
builder.MapRootCommand(options => {
options.Command.Description = "A greeter command";

options.YourNameOption.Description = "Your name so the command can greet you.";
});

// modify the echo command's options
builder.MapEchoCommandCommand(options =>
{
options.Command.Description = "A command that echoes a prompt back to the console";

options.PromptArgument.Description = "The prompt to echo back";
options.PromptArgument.DefaultValueFactory = _ => "echo";
});


builder.MapAllCommands();

var app = builder.Build();

await app.StartAsync();
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"profiles": {
"MinimalCliApp": {
"commandName": "Project",
// commandLineArgs will get called on the console application when you use Start (F5)
"commandLineArgs": "-h"
//"commandLineArgs": "echo-command \"foo\""
}
}
}
10 changes: 8 additions & 2 deletions src/MinimalCli.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32804.467
# Visual Studio Version 18
VisualStudioVersion = 18.0.11205.157 d18.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DemoApp", "DemoApp\DemoApp.csproj", "{C10C4313-AF8A-437C-825F-A7733F288DEE}"
EndProject
Expand All @@ -20,6 +20,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MinimalCli.Core", "MinimalC
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MinimalCli.SourceGenerator", "MinimalCli.SourceGenerator\MinimalCli.SourceGenerator.csproj", "{5AF84270-8ECB-4097-A8DA-9C676E1E9373}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MinimalCli.Templates", "MinimalCli.Templates\MinimalCli.Templates.csproj", "{01AD5287-A48C-880F-E2F6-5FD7E4EDA76B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -46,6 +48,10 @@ Global
{5AF84270-8ECB-4097-A8DA-9C676E1E9373}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5AF84270-8ECB-4097-A8DA-9C676E1E9373}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5AF84270-8ECB-4097-A8DA-9C676E1E9373}.Release|Any CPU.Build.0 = Release|Any CPU
{01AD5287-A48C-880F-E2F6-5FD7E4EDA76B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{01AD5287-A48C-880F-E2F6-5FD7E4EDA76B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{01AD5287-A48C-880F-E2F6-5FD7E4EDA76B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{01AD5287-A48C-880F-E2F6-5FD7E4EDA76B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Loading