@@ -7,50 +7,88 @@ public interface IArgumentParser<T>
77 static abstract bool TryParse ( ReadOnlySpan < char > s , out T result ) ;
88}
99
10+ /// <summary>
11+ /// Represents the execution context for a console application command, containing command metadata and parsed arguments.
12+ /// </summary>
1013public record ConsoleAppContext
1114{
15+ /// <summary>
16+ /// Gets the name of the command being executed.
17+ /// </summary>
1218 public string CommandName { get ; init ; }
13- public string [ ] Arguments { get ; init ; }
19+
20+ /// <summary>
21+ /// Gets the raw arguments passed to the application, including the command name itself.
22+ /// </summary>
23+ public ReadOnlyMemory < string > Arguments { get ; init ; }
24+
25+ /// <summary>
26+ /// Gets the custom state object that can be used to share data across commands.
27+ /// </summary>
1428 public object ? State { get ; init ; }
29+
30+ /// <summary>
31+ /// Gets the parsed global options that apply across all commands.
32+ /// </summary>
1533 public object ? GlobalOptions { get ; init ; }
1634
35+ /// <summary>
36+ /// Gets the depth of the command in a nested command hierarchy. Used internally by the framework.
37+ /// </summary>
1738 [ EditorBrowsable ( EditorBrowsableState . Never ) ]
1839 public int CommandDepth { get ; }
1940
41+ /// <summary>
42+ /// Gets the index of the escape separator ('--') in the arguments, or -1 if not present. Used internally by the framework.
43+ /// </summary>
2044 [ EditorBrowsable ( EditorBrowsableState . Never ) ]
2145 public int EscapeIndex { get ; }
2246
47+ /// <summary>
48+ /// Gets the internal command arguments with global options removed. Used internally by the framework.
49+ /// </summary>
2350 [ EditorBrowsable ( EditorBrowsableState . Never ) ]
24- public string [ ] InternalCommandArgs { get ; }
51+ public ReadOnlyMemory < string > InternalCommandArgs { get ; }
2552
53+ /// <summary>
54+ /// Gets the arguments intended for the current command, excluding the command name and any escaped arguments after '--'.
55+ /// </summary>
2656 public ReadOnlySpan < string > CommandArguments
2757 {
2858 get => ( EscapeIndex == - 1 )
29- ? Arguments . AsSpan ( CommandDepth )
30- : Arguments . AsSpan ( CommandDepth , EscapeIndex - CommandDepth ) ;
59+ ? Arguments . Span . Slice ( CommandDepth )
60+ : Arguments . Span . Slice ( CommandDepth , EscapeIndex - CommandDepth ) ;
3161 }
3262
63+ /// <summary>
64+ /// Gets the arguments that appear after the escape separator ('--'), which are not parsed by the command.
65+ /// Returns an empty span if no escape separator is present.
66+ /// </summary>
3367 public ReadOnlySpan < string > EscapedArguments
3468 {
3569 get => ( EscapeIndex == - 1 )
3670 ? Array . Empty < string > ( )
37- : Arguments . AsSpan ( EscapeIndex + 1 ) ;
71+ : Arguments . Span . Slice ( EscapeIndex + 1 ) ;
3872 }
3973
40- public ConsoleAppContext ( string commandName , string [ ] arguments , string [ ] commandArgs , object ? state , object ? globalOptions , int commandDepth , int escapeIndex )
74+ public ConsoleAppContext ( string commandName , ReadOnlyMemory < string > arguments , ReadOnlyMemory < string > internalCommandArgs , object ? state , object ? globalOptions , int commandDepth , int escapeIndex )
4175 {
4276 this . CommandName = commandName ;
4377 this . Arguments = arguments ;
44- this . InternalCommandArgs = commandArgs ;
78+ this . InternalCommandArgs = internalCommandArgs ;
4579 this . State = state ;
4680 this . GlobalOptions = globalOptions ;
4781 this . CommandDepth = commandDepth ;
4882 this . EscapeIndex = escapeIndex ;
4983 }
5084
85+ /// <summary>
86+ /// Returns a string representation of all arguments joined by spaces.
87+ /// </summary>
88+ /// <returns>A space-separated string of all arguments.</returns>
5189 public override string ToString ( )
5290 {
53- return string . Join ( " " , Arguments ) ;
91+ return string . Join ( " " , Arguments . ToArray ( ) ) ;
5492 }
5593}
5694
0 commit comments