Skip to content

Instantly share code, notes, and snippets.

@kevingosse
Created July 10, 2023 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevingosse/eaf05c7c15c2add62205cb956a4fcac6 to your computer and use it in GitHub Desktop.
Save kevingosse/eaf05c7c15c2add62205cb956a4fcac6 to your computer and use it in GitHub Desktop.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
<IlcDisableReflection>true</IlcDisableReflection>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>
</Project>
using System.CommandLine;
namespace NativeCommandLine
{
internal class Program
{
static async Task Main(string[] args)
{
var fileOption = new Option<FileInfo?>(
name: "--file",
description: "The file to read and display on the console.");
var rootCommand = new RootCommand("Sample app for System.CommandLine");
rootCommand.AddOption(fileOption);
rootCommand.SetHandler((file) =>
{
Console.WriteLine("Reading " + file!);
},
fileOption);
await rootCommand.InvokeAsync(args);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment