command-line-api
command-line-api copied to clipboard
Type Binding
Current Problems
-
We cannot register custom type binding. We have to provide a
parseArgumentmethod to every option and/or argument where the same custom type is used. -
We cannot leverage the existing validation logic for supported types such as
Urito parse custom types, since we are back to dealing with string tokens once we useparseArgument.
Proposed Solution
I would like to have an API that allows custom type binding.
builder.BindArgumentType<IDbClient>(str => new DbClient(str));
// or, to leverage existing validation for `Uri`
builder.BindArgumentType<Uri, IDbClient>(uri => new DbClient(uri));
Then we can make the code much more lean and readable when we use the type binding.
new Option<IDbClient>("--from"),
// the following should work even if `List<IDbClient>` is not registered by the user
new Option<List<IDbClient>>("--to"),