Parsing - strong typed

This example demonstrates how to parse the arguments getting a strong typed class as result.
Settings settings = CommandLineParser.Parse<Settings>(args);
The command line arguments will be passed to the matching properties. See Syntax.
Isn't that easy, just a line of code.

This may be your settings object:
public class Settings
{
        #region properties
        public bool Install { get; private set; }
        public bool Uninstall { get; private set; }
        [ShortOptionName("s")]
        public bool StartAfterInstall { get; private set; }
        [ShortOptionName("n"), OptionName("name"), DefaultValue("MongrelService")]
        public string ServiceName { get; private set; }
        [ShortOptionName("u"), Description("The user name starting the service")]
        public string UserName { get; private set; }
        [ShortOptionName("p")]
        public string Password { get; private set; }
        [DefaultValue("Mongrel Service")]
        public string DisplayName { get; private set; }
        [DefaultValue("Service to handle mongrel rails")]
        public string Description { get; private set; }
        #endregion
}
See the Attributes for more details.

Printing the help

This example demonstrates how to print the available options to console. Also known as the help.
Console.Write(CommandLineParser.GetInfo<Settings>());

Last edited Jul 26, 2009 at 12:58 PM by twenzel, version 6

Comments

No comments yet.