dotnet / command-line-api

Command line parsing, invocation, and rendering of terminal output.
https://github.com/dotnet/command-line-api/wiki
MIT License
3.35k stars 375 forks source link

Collections need to support locations #2389

Open KathleenDollard opened 2 months ago

KathleenDollard commented 2 months ago

The current structure of Location is:

   public string Text { get; }
   public string Source { get; }
   public int Index { get; }
   public int Offset { get; }
   public int Length { get; }
   public Location? OuterLocation { get; }

To support goals of errata and reporting where values came from, we are building in a location system. This is attached to ValueResult and CommandValueResult in the public API. This does not currently support collections.

In order to support a pattern were -x is an option that accepts a collection, we need to maintain a Location instance for each member of the collection:

mycommand -x One @mine.rsp Two

AFAIK, this is valid, and if the response file had three entries, there would be five values in the collection for the option.

Thus, the design is that ValueResult will hold a collection of Location.

Sidenotes:

  • Index was renamed from Start recently.
  • We plan to rename CommandValueResult, but do not want the disruption now of renaming CommandResult which is one of the alternate names.
  • For performance reasons, we may later set a flag to maintain locations only when requested or be able to turn them off. Also, the size is relatively small because the Text, Source, and Location will generally be references to existing instance.