Skip to content

Commit fabe5a1

Browse files
authored
Convert xwbtool to use GNU-style long options (#499)
1 parent 6254a38 commit fabe5a1

File tree

2 files changed

+157
-71
lines changed

2 files changed

+157
-71
lines changed

MakeSpriteFont/CommandLineParser.cs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,25 @@ public bool ParseCommandLine(string[] args)
8989

9090
bool ParseArgument(string arg)
9191
{
92-
if (arg.StartsWith("/"))
92+
if (arg.StartsWith("--"))
93+
{
94+
string name = arg.Substring(2).ToLowerInvariant();
95+
96+
if (name == "version")
97+
{
98+
ShowVersion();
99+
}
100+
else if (name == "help")
101+
{
102+
ShowUsage();
103+
}
104+
else
105+
{
106+
ShowError("Unknown long option '{0}'", name);
107+
}
108+
return false;
109+
}
110+
else if (arg.StartsWith("/") || arg.StartsWith("-"))
93111
{
94112
// Parse an optional argument.
95113
char[] separators = { ':' };
@@ -202,10 +220,16 @@ static string GetOptionName(FieldInfo field)
202220

203221
void ShowError(string message, params object[] args)
204222
{
205-
string name = Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().ProcessName);
206-
207223
Console.Error.WriteLine(message, args);
208224
Console.Error.WriteLine();
225+
ShowUsage();
226+
}
227+
228+
229+
void ShowUsage()
230+
{
231+
string name = Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().ProcessName);
232+
209233
Console.Error.WriteLine("Usage: {0} {1}", name, string.Join(" ", requiredUsageHelp));
210234

211235
if (optionalUsageHelp.Count > 0)
@@ -220,6 +244,15 @@ void ShowError(string message, params object[] args)
220244
}
221245
}
222246

247+
void ShowVersion()
248+
{
249+
string name = Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().ProcessName);
250+
251+
Version version = Assembly.GetEntryAssembly().GetName().Version;
252+
253+
Console.Error.WriteLine("{0} Version {1}", name, version);
254+
}
255+
223256

224257
static T GetAttribute<T>(ICustomAttributeProvider provider) where T : Attribute
225258
{

0 commit comments

Comments
 (0)