33using System . Collections . ObjectModel ;
44using System . ComponentModel ;
55using System . Linq ;
6+ using System . Reflection . Metadata . Ecma335 ;
67
78namespace J4JSoftware . CommandLine
89{
@@ -12,62 +13,45 @@ public class Option
1213 private readonly List < string > _allocatedValues = new List < string > ( ) ;
1314 private readonly MasterTextCollection _masterText ;
1415
15- private int _allowedNumValues ;
16-
1716 internal Option (
18- Options container ,
19- IContextKey contextKey ,
17+ OptionsBase container ,
18+ string contextPath ,
2019 MasterTextCollection masterText
2120 )
2221 {
2322 Container = container ;
24- ContextKey = contextKey ;
23+ ContextPath = contextPath ;
2524 _masterText = masterText ;
2625
2726 if ( Container . UsesContextPath ( ContextPath ! ) )
2827 throw new ArgumentException ( $ "Duplicate context key path '{ ContextPath } '" ) ;
2928 }
3029
3130 // the collection of Options used by the parsing activity
32- public Options Container { get ; }
33-
34- public IContextKey ? ContextKey { get ; }
35-
36- public List < IContextKey > ? ContextPath
37- {
38- get
39- {
40- if ( Parent == null || ContextKey == null )
41- {
42- if ( ContextKey == null )
43- return null ;
44-
45- return new List < IContextKey > { ContextKey } ;
46- }
31+ public OptionsBase Container { get ; }
4732
48- var retVal = Parent . ContextPath ! ;
49-
50- retVal . Add ( ContextKey ) ;
51-
52- return retVal ;
53- }
54- }
55-
56- public Option ? Parent { get ; private set ; }
33+ public string ? ContextPath { get ; }
5734
5835 public ReadOnlyCollection < string > Keys => _cmdLineKeys . AsReadOnly ( ) ;
5936
60- // the first key defined for an option, sorted alphabetically (Options can define multiple keys
61- // but they must be unique within the scope of all Options)
62- public string FirstKey => _cmdLineKeys . OrderBy ( k => k ) . First ( ) ;
63-
6437 public string ? CommandLineKeyProvided { get ; set ; }
6538
66- public bool WasAssignedValue
39+ public int MaxValues =>
40+ Style switch
41+ {
42+ OptionStyle . Collection => int . MaxValue ,
43+ OptionStyle . SingleValued => 1 ,
44+ OptionStyle . Switch => 0 ,
45+ _ => throw new InvalidEnumArgumentException ( $ "Unsupported OptionStyle '{ Style } '" )
46+ } ;
47+
48+ public int NumValuesAllocated => _allocatedValues . Count ;
49+
50+ public bool ValuesSatisfied
6751 {
6852 get
6953 {
70- if ( string . IsNullOrEmpty ( CommandLineKeyProvided ) )
54+ if ( string . IsNullOrEmpty ( CommandLineKeyProvided ) )
7155 return false ;
7256
7357 var numValuesAlloc = _allocatedValues . Count ;
@@ -81,7 +65,7 @@ public bool WasAssignedValue
8165 } ;
8266 }
8367 }
84-
68+
8569 public ReadOnlyCollection < string > CommandLineValues => _allocatedValues . AsReadOnly ( ) ;
8670
8771 public OptionStyle Style { get ; private set ; }
@@ -114,14 +98,7 @@ public Option AddCommandLineKeys(params string[] cmdLineKeys)
11498
11599 public Option SetStyle ( OptionStyle style )
116100 {
117- _allowedNumValues = style switch
118- {
119- OptionStyle . Collection => Int32 . MaxValue ,
120- OptionStyle . SingleValued => 1 ,
121- OptionStyle . Switch => 0 ,
122- _ => throw new InvalidEnumArgumentException ( $ "Unsupported OptionStyle '{ style } '" )
123- } ;
124-
101+ Style = style ;
125102 return this ;
126103 }
127104
@@ -142,13 +119,5 @@ public Option SetDescription(string description)
142119 Description = description ;
143120 return this ;
144121 }
145-
146- public Option ChildOf ( Option parent )
147- {
148- if ( parent != this )
149- Parent = parent ;
150-
151- return this ;
152- }
153122 }
154123}
0 commit comments