cake-build / cake-build/cake

Allow empty arguments when using double dashed args

Open
#3,277 6 comments 0 reactions 1 assignee Claimed by @Nisha2015 View on GitHub
blocked-upstream Improvement
Dominant language
C#
Stars
4.2k
Forks
778
Avg merge
1h 15m
Merged PRs (30d)
19

Description

### Background

A pattern that we've seen is to have use environment variables as values for Cake script arguments. e.g.

```powershell
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.

```powershell
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](https://github.com/spectreconsole/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](https://github.com/spectreconsole/spectre.console). 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](https://github.com/spectreconsole/spectre.console).

---

Related:
- [How do you pass empty arguments in Cake v1?](https://stackoverflow.com/questions/66121207/how-do-you-pass-empty-arguments-in-cake-v1/66125812#66125812)
- [I can no longer pass empty string as argument values](https://github.com/cake-build/cake/discussions/3198)
- [Passing empty arguments](https://cakebuild.net/docs/getting-started/upgrade#passing-empty-arguments)

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.