Command-line-api: How to bind to nullable value type parameters

Created on 23 Feb 2019  路  3Comments  路  Source: dotnet/command-line-api

I'm enjoying using this library, despite it still being in the experimental stages, but I'm not sure how to deal with the latest changes.

Specifically, when bumping System.CommandLine.Experimental from 63807-01 to 63822-01, it no longer binds a nullable int parameter and it always gets passed as 0, even though I specify it should default to a value. See the full source at BoardGameGeek.Dungeon/Application/CommandLine.cs.

If I change the year option to:
c# var yearOption = new Option(new[] { "-y", "--year" }, "Year to analyze.", new Argument<int?>());
I'd expect it to bind to null if not specified on the command-line, or the value if specified, but it still always gets passed as 0 in both cases, so the binding no longer works at all.

It does work again if I replace int? everywhere with int; but this used to work, albeit with no guarantees of stability, and it seems reasonable to want to bind to a nullable value type.

bug

All 3 comments

Thanks. This is a bug introduced by the latest binding refactor (which added support for binding to complex types, e.g. `CommandHandler.Create). I'm working on a fix for it.

This should be fixed now with #419.

Wow, confirmed as fixed! Thanks a lot, @jonsequitur!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mariopasquali picture mariopasquali  路  4Comments

KathleenDollard picture KathleenDollard  路  4Comments

jonsequitur picture jonsequitur  路  6Comments

SirJosh3917 picture SirJosh3917  路  3Comments

clmcgrath picture clmcgrath  路  3Comments