Unparsing skips arguments with values equal to the argument type's default value
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 45/100
Rechercherichtung
Reproduziere das Problem mit der bereitgestellten Program- und TestArgs-App und konzentriere dich dabei auf Parser.FormatCommandLine mit settings.SkipDefault = true. Vergleiche die Ausgabe für die Werte 0, 1 und 2 mit den erwarteten Befehlszeilen und überprüfe anschließend, dass jedes Ergebnis beim Round-Trip wieder in die ursprünglichen Werte geparst wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- C#
- Sterne
- 4.8k
- Forks
- 478
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus commandlineparser/commandline
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
commandlineparser/commandline#951 · 1 Kommentar ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 70/100
commandlineparser/commandline#880 · 2 Reaktionen ·
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 45/100
commandlineparser/commandline#952 ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 35/100
commandlineparser/commandline#948 ·
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
commandlineparser/commandline#947 ·
Alle Issues in commandlineparser/commandline
Ähnliche Issues
-
effort:S P3 refactor
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
nightscout/nocturne#1532 ·
-
core dependencies
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 80/100
-
documentation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
-
C#/.NET Roslyn LSP Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
DotNetNext/SqlSugar#1458 ·