From be1a3af6ae993e81015ef60c8c3f915e26733825 Mon Sep 17 00:00:00 2001 From: Mehmet Seckin <1876867+mehmetseckin@users.noreply.github.com> Date: Wed, 9 Oct 2019 23:30:13 +0000 Subject: [PATCH] Add a simple CLI application Add a starter CLI application that prints out its name, version and description. --- src/Microsoft.Todo.CLI.sln | 25 +++++++++++ .../Microsoft.Todo.CLI.csproj | 25 +++++++++++ src/Microsoft.Todo.CLI/Program.cs | 45 +++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 src/Microsoft.Todo.CLI.sln create mode 100644 src/Microsoft.Todo.CLI/Microsoft.Todo.CLI.csproj create mode 100644 src/Microsoft.Todo.CLI/Program.cs diff --git a/src/Microsoft.Todo.CLI.sln b/src/Microsoft.Todo.CLI.sln new file mode 100644 index 0000000..a6f4d19 --- /dev/null +++ b/src/Microsoft.Todo.CLI.sln @@ -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 diff --git a/src/Microsoft.Todo.CLI/Microsoft.Todo.CLI.csproj b/src/Microsoft.Todo.CLI/Microsoft.Todo.CLI.csproj new file mode 100644 index 0000000..1dbbb4f --- /dev/null +++ b/src/Microsoft.Todo.CLI/Microsoft.Todo.CLI.csproj @@ -0,0 +1,25 @@ + + + + Exe + netcoreapp3.0 + todo + mehmetseckin + todo + A CLI to manage to do items + https://github.com/mehmetseckin/todo-cli/ + Git + todo + 0.0.0.0 + 0.0.0.0 + 0.0.0 + todo + true + Microsoft.Todo.CLI.Program + + + + + + + diff --git a/src/Microsoft.Todo.CLI/Program.cs b/src/Microsoft.Todo.CLI/Program.cs new file mode 100644 index 0000000..f298c2a --- /dev/null +++ b/src/Microsoft.Todo.CLI/Program.cs @@ -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() + } + }; + + rootCommand.Description = "A CLI to manage to do items."; + + // Define handler + rootCommand.Handler = CommandHandler.Create((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()?.Description; + Console.WriteLine($"{entryAssemblyName.Name} {entryAssemblyName.Version} - {description}"); + } + } +}