cake-build / cake-build/cake

Assume arguments provided _after_ the .cake script (when provided) to be "remaining arguments"

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

Description

> This is closely related to #3279.

### Background

The Cake runner supports a number of arguments, such `--version` to display the version of the runner, or `--debug` to launch the script in debug mode.

However, this make it impossible for these names to be used as arguments in Cake build scripts. For example, if one wanted to use the argument `version` as an input to the build script:

```cakescript
var version = Argument("version");
```

And then run Cake:

```powershell
dotnet cake --version=1.2.3
```

They would receive an error: `Flags cannot be assigned a value`

### Workaround

The current workaround is to use the "remaining arguments" feature when using one of these "reserved" argument names:

```powershell
dotnet cake -- --version=1.2.3
```

### Proposal

This issue intends to make the necessary updates to - only when a `.cake` file is provided as an argument - to assume that any arguments **after** the `.cake` file to be considered as "remaining arguments" instead of Cake runner arguments.

In other words: Consider that all arguments **before** the `.cake` filename to be arguments targeted at the Cake runner, and all arguments **after** the `.cake` filename to be targeted at the build script:

```
dotnet cake (cake-args) filename.cake (build-args)
```

| Command-line | Expected result |
| --- | --- |
| `dotnet cake --version` | Display Cake version (as it is today) |
| `dotnet cake --version=1.2.3` | Error: `Flags cannot be assigned a value` (unless #3279 is implemented) |
| `dotnet cake build.cake --version=1.2.3` | Run build script and set the `version` argument to `1.2.3` |
| `dotnet cake --version=1.2.3 build.cake` | Error: `Flags cannot be assigned a value` (unless #3279 is implemented) |

This should work for all Cake runner arguments.

![image](https://user-images.githubusercontent.com/177608/111087260-6884e980-84ff-11eb-8554-c7d38af2d5bb.png)

---

Related:
- [Improve error message for reserved argument names](https://github.com/cake-build/cake/issues/2794)
- [Allow users to use any of the Cake runner arguments as build script arguments](https://github.com/cake-build/cake/issues/3279)

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.