command-line-api icon indicating copy to clipboard operation
command-line-api copied to clipboard

HasOption alternative When migrating to 2.0 beta5

Open WeihanLi opened this issue 6 months ago • 8 comments

When migrating to 2.0 beta 5, the ParseResult.HasOption is not there any more, and seems not mentioned in the migration guide, is there alternative for it?

I use it to see whether the user has that option input

https://learn.microsoft.com/en-us/dotnet/standard/commandline/migration-guide-2.0.0-beta5

WeihanLi avatar Jun 25 '25 00:06 WeihanLi

Without knowing more about the specific usage, I would generally say use ParseResult.GetValue.

Does this work or is there a reason to have a separate check for HasOption?

jonsequitur avatar Jun 25 '25 15:06 jonsequitur

In the dotnet SDK we have our own HasOption - we mostly use it to add the extra "is not implicit" check so we can tell when something was explicitly set by the user.

baronfel avatar Jun 25 '25 15:06 baronfel

I don't remember if that's what HasOption did before, e.g. did it return true when the default value was used?

I was looking for the ability to differentiate these yesterday though. In the current API you can check ParseResult.GetResult(option).Implicit.

jonsequitur avatar Jun 25 '25 15:06 jonsequitur

Thanks very much @baronfel @jonsequitur , should I close this one now since it's resolved, or keep it open for document?

WeihanLi avatar Jun 25 '25 16:06 WeihanLi

Let's keep this open until we make a decision on the documentation bug.

jonsequitur avatar Jun 25 '25 17:06 jonsequitur

We would want one or two new APIs for this where we clearly answer, "did the user specify this option?" and, "is there a value for this option?"

jeffhandley avatar Sep 16 '25 16:09 jeffhandley

For 2.0.0, we should augment the API docs to have better clarity around those 2 questions. Then we will explore new APIs in 3.0.0.

jeffhandley avatar Sep 16 '25 16:09 jeffhandley

Assigning to @adamsitnik for the docs portion.

jeffhandley avatar Sep 18 '25 17:09 jeffhandley