Skip to content

Commit df563a8

Browse files
committed
Update ArgumentsManager.cs
Added FullName property Added AddArguments(Argument arg) overload Added AddHelpArgument method Added CheckHelp method Added AddVersionArgument method Added CheckVersion method
1 parent 291017b commit df563a8

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

ProgramArgumentsManager/ArgumentsManager.cs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public class ArgumentsManager
1414
public string AppDescription { get; }
1515
public string Version { get; }
1616

17+
public string FullName => AppName + " " + Version;
18+
1719
private readonly Dictionary<Argument, Argument.ArgValues> _options;
1820

1921
public ArgumentsManager(string name) : this(name, "1.0.0") { }
@@ -46,9 +48,43 @@ public void AddArguments(string format, string description)
4648
throw new ArgumentException("Le format '" + format + " n'est pas comaptible en tant que paramètre !",
4749
nameof(format));
4850

49-
_options.Add(new Argument(formats, description), new Argument.ArgValues());
51+
AddArguments(new Argument(formats, description));
52+
}
53+
54+
private void AddArguments(Argument arg) => _options.Add(arg, new Argument.ArgValues());
55+
56+
public void AddHelpArgument() => AddArguments("-?, --help", "Show this help page");
57+
58+
public bool CheckHelp() => IsSpecified("?");
59+
60+
public void CheckHelp<T>(Action callback)
61+
{
62+
if (IsSpecified("?"))
63+
callback();
64+
}
65+
66+
public void CheckHelp<T1>(Action<T1> callback, T1 arg1)
67+
{
68+
if (IsSpecified("?"))
69+
callback(arg1);
5070
}
5171

72+
public void CheckHelp<T1, T2>(Action<T1, T2> callback, T1 arg1, T2 arg2)
73+
{
74+
if (IsSpecified("?"))
75+
callback(arg1, arg2);
76+
}
77+
78+
public void CheckHelp<TResult, T1, T2>(Func<T1, T2, TResult> callback, T1 param1, T2 param2)
79+
{
80+
if (IsSpecified("?"))
81+
callback(param1, param2);
82+
}
83+
84+
public void AddVersionArgument() => AddArguments("-v, --version", "Show the app version");
85+
86+
public bool CheckVersion() => IsSpecified("v");
87+
5288
public void Parse(string[] args)
5389
{
5490
string lastArg = null;

0 commit comments

Comments
 (0)