Skip to content

Commit 652d11f

Browse files
committed
update readme for release
1 parent fa73063 commit 652d11f

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,47 @@ static void Main(string[] args)
4747

4848
`.WithDescription("Execute operation in silent mode without feedback")` Specify a help description for the option
4949

50+
### Parsing Using Fluent Command Line Builder
51+
52+
Instead of assigning parsed values to variables you can use the Fluent Command Line Builder to automatically create a defined object type and setup individual Options for each strongly-typed property. Because the builder is simply a wrapper around the parser you can still use the Fluent Command Line Parser Api to define the behaviour for each Option.
53+
54+
The Fluent Command Line Builder can build a type and populate the properties with parsed values such as in the following example:
55+
```
56+
public class ApplicationArguments
57+
{
58+
public int RecordId { get; set; }
59+
public bool Silent { get; set; }
60+
public string NewValue { get; set; }
61+
}
62+
63+
static void Main(string[] args)
64+
{
65+
// create a builder for the ApplicationArguments type
66+
var b = new FluentCommandLineBuilder<ApplicationArguments>();
67+
68+
// specify which property the value will be assigned too.
69+
b.Setup(arg => arg.RecordId)
70+
.As('r', "record") // define the short and long option name
71+
.Required(); // using the standard fluent Api to declare this Option as required.
72+
73+
b.Setup(arg => arg.NewValue)
74+
.As('v', "value")
75+
.Required();
76+
77+
b.Setup(arg => arg.Silent)
78+
.As('s', "silent")
79+
.SetDefault(false); // use the standard fluent Api to define a default value if non is specified in the arguments
80+
81+
var result = b.Parse(args);
82+
83+
if(result.HasErrors == false)
84+
{
85+
// use the instantiated ApplicationArguments object from the Object property on the builder.
86+
application.Run(b.Object);
87+
}
88+
}
89+
```
90+
5091
### Parsing To Collections
5192

5293
Many arguments can be collected as part of a list. Types supported are `string`, `int`, `double` and `bool`

0 commit comments

Comments
 (0)