We've all written a few console apps in our time, but how often do we spend anytime creating a help command line switch that spits out how to use the app? Hopefully you answered, "everytime." There's nothing more annoying than a console app that doesn't display a man page if you forget to supply required parameters.
It's so easy to add syntax help, especially if you drop the Console.WriteLines in favor of an embedded text file resource. This way you can edit your command line usage as plain text which is so much easier to write and maintain. This may seem obvious, but often time we forget because, "it's just a quickie console app." So the next time your find yourself writing a console utility, remember to use an embedded text resource as your help (or man) page.
Other than actually creating the text file and marking it as an embedded resource, this all the code required (don't forget to prefix your text file with the default assembly namespace):
private static void Usage()
{
using (
Stream s =
Assembly.GetExecutingAssembly().GetManifestResourceStream(
"Sneal.Build.ConfigPoke.Console.usage.txt"))
using (StreamReader reader = new StreamReader(s))
System.Console.WriteLine(reader.ReadToEnd());
}
Remember Me
a@href@title, strike
Powered by: newtelligence dasBlog 2.1.8102.813
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2010, Shawn Neal
E-mail