Cysharp / Cysharp/ConsoleAppFramework
Aliasing an option as itself causes a compile error
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2.2k
- Forks
- 127
- PR merge metrics
- No merged PRs in 30d
Description
I recently got into the habit of adding aliases to all of my commands, even if it did not change the default parameter name. I suppose it made my XML documentation look more like the help menu and made all of the parameters consistent. But I noticed if you add an alias that is the same as the name the generator automatically creates, you get a compile error.
For example, if you build this code:
using ConsoleAppFramework;
var app = ConsoleApp.Create();
app.Add<MyCommand>();
app.Run(args);
class MyCommand
{
/// <param name="target">--target, The path to the file that is to be updated.</param>
[Command("update-file")]
public async Task Command(string target) { }
}
You will get this error:
ConsoleApp.Builder.g.cs(85,25): Error CS0152 : The switch statement contains multiple cases with the label value '"--target"'
And the generator will have made this code:
for (int i = 0; i < commandArgs.Length; i++)
{
var name = commandArgs[i];
switch (name)
{
case "--target":
case "--target": // Error CS0152
{
if (!TryIncrementIndex(ref i, commandArgs.Length)) { ThrowArgumentParseFailed("target", commandArgs[i]); } else { arg0 = commandArgs[i]; }
arg0Parsed = true;
continue;
}
It looks like the generator doesn't avoid adding an alias to the parsed command info if the alias matches the default name:
I would like to ask whether this is actually considered a bug, since I know the way I am using aliases is strange.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/ConsoleAppFramework/Parser.cs around lines 865-870 and reproduce the issue with the C# example from the report. Check the generated ConsoleApp.Builder.g.cs switch for duplicate "--target" cases; done means the aliasing example compiles without duplicate case labels.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100