Skip to content

Commit 2e67990

Browse files
committed
Amelioration
Added and moved Argument class Renamed and updated ArgumentManager
1 parent 8e1f4f6 commit 2e67990

File tree

3 files changed

+58
-36
lines changed

3 files changed

+58
-36
lines changed

ProgramArgumentsManager/Arguments.cs

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.CodeDom;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
6+
namespace ProgramArgumentsManager
7+
{
8+
public class ArgumentsManager
9+
{
10+
public string ApplicationName { get; }
11+
public string Version { get; }
12+
13+
private Dictionary<Argument, string> _options;
14+
15+
public ArgumentsManager(string name) : this(name, "1.0.0") { }
16+
17+
public ArgumentsManager(string name, string version)
18+
{
19+
ApplicationName = name;
20+
Version = version;
21+
22+
_options = new Dictionary<Argument, string>();
23+
}
24+
25+
public void AddArguments(string format, string description)
26+
{
27+
format = format.Trim();
28+
29+
if (!format.Contains("-") && !format.Contains("--"))
30+
throw new ArgumentException("Le format '" + format + " n'est pas comaptible en tant que paramètre !",
31+
nameof(format));
32+
33+
char[] delimiters = {',', ';'};
34+
string[] formats = format.Split(delimiters);
35+
36+
if (formats.Any(f => !f.StartsWith("-") && !f.StartsWith("--")))
37+
throw new ArgumentException("Le format '" + format + " n'est pas comaptible en tant que paramètre !",
38+
nameof(format));
39+
40+
_options.Add(new Argument(formats), description);
41+
}
42+
43+
private class Argument
44+
{
45+
private string[] _names { get; }
46+
47+
public Argument(string name) : this(new []{name}) { }
48+
public Argument(string name1, string name2) : this(new[] {name1, name2}) { }
49+
public Argument(string[] names)
50+
{
51+
_names = names;
52+
}
53+
54+
public bool Contain(string name) => _names.Contains(name);
55+
}
56+
}
57+
}

ProgramArgumentsManager/ProgramArgumentsManager.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<Reference Include="System.Xml" />
4242
</ItemGroup>
4343
<ItemGroup>
44-
<Compile Include="Arguments.cs" />
44+
<Compile Include="ArgumentsManager.cs" />
4545
<Compile Include="Properties\AssemblyInfo.cs" />
4646
</ItemGroup>
4747
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

0 commit comments

Comments
 (0)