Commits

Matt Hamilton committed 939eb4e

More Readme text

Comments (0)

Files changed (1)

 ... or using just enough characters to uniquely identify the arguments:
 
 > myapp.exe /i /h=100
+
+Required Arguments
+------------------
+If an argument is required for your application, give it a `Required` attribute (found in the `System.ComponentModel.DataAnnotations` namespace, like so:
+
+    public class Foo
+    {
+        [Required]
+        public bool IsAwesome { get; set; }
+        public int HowAwesome { get; set; }
+    }
+
+If the user omits the "/isawesome" argument, an ArgumentException will be thrown from the `As<T>` method.
+
+Alternate Names
+---------------
+If you want your `HowAwesome` property to be populated from an argument simply called "/level", you can do so using the `ShortName` property of the `Display` attribute (also found in the `System.ComponentModel.DataAnnotations` namespace), like so:
+
+    public class Foo
+    {
+        [Required]
+        public bool IsAwesome { get; set; }
+
+        [Display(ShortName = "level")]
+        public int HowAwesome { get; set; }
+    }
+
+Argument Descriptions
+---------------------
+If you want to be able to show a helpful description of each argument (see the next section, "Showing Help"), you can do so two ways:
+
+1. Add a `Description` attribute (from the `System.ComponentModel` namespace)
+2. Use the `Description` property of the aforementioned `Display` attribute
+
+Here's an example using both techniques:
+
+    public class Foo
+    {
+        [Required]
+        [Description("Whether the app is awesome")]
+        public bool IsAwesome { get; set; }
+
+        [Display(ShortName = "level", Description="How awesome the app is")]
+        public int HowAwesome { get; set; }
+    }
+
+Showing Help
+------------
+To generate a string that you can display to the user if they get an argument wrong, use the `AppArgs.HelpFor<T>` static method. I like to do something like this:
+
+    try
+    {
+        var foo = args.As<Foo>();
+    }
+    catch (Exception ex)
+    {
+        Console.WriteLine(ex.Message);
+        Console.WriteLine();
+        Console.WriteLine(AppArgs.HelpFor<Foo>());
+    }
+
+If the user omits the required "/isawesome" switch now, we'll see this output:
+
+<pre>
+Argument missing: 'db'
+
+MyApp /isawesome [/level=value]
+
+ /isawesome	Whether the app is awesome
+ /level    	How awesome the app is
+</pre>
+
+As you can see, required arguments are not enclosed in square brackets in the help text, and are listed before optional arguments.