Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert xwbtool to use GNU-style long options #499

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading