Skip to content

Commit 747e264

Browse files
authored
Update How-To.md
1 parent e6c9aff commit 747e264

File tree

1 file changed

+3
-26
lines changed

1 file changed

+3
-26
lines changed

docs/How-To.md

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,9 @@ public static void DoSomething(int anInt, string aString)
9191
}
9292
```
9393

94-
This is known as binding. You can learn more about it in the interactive tutorial described in the readme: [https://github.com/dotnet/command-line-api#interactive-tutorials](https://github.com/dotnet/command-line-api#interactive-tutorials)
94+
The process of creating these values based on command line input is known as model binding.
9595

96-
There are currently two models for configuring the `System.CommandLine` parser to bind these parameters.
97-
98-
### Syntax-first
99-
100-
One approach that you can use is to configure the parser directly by adding `Option`s to your `RootCommand`. **Note that the option names should match the names of the parameters of the `DoSomething` method.**
101-
102-
Parameters are matched using a naming convention that converts camel-cased parameters to kebab-cased options. In this example, the option `--an-int` matches parameter `anInt` on the `DoSomething` method.
96+
The most common way that `System.CommandLine` performs model binding is to match option or argument names or aliases to the parameter names on a handler, or to the property names of complex objects passed to a handler. Parameters or properties are matched using a convention that matches camel-cased parameter names to kebab-cased option names. In this example, the option `--an-int` matches parameter `anInt` on the `DoSomething` method.
10397

10498
```csharp
10599
static void Main()
@@ -120,24 +114,7 @@ public static void DoSomething(int anInt, string aString)
120114
}
121115
```
122116

123-
### Method-first
124-
125-
Another approach is to let `System.CommandLine` configure the parser for you based on your method signature using the `Command.ConfigureFromMethod` extension method found in the `System.CommandLine.DragonFruit` library. (The [DragonFruit](Your-first-app-with-System.CommandLine.DragonFruit.md) app model uses this approach for its strongly-typed `Main` method but it can be used with any method.)
126-
127-
```csharp
128-
static void Main()
129-
{
130-
var rootCommand = new RootCommand();
131-
132-
MethodInfo method = typeof(Program).GetMethod(nameof(DoSomething));
133-
134-
rootCommand.ConfigureFromMethod<int, string>(method);
135-
136-
rootCommand.InvokeAsync(args).Wait();
137-
}
138-
```
139-
140-
`ConfigureFromMethod` adds options to your command based on the parameters of the specified method. Options are created using a naming convention that converts camel-cased parameters to kebab-cased options. In this example, the parameter `anInt` generates an option with the alias `--an-int`;
117+
For more details, see: [model binding](model-binding.md).
141118

142119
## Argument validation and binding
143120

0 commit comments

Comments
 (0)