-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a starter CLI application that prints out its name, version and description.
- Loading branch information
1 parent
a8b1129
commit be1a3af
Showing
3 changed files
with
95 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.29326.143 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Todo.CLI", "Microsoft.Todo.CLI\Microsoft.Todo.CLI.csproj", "{DAE1B155-3197-4C6A-A447-E042DE7185F3}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{DAE1B155-3197-4C6A-A447-E042DE7185F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{DAE1B155-3197-4C6A-A447-E042DE7185F3}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{DAE1B155-3197-4C6A-A447-E042DE7185F3}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{DAE1B155-3197-4C6A-A447-E042DE7185F3}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {3A20161D-AB81-43A6-AD3C-7828D9859E7B} | ||
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,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.0</TargetFramework> | ||
<PackageId>todo</PackageId> | ||
<Authors>mehmetseckin</Authors> | ||
<Product>todo</Product> | ||
<Description>A CLI to manage to do items</Description> | ||
<RepositoryUrl>https://github.com/mehmetseckin/todo-cli/</RepositoryUrl> | ||
<RepositoryType>Git</RepositoryType> | ||
<PackageTags>todo</PackageTags> | ||
<AssemblyVersion>0.0.0.0</AssemblyVersion> | ||
<FileVersion>0.0.0.0</FileVersion> | ||
<Version>0.0.0</Version> | ||
<AssemblyName>todo</AssemblyName> | ||
<NoWin32Manifest>true</NoWin32Manifest> | ||
<StartupObject>Microsoft.Todo.CLI.Program</StartupObject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="System.CommandLine.Experimental" Version="0.3.0-alpha.19405.1" /> | ||
</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,45 @@ | ||
using System; | ||
using System.CommandLine; | ||
using System.CommandLine.Invocation; | ||
using System.IO; | ||
using System.Reflection; | ||
|
||
namespace Microsoft.Todo.CLI | ||
{ | ||
class Program | ||
{ | ||
static int Main(string[] args) | ||
{ | ||
// Define the root command | ||
var rootCommand = new RootCommand | ||
{ | ||
new Option(new string[] { "-v", "--version" } , "Prints out the todo CLI version.") | ||
{ | ||
Argument = new Argument<bool>() | ||
} | ||
}; | ||
|
||
rootCommand.Description = "A CLI to manage to do items."; | ||
|
||
// Define handler | ||
rootCommand.Handler = CommandHandler.Create<bool>((version) => | ||
{ | ||
if (version) | ||
{ | ||
PrintVersion(); | ||
return; | ||
} | ||
}); | ||
|
||
return rootCommand.InvokeAsync(args).Result; | ||
} | ||
|
||
private static void PrintVersion() | ||
{ | ||
var entryAssembly = Assembly.GetEntryAssembly(); | ||
var entryAssemblyName = entryAssembly.GetName(); | ||
var description = entryAssembly.GetCustomAttribute<AssemblyDescriptionAttribute>()?.Description; | ||
Console.WriteLine($"{entryAssemblyName.Name} {entryAssemblyName.Version} - {description}"); | ||
} | ||
} | ||
} |