From aea03cdee667f2e7468a752849aaba09d7fc5f37 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Mon, 28 Oct 2024 13:49:04 -0700 Subject: [PATCH] Update MakeSpriteFont with --version and --help --- MakeSpriteFont/CommandLineParser.cs | 39 ++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/MakeSpriteFont/CommandLineParser.cs b/MakeSpriteFont/CommandLineParser.cs index 88dda19f1..f4c40a81c 100644 --- a/MakeSpriteFont/CommandLineParser.cs +++ b/MakeSpriteFont/CommandLineParser.cs @@ -89,7 +89,25 @@ public bool ParseCommandLine(string[] args) bool ParseArgument(string arg) { - if (arg.StartsWith("/")) + if (arg.StartsWith("--")) + { + string name = arg.Substring(2).ToLowerInvariant(); + + if (name == "version") + { + ShowVersion(); + } + else if (name == "help") + { + ShowUsage(); + } + else + { + ShowError("Unknown long option '{0}'", name); + } + return false; + } + else if (arg.StartsWith("/") || arg.StartsWith("-")) { // Parse an optional argument. char[] separators = { ':' }; @@ -202,10 +220,16 @@ static string GetOptionName(FieldInfo field) void ShowError(string message, params object[] args) { - string name = Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().ProcessName); - Console.Error.WriteLine(message, args); Console.Error.WriteLine(); + ShowUsage(); + } + + + void ShowUsage() + { + string name = Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().ProcessName); + Console.Error.WriteLine("Usage: {0} {1}", name, string.Join(" ", requiredUsageHelp)); if (optionalUsageHelp.Count > 0) @@ -220,6 +244,15 @@ void ShowError(string message, params object[] args) } } + void ShowVersion() + { + string name = Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().ProcessName); + + Version version = Assembly.GetEntryAssembly().GetName().Version; + + Console.Error.WriteLine("{0} Version {1}", name, version); + } + static T GetAttribute(ICustomAttributeProvider provider) where T : Attribute {