WithParsedAsync in netcore3.1

CSharp · Console

/Program.cs

// @nuget: CommandLineParser -Version 2.8.0
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using CommandLine;

//Run WithParsedAsync  in v2.8+
public class Program
{
	public static async Task Main()
	{
		var args = "--userid=root -t int:long:string".Split();
		await Parser.Default.ParseArguments<Options>(args)
			 .WithParsedAsync(RunAsync);
		Console.WriteLine($"Exit code= {Environment.ExitCode}");
	}

	//async method
	static async Task RunAsync(Options options)
	{
		Console.WriteLine("Starting async/await method");
		Console.WriteLine("Before async/await");
		await Task.Delay(0); //simulate async method	
		Console.WriteLine($"UserId={options.UserId}");
		await Task.Delay(0); //simulate async method	
		Console.WriteLine("After async/await");
	}
}

class Options
{
	[Option]
	public string UserId
	{
		get;
		set;
	}

	[Option('t', Separator = ':')]
	public IEnumerable<string> Types
	{
		get;
		set;
	}
}
;