Skip to content

Naming mismatch between options/arguments and handler parameters is non-obvious #557

Open
@jonsequitur

Description

@jonsequitur

System.CommandLine's most common usability issue is that handler parameters whose name doesn't match an option or argument will never be successfully bound at invocation time.

For example, it may seem intuitive that the following should work, but handler parameter i will never be bound:

var command = new RootCommand
{ 
    new Option<int>("--an-int")
};

command.Handler = CommandHandler.Create<int>( i => /*   */ );

The alternative APIs were introduced here:

A more flexible approach (using a similar API pattern but generating the handlers using source generators) is being worked out here:

Possible approaches include:

  • Add an ordering-based matching strategy. This possibly suffers from other non-obviousness problems. Maybe the two strategies can operate together.
  • Add an error checking mechanism. Ideally this would not be a runtime check since, once compiled, it would be a continual performance hit while the answer would never change. An analyzer might be a good approach.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions