dotnet / dotnet/command-line-api

Argument not passed to command handler?

Open
#1,228 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

So I have a .net core 3.1 console app, package version 2.0.0-beta1.20574.7 and this code:

```
using System;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.Threading.Tasks;

namespace CommandParseTest
{
class Program
{
private static async Task Main(string[] args)
{
Console.WriteLine(Environment.CommandLine);
var realMain = new RootCommand("my program")
{
new Option(
"--x",
"Pass a number"
)
};

realMain.Handler = CommandHandler.Create(Run);
await realMain.InvokeAsync(args);
}

private static async Task Run(int foundItemFileToRead)
{
Console.WriteLine(foundItemFileToRead);
}
}
}
```

Now, if I call this like `CommandParseTest.exe --x 3`, I get 0.
Am I doing something wrong?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.