Closed
Description
I want to use enum
with getDefaultValue
. However, it does not work as expected.
My understanding is that AppFunc
should output Fatal
.
$ dotnet run
Verbose
Also the parsing does not seem to work at all:
$ dotnet run -- -v Fatal
Verbose
See the following code:
using System;
using System.CommandLine;
using System.CommandLine.Invocation;
namespace daemon_limitcalc
{
public static class Program
{
public enum LogEventLevel
{
Verbose = 0,
Debug = 1,
Information = 2,
Warning = 3,
Error = 4,
Fatal = 5
}
public static int AppFunc(LogEventLevel loglevel)
{
Console.WriteLine(loglevel);
return 0;
}
public static int Main(string[] args)
{
// Create a root command with some options
var rootCommand = new RootCommand
{
new Option(new[] {"-v", "--verbose" })
{
IsRequired = false,
Argument = new Argument<LogEventLevel>(
getDefaultValue: () => LogEventLevel.Fatal
)
},
};
rootCommand.Description = "Demo program";
// Note that the parameters of the handler method are matched according to the names of the options
rootCommand.Handler = CommandHandler.Create<LogEventLevel>(AppFunc);
return rootCommand.InvokeAsync(args).Result;
}
}
}
Metadata
Metadata
Assignees
Labels
No labels