Skip to content

Commit 291017b

Browse files
committed
Update ArgumentsManager.cs
Added ArgumentsManager.HasValue method Updated ArgumentsManager.GetMissingArguments method
1 parent 23b77e7 commit 291017b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

ProgramArgumentsManager/ArgumentsManager.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public void Parse(string[] args)
7575

7676
public string GetValue(string arg) => _options[arg].Values is null ? null : string.Join(" ", _options[arg].Values);
7777

78+
public bool HasValue(string arg) => _options[arg].Values != null;
79+
7880
public void ShowUsage(int padLeft = _DEFAULT_PAD_LEFT) => Console.WriteLine(GetUsage(padLeft));
7981

8082
public string GetUsage(int padLeft = _DEFAULT_PAD_LEFT)
@@ -98,7 +100,15 @@ public void CheckRequired()
98100
throw new ArgumentRequiredException(argument);
99101
}
100102

101-
public List<Argument> GetMissingArguments() => _options.Keys.Where(a => a.Asked == Argument.Ask.Required && !IsSpecified(a.Names[0])).ToList();
103+
public List<Argument> GetMissingArguments() => GetMissingArguments(false);
104+
public List<Argument> GetMissingArguments(bool permitNull)
105+
{
106+
Func<Argument, bool> predicate = a => permitNull ?
107+
a.Asked == Argument.Ask.Required && !IsSpecified(a.Names[0]) :
108+
!HasValue(a.Names[0]);
109+
110+
return _options.Keys.Where(predicate).ToList();
111+
}
102112

103113
public class Argument
104114
{
@@ -112,7 +122,7 @@ public enum Ask
112122
public string Description { get; }
113123
public Ask Asked { get; internal set; }
114124

115-
internal Argument(string name, string desc) : this(new[] {name}, desc) { }
125+
internal Argument(string name, string desc) : this(new[] { name }, desc) { }
116126

117127
internal Argument(string[] names, string desc)
118128
{

0 commit comments

Comments
 (0)