Unparsing skips arguments with values equal to the argument type's default value
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
Riproduci il problema con l’app Program e TestArgs fornita, concentrandoti su Parser.FormatCommandLine con settings.SkipDefault = true. Confronta il relativo output per i valori 0, 1 e 2 con le righe di comando previste, quindi verifica che ogni risultato venga analizzato nuovamente tramite round-trip nei valori originali.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Using CommandLineParser 2.9.1, the unparsing behaviour with SkipDefault = true seems to be incorrect. Here is a test app to reproduce the behaviour.
using CommandLine;
namespace UnparsingTest
{
public class Program
{
public class TestArgs
{
[Option('c', Required = true)]
public int CompulsoryWithoutDefault { get; set; }
[Option('d', Required = true, Default = 1)]
public int CompulsoryWithDefault { get; set; } = 1;
[Option('o', Required = false, Default = 1)]
public int Optional { get; set; } = 1;
}
static void Main()
{
Parser parser = new Parser();
for (int i = 0; i <= 2; ++i)
{
TestArgs args = new TestArgs()
{
CompulsoryWithoutDefault = i,
CompulsoryWithDefault = i,
Optional = i,
};
string commandLine = parser.FormatCommandLine(args, settings => settings.SkipDefault = true);
System.Console.WriteLine($"CompulsoryWithDefault: {args.CompulsoryWithDefault}, CompulsoryWithoutDefault: {args.CompulsoryWithoutDefault}, Optional: {args.Optional}, Command line: \"{commandLine}\"");
}
}
}
}
There are 2 compulsory arguments, one with a Default value and one without a Default value. CompulsoryWithDefault and Optional have their Default values set to any value that is not default(int).
The test app's console output shows the unparsed command line for the 3 sets of arguments
CompulsoryWithDefault: 0, CompulsoryWithoutDefault: 0, Optional: 0, Command line: ""
CompulsoryWithDefault: 1, CompulsoryWithoutDefault: 1, Optional: 1, Command line: "-c 1"
CompulsoryWithDefault: 2, CompulsoryWithoutDefault: 2, Optional: 2, Command line: "-c 2 -d 2 -o 2"
The unparsed command line for the first case will fail round trip parsing because the compulsory -c and -d arguments are missing and -o is missing so Optional will have a value of 1 instead of 0. The unparsed command line for the second case will also fail round trip parsing because the compulsory -d argument is missing. Only the third case is giving correct output.
The bug appears to be that the unparser is skipping Required = true arguments, arguments with value equal to Default = {value} and arguments with value equal to default(typeof(argument)).
The correct behaviour would be to only skip arguments that do not have Required = true and whose value equals the value specified in Default = {value}.
The expected console output would be
CompulsoryWithDefault: 0, CompulsoryWithoutDefault: 0, Optional: 0, Command line: "-c 0 -d 0 -o 0"
CompulsoryWithDefault: 1, CompulsoryWithoutDefault: 1, Optional: 1, Command line: "-c 1 -d 1"
CompulsoryWithDefault: 2, CompulsoryWithoutDefault: 2, Optional: 2, Command line: "-c 2 -d 2 -o 2"
These command lines would then correctly round trip parse/unparse.
- Lingua principale
- C#
- Stelle
- 4.8k
- Fork
- 478
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di commandlineparser/commandline
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
commandlineparser/commandline#951 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 70/100
commandlineparser/commandline#880 · 2 reazioni ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 45/100
commandlineparser/commandline#952 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
commandlineparser/commandline#948 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
commandlineparser/commandline#947 ·
Tutte le issue di commandlineparser/commandline
Issue simili
-
CS0162 "Unreachable code detected" warning from a MSBuildTemp .tmp file in every game project Apertabug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
Type: enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
apache/arrow-adbc#4809 ·
-
type/automation type/tech-debt
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
microsoft/vscode-azurefunctions#5197 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
microsoft/microsoft-ui-reactor#1274 ·