dotnet / dotnet/command-line-api

FromAmong should consider custom parsing

Aperta
#1,503 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Area-Parser and Binder bug
Lingua principale
C#
Stelle
3.7k
Fork
428
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

2.0.0-beta1.21601.2 breaks the following use case:
Given option:
```
internal static Option> CreateColumnsOption()
{
Option> option = new(new[] { "--columns" }, ParseCommaSeparatedValues)
{
Arity = new ArgumentArity(1, 4),
Description = LocalizableStrings.OptionDescriptionColumns,
AllowMultipleArgumentsPerToken = true,
};
option.FromAmong(
TabularOutputSettings.ColumnNames.Author,
TabularOutputSettings.ColumnNames.Language,
TabularOutputSettings.ColumnNames.Type,
TabularOutputSettings.ColumnNames.Tags);
return option;
}

internal static IReadOnlyList ParseCommaSeparatedValues(ArgumentResult result)
{
List values = new List();
foreach (var value in result.Tokens.Select(t => t.Value))
{
values.AddRange(value.Split(",", StringSplitOptions.TrimEntries).Where(s => !string.IsNullOrWhiteSpace(s)));
}
return values;
}
```
the following use cases fail:
`new list --columns author, type --columns tag`
`new list --columns author,type`

Error is:

```
System.InvalidOperationException : Argument 'author,type' not recognized. Must be one of:
'author'
'language'
'type'
'tags'

Stack Trace: 
ArgumentConverter.GetValueOrDefault[T](ArgumentConversionResult result)
OptionResult.GetValueOrDefault[T]()
ParseResult.GetValueForOption[T](Option`1 option)
GlobalArgs.ParseTabularOutputSettings(ITabularOutputCommand command, ParseResult parseResult) line 42
ListCommandArgs.ctor(BaseListCommand command, ParseResult parseResult) line 128
ListTests.List_CanParseColumns(String command, String[] expectedColumns) line 222
```

This scenario worked in 2.0.0-beta1.21561.1

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Reproduce the failing ListTests.List_CanParseColumns cases for comma-separated values, then trace ArgumentConverter.GetValueOrDefault and the option's FromAmong validation. Done means both `new list --columns author,type` and `new list --columns author, type --columns tag` parse successfully with the expected columns.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp
Ambito
cli
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.