dotnet / dotnet/command-line-api
How to get `Command` when setting up host.
- Dominant language
- C#
- Stars
- 3.7k
- Forks
- 428
- PR merge metrics
- No merged PRs in 30d
Description
What is the easiest way to get `Command` and its `Options` or `Arguments` when configuring the host?
is this the best way?
```csharp
public static bool TryGetGlobalInputOption(this IHostBuilder hostBuilder, [NotNullWhen(true)] out string? filename)
{
var invocation = hostBuilder.Properties[typeof(InvocationContext)] as InvocationContext;
var command = invocation!.ParseResult.CommandResult.Command;
var inputOptions = command.Options.FirstOrDefault(f => f.Name == "input");
filename = null;
if (inputOptions != null)
filename = invocation.ParseResult.GetValueForOption(inputOptions) as string;
return filename != null;
}
```
Contributor guide
Assessment
This issue has not been assessed yet.