Allow empty arguments when using double dashed args
See original GitHub issueBackground
A pattern that we’ve seen is to have use environment variables as values for Cake script arguments. e.g.
dotnet cake --argName=%ARG_NAME_VALUE%
If the %ARG_NAME_VALUE%
environment value exists and has a value, everything works as expected.
However, if the environment variable does not exist, or its value is empty, the user receives an error from the Cake runner: Expected an option value
.
The current workaround is to use
(space) instead of =
if the value can be empty/null. e.g.
dotnet cake --argName %ARG_NAME_VALUE%
Proposal
This issue intends to make the necessary updates to allow empty arguments when using the --argName=
syntax, which translates to the argument value being null
for the build script.
NB: Heads-up that we use Spectre.Console for parsing arguments, so there’s a little bit of investigation needed to see if the fix can (and should) be done directly in Cake, of if it should be fixed upstream. If you discover that the fix doesn’t belong in Cake, you’d need to send a PR to Spectre.Console and the fix in Cake would be just upgrading to a newer version of Spectre.Console.
Related:
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
Opened the issue in Spectre.Console repo https://github.com/spectreconsole/spectre.console/issues/594
Update:
I’ve worked on this, and debugged the issue. Issue is coming from Spectre.Console.Cli in ScanOptions method of CommandTreeTokenizer class. Below is the code throwing the exception, this is coming as the value of environment variable is empty or null, so the if condition i.e. if (!reader.TryPeek(out _)) is being satisfied and exception is thrown.
I will be working on this further and raising a PR against Spectre.Console repository.