Skip to content

Commit

Permalink
Update MakeSpriteFont with --version and --help
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn committed Oct 28, 2024
1 parent d4f8adc commit aea03cd
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions MakeSpriteFont/CommandLineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = { ':' };
Expand Down Expand Up @@ -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)
Expand All @@ -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<T>(ICustomAttributeProvider provider) where T : Attribute
{
Expand Down

0 comments on commit aea03cd

Please sign in to comment.