Skip to content

Commit

Permalink
Add a simple CLI application
Browse files Browse the repository at this point in the history
Add a starter CLI application that prints out
its name, version and description.
  • Loading branch information
mehmetseckin committed Oct 9, 2019
1 parent a8b1129 commit be1a3af
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Microsoft.Todo.CLI.sln
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
25 changes: 25 additions & 0 deletions src/Microsoft.Todo.CLI/Microsoft.Todo.CLI.csproj
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>
45 changes: 45 additions & 0 deletions src/Microsoft.Todo.CLI/Program.cs
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}");
}
}
}

0 comments on commit be1a3af

Please sign in to comment.