Created
July 10, 2023 14:01
-
-
Save kevingosse/eaf05c7c15c2add62205cb956a4fcac6 to your computer and use it in GitHub Desktop.
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
<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> |
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
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