Move `--version` handling up so there's no window and no other prints

This commit is contained in:
YoshiRulz 2025-05-29 14:46:04 +10:00
parent 4a3631ef3e
commit 8c9e49cd1d
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
3 changed files with 10 additions and 17 deletions

View File

@ -7,6 +7,7 @@ using System.CommandLine.Parsing;
using System.Linq;
using System.Net.Sockets;
using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
using BizHawk.Common.StringExtensions;
@ -147,13 +148,13 @@ namespace BizHawk.Client.Common
public static int? ParseArguments(out ParsedCLIFlags parsed, string[] args)
{
parsed = default;
if (args.Length is not 0) Console.WriteLine($"parsing command-line flags: {string.Join(" ", args)}");
if (args.Length is not 0) Console.Error.WriteLine($"parsing command-line flags: {string.Join(" ", args)}");
var result = Parser.Parse(args);
if (result.Errors.Count is not 0)
{
// write all to stdout and show first in modal dialog (done in `catch` block in `Program`)
Console.WriteLine("failed to parse command-line arguments:");
foreach (var error in result.Errors) Console.WriteLine(error.Message);
Console.Error.WriteLine("failed to parse command-line arguments:");
foreach (var error in result.Errors) Console.Error.WriteLine(error.Message);
throw new ArgParserException($"failed to parse command-line arguments: {result.Errors[0].Message}");
}
var triggeredGeneratedOption = GeneratedOptions.FirstOrDefault(o => result.FindResultFor(o) is not null);
@ -168,6 +169,12 @@ namespace BizHawk.Client.Common
return exitCode;
}
}
if (result.GetValueForOption(OptionQueryAppVersion))
{
// means e.g. `./EmuHawkMono.sh --version` was passed, so print that and exit immediately
Console.WriteLine(VersionInfo.GetEmuVersion());
return 0;
}
var autoDumpLength = result.GetValueForOption(OptionAVDumpEndAtFrame);
HashSet<int>? currAviWriterFrameList = null;
@ -218,7 +225,6 @@ namespace BizHawk.Client.Common
cmdDumpType: result.GetValueForOption(OptionAVDumpType),
currAviWriterFrameList: currAviWriterFrameList,
autoDumpLength: autoDumpLength ?? 0,
printVersion: result.GetValueForOption(OptionQueryAppVersion),
cmdDumpName: result.GetValueForOption(OptionAVDumpName),
autoCloseOnDump: result.GetValueForOption(OptionAVDumpQuitWhenDone),
chromeless: result.GetValueForOption(OptionLaunchChromeless),

View File

@ -21,8 +21,6 @@ namespace BizHawk.Client.Common
public readonly int _autoDumpLength;
public readonly bool printVersion;
public readonly string? cmdDumpName;
public readonly bool _autoCloseOnDump;
@ -61,7 +59,6 @@ namespace BizHawk.Client.Common
string? cmdDumpType,
HashSet<int>? currAviWriterFrameList,
int autoDumpLength,
bool printVersion,
string? cmdDumpName,
bool autoCloseOnDump,
bool chromeless,
@ -85,7 +82,6 @@ namespace BizHawk.Client.Common
this.cmdDumpType = cmdDumpType;
_currAviWriterFrameList = currAviWriterFrameList;
_autoDumpLength = autoDumpLength;
this.printVersion = printVersion;
this.cmdDumpName = cmdDumpName;
_autoCloseOnDump = autoCloseOnDump;
_chromeless = chromeless;

View File

@ -896,15 +896,6 @@ namespace BizHawk.Client.EmuHawk
ToggleFullscreen();
}
// Simply exit the program if the version is asked for
if (_argParser.printVersion)
{
// Print the version
Console.WriteLine(VersionInfo.GetEmuVersion());
// Return and leave
return _exitCode;
}
CaptureMouse(Config.CaptureMouse);
// incantation required to get the program reliably on top of the console window