From 6ed68d3e6d7bfd519293e772de794c3b3460773e Mon Sep 17 00:00:00 2001 From: aszlig Date: Tue, 17 Jul 2018 07:33:46 +0200 Subject: monogame-patcher: Work around terminal width issue If the command is not executed inside a terminal the value of Console.WindowWidth is 0 and thus we will get an exception from CommandLineParser: Unhandled Exception: System.ArgumentOutOfRangeException: Length cannot be less than zero. Parameter name: length at System.String.Substring ... at CommandLine.Text.HelpText.AddOption ... ... So let's initialize the parser with settings and if WindowWidth is 0 we just add 80 as the width. Signed-off-by: aszlig --- pkgs/games/build-support/monogame-patcher/src/patcher.cs | 12 +++++++++++- pkgs/games/build-support/monogame-patcher/src/test.sh | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'pkgs/games/build-support') diff --git a/pkgs/games/build-support/monogame-patcher/src/patcher.cs b/pkgs/games/build-support/monogame-patcher/src/patcher.cs index cac60250..b35e44d6 100644 --- a/pkgs/games/build-support/monogame-patcher/src/patcher.cs +++ b/pkgs/games/build-support/monogame-patcher/src/patcher.cs @@ -128,7 +128,17 @@ class ReplaceCall : Command { public class patcher { public static int Main(string[] args) { - Parser.Default.ParseArguments(args) + var parser = new Parser((settings) => { + settings.EnableDashDash = true; + settings.HelpWriter = Console.Error; + + // XXX: When not running in a terminal the width is 0, but the + // CommandLine library expects it to be greater than zero. + if (Console.WindowWidth == 0) + settings.MaximumDisplayWidth = 80; + }); + + parser.ParseArguments(args) .WithParsed(opts => new FixFileStreams(opts)) .WithParsed(opts => new ReplaceCall(opts)); return 0; diff --git a/pkgs/games/build-support/monogame-patcher/src/test.sh b/pkgs/games/build-support/monogame-patcher/src/test.sh index 80260c80..9c51cd7e 100644 --- a/pkgs/games/build-support/monogame-patcher/src/test.sh +++ b/pkgs/games/build-support/monogame-patcher/src/test.sh @@ -76,3 +76,5 @@ test "$(mono test2.exe)" = "can write" "$out/bin/monogame-patcher" fix-filestreams -i b.dll b test "$(mono test2.exe)" = "can not write" + +"$out/bin/monogame-patcher" --help 2>&1 | grep -q fix-filestreams -- cgit 1.4.1