File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed
Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change 44
55namespace ProgramArgumentsManager
66{
7+ using Exceptions ;
8+
79 public class ArgumentsManager
810 {
911 private const int _DEFAULT_PAD_LEFT = 20 ;
@@ -88,17 +90,25 @@ public string GetUsage(int padLeft = _DEFAULT_PAD_LEFT)
8890 current + option . Key . ToString ( ) . PadLeft ( padLeft ) + " = " + option . Key . Description + "\n " ) ;
8991 }
9092
93+ public void CheckRequired ( )
94+ {
95+ foreach ( Argument argument in _options . Keys . Where ( a => a . Asked == Argument . Ask . Required && ! IsSpecified ( a . Names [ 0 ] ) ) )
96+ throw new ArgumentRequiredException ( argument ) ;
97+ }
98+
99+ public List < Argument > GetMissingArguments ( ) => _options . Keys . Where ( a => a . Asked == Argument . Ask . Required && ! IsSpecified ( a . Names [ 0 ] ) ) . ToList ( ) ;
100+
91101 public class Argument
92102 {
93- private enum Ask
103+ public enum Ask
94104 {
95105 Required ,
96106 Optional
97107 }
98108
99109 public string [ ] Names { get ; }
100110 public string Description { get ; }
101- private readonly Ask _ask ;
111+ public Ask Asked { get ; }
102112
103113 internal Argument ( string name , string desc ) : this ( new [ ] { name } , desc ) { }
104114
@@ -108,11 +118,11 @@ internal Argument(string[] names, string desc)
108118 Description = desc ;
109119
110120 if ( desc . StartsWith ( "[OPTIONAL]" , StringComparison . InvariantCultureIgnoreCase ) )
111- _ask = Ask . Optional ;
121+ Asked = Ask . Optional ;
112122 else if ( desc . StartsWith ( "[REQUIRED]" , StringComparison . InvariantCultureIgnoreCase ) )
113- _ask = Ask . Required ;
123+ Asked = Ask . Required ;
114124 else
115- _ask = Ask . Required ;
125+ Asked = Ask . Optional ;
116126 }
117127
118128 private bool Equals ( Argument other ) => other . Names . Any ( s => Names . Contains ( s ) ) ;
You can’t perform that action at this time.
0 commit comments