Skip to content

Commit

Permalink
Convert xwbtool to use GNU-style long options (#499)
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn authored Oct 28, 2024
1 parent 6254a38 commit fabe5a1
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 71 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
Loading

0 comments on commit fabe5a1

Please sign in to comment.