Skip to content

Commit 351c246

Browse files
committed
Releasing CLUNL.ConsoleAppHelper 0.0.2
Fixed the bug that ConsoleAppHelper will crash when a feature have no options.
1 parent 6f11dc2 commit 351c246

File tree

6 files changed

+106
-49
lines changed

6 files changed

+106
-49
lines changed

CLUNL.ConsoleAppHelper/CLUNL.ConsoleAppHelper.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>net5.0</TargetFramework>
55
<GenerateDocumentationFile>True</GenerateDocumentationFile>
6-
<Version>0.0.1.0</Version>
6+
<Version>0.0.2.0</Version>
77
<PackageLicenseExpression></PackageLicenseExpression>
88
<PackageProjectUrl>https://github.com/creeperlv/CLUNL</PackageProjectUrl>
99
<RepositoryUrl>https://github.com/creeperlv/CLUNL</RepositoryUrl>

CLUNL.ConsoleAppHelper/ConsoleAppHelper.cs

+49-44
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public static void Init(string FeatureCollectionID, string ProductName = "CLUNL"
212212
{
213213
if (Feature.FeatureCollectionID == FeatureCollectionID)
214214
{
215-
features.Add(Feature.Name.ToUpper(), (IFeature) Activator.CreateInstance(type));
215+
features.Add(Feature.Name.ToUpper(), (IFeature)Activator.CreateInstance(type));
216216
infos.Add(Feature.Name.ToUpper(), Feature);
217217
}
218218
}
@@ -227,7 +227,7 @@ public static void Init(string FeatureCollectionID, string ProductName = "CLUNL"
227227
{
228228
if (Feature.FeatureCollectionID == FeatureCollectionID)
229229
{
230-
VersionProvider = (IFeatureCollectionVersion) Activator.CreateInstance(type);
230+
VersionProvider = (IFeatureCollectionVersion)Activator.CreateInstance(type);
231231
}
232232
}
233233
}
@@ -283,53 +283,58 @@ public static void PrintHelp(string FeatureName)
283283
OutLine(FeatureDesc);
284284
OutLine();
285285
}
286-
OutLine("\t" + Language.Find("General.Console.Options", "Options:"));
287-
OutLine();
288-
ParameterList p = new ParameterList();
289-
p.ApplyDescription(infos[FeatureName]);
290-
Dictionary<string, List<string>> keyValuePairs = new Dictionary<string, List<string>>();
291-
foreach (var item in p.Parameters)
292-
{
293-
if (keyValuePairs.ContainsKey(item.Value))
294-
{
295-
keyValuePairs[item.Value].Add(item.Key);
296-
}
297-
else
298-
{
299-
keyValuePairs.Add(item.Value, new List<string>() { item.Value });
300-
}
301-
}
302-
foreach (var item in keyValuePairs)
303-
{
304-
Out("\t");
305-
for (int i = 0; i < item.Value.Count; i++)
286+
if (infos[FeatureName].Options != null)
287+
if (infos[FeatureName].OptionDescriptions != null)
306288
{
307-
if (i == 0)
308-
{
309-
Out($"-{item.Value[i]}");
310-
}
311-
else
312-
Out($", -{item.Value[i]}");
313-
}
314-
OutLine();
315-
int index = -1;
316-
for (int i = 0; i < p.Options.Count; i++)
317-
{
318-
if (p.Options.ElementAt(i).Key == item.Key)
289+
OutLine("\t" + Language.Find("General.Console.Options", "Options:"));
290+
OutLine();
291+
ParameterList p = new ParameterList();
292+
p.ApplyDescription(infos[FeatureName]);
293+
Dictionary<string, List<string>> keyValuePairs = new Dictionary<string, List<string>>();
294+
foreach (var item in p.Parameters)
319295
{
320-
index = i;
321-
break;
296+
if (keyValuePairs.ContainsKey(item.Value))
297+
{
298+
keyValuePairs[item.Value].Add(item.Key);
299+
}
300+
else
301+
{
302+
keyValuePairs.Add(item.Value, new List<string>() { item.Value });
303+
}
322304
}
323-
}
324-
string fallback = "";
325-
if (infos[FeatureName].OptionDescriptions is not null)
326-
if (infos[FeatureName].OptionDescriptions.Length > 0 && index is not -1)
305+
foreach (var item in keyValuePairs)
327306
{
328-
fallback = infos[FeatureName].OptionDescriptions[index];
307+
Out("\t");
308+
for (int i = 0; i < item.Value.Count; i++)
309+
{
310+
if (i == 0)
311+
{
312+
Out($"-{item.Value[i]}");
313+
}
314+
else
315+
Out($", -{item.Value[i]}");
316+
}
317+
OutLine();
318+
int index = -1;
319+
for (int i = 0; i < p.Options.Count; i++)
320+
{
321+
if (p.Options.ElementAt(i).Key == item.Key)
322+
{
323+
index = i;
324+
break;
325+
}
326+
}
327+
string fallback = "";
328+
if (infos[FeatureName].OptionDescriptions is not null)
329+
if (infos[FeatureName].OptionDescriptions.Length > 0 && index is not -1)
330+
{
331+
fallback = infos[FeatureName].OptionDescriptions[index];
332+
}
333+
OutLine($"\t{Language.Find(CurrentFeatureCollectionID + ".Options." + item.Key, fallback)}");
334+
329335
}
330-
OutLine($"\t{Language.Find(CurrentFeatureCollectionID + ".Options." + item.Key, fallback)}");
331336

332-
}
337+
}
333338
}
334339
/// <summary>
335340
/// Print out localized version message.
@@ -533,7 +538,7 @@ public object Query(string KeyVariant)
533538
/// <returns></returns>
534539
public T Query<T>(string KeyVariant)
535540
{
536-
return (T) Options[Parameters[KeyVariant.ToUpper()]];
541+
return (T)Options[Parameters[KeyVariant.ToUpper()]];
537542
}
538543
/// <summary>
539544
/// Internal usage.

Creeper Lv's Universal dotNet Library.sln

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 17
4-
VisualStudioVersion = 17.0.31521.260
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31624.102
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CLUNL", "Creeper Lv's Universal dotNet Library\CLUNL.csproj", "{597737F0-9561-49FF-B000-F45DF6156B2D}"
77
EndProject
@@ -31,9 +31,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CLUNL.Diagnosis", "CLUNL.Di
3131
EndProject
3232
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CLUNL.Scripting", "CLUNL.Scripting\CLUNL.Scripting.csproj", "{897B3DAD-B205-4771-8112-3357928B0801}"
3333
EndProject
34-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CLUNL.ConsoleAppHelper", "CLUNL.ConsoleAppHelper\CLUNL.ConsoleAppHelper.csproj", "{166A9243-50CA-4530-A4A7-71F27745675C}"
34+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CLUNL.ConsoleAppHelper", "CLUNL.ConsoleAppHelper\CLUNL.ConsoleAppHelper.csproj", "{166A9243-50CA-4530-A4A7-71F27745675C}"
3535
EndProject
36-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CLUNL.Localization", "CLUNL.Localization\CLUNL.Localization.csproj", "{92E8596E-2690-460B-BA6F-6CEE8167BBC1}"
36+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CLUNL.Localization", "CLUNL.Localization\CLUNL.Localization.csproj", "{92E8596E-2690-460B-BA6F-6CEE8167BBC1}"
37+
EndProject
38+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{EA434C75-880E-4D80-9415-8B91AE5431BA}"
39+
EndProject
40+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleConsoleApp", "SampleConsoleApp\SampleConsoleApp.csproj", "{01F9D58F-B60C-48F9-A2E7-9AEFC2E77321}"
3741
EndProject
3842
Global
3943
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -85,13 +89,18 @@ Global
8589
{92E8596E-2690-460B-BA6F-6CEE8167BBC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
8690
{92E8596E-2690-460B-BA6F-6CEE8167BBC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
8791
{92E8596E-2690-460B-BA6F-6CEE8167BBC1}.Release|Any CPU.Build.0 = Release|Any CPU
92+
{01F9D58F-B60C-48F9-A2E7-9AEFC2E77321}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
93+
{01F9D58F-B60C-48F9-A2E7-9AEFC2E77321}.Debug|Any CPU.Build.0 = Debug|Any CPU
94+
{01F9D58F-B60C-48F9-A2E7-9AEFC2E77321}.Release|Any CPU.ActiveCfg = Release|Any CPU
95+
{01F9D58F-B60C-48F9-A2E7-9AEFC2E77321}.Release|Any CPU.Build.0 = Release|Any CPU
8896
EndGlobalSection
8997
GlobalSection(SolutionProperties) = preSolution
9098
HideSolutionNode = FALSE
9199
EndGlobalSection
92100
GlobalSection(NestedProjects) = preSolution
93101
{09947DA9-3CE4-4E7E-9087-B8083DC26DB9} = {5BE49C17-34E3-4EED-BA8F-F967683C6232}
94102
{4E577367-A548-4C58-BB3C-DA55F6D424E1} = {5BE49C17-34E3-4EED-BA8F-F967683C6232}
103+
{01F9D58F-B60C-48F9-A2E7-9AEFC2E77321} = {EA434C75-880E-4D80-9415-8B91AE5431BA}
95104
EndGlobalSection
96105
GlobalSection(ExtensibilityGlobals) = postSolution
97106
SolutionGuid = {C906856E-1A4B-4972-8D20-2B10DA48F4D0}

SampleConsoleApp/Locales/en-US.lang

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Default Language File
2+
# Created By Creeper Lv
3+
Warning.000=Test

SampleConsoleApp/Program.cs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using CLUNL.ConsoleAppHelper;
2+
using System;
3+
4+
namespace SampleConsoleApp
5+
{
6+
public class Program
7+
{
8+
static void Main(string[] args)
9+
{
10+
ConsoleAppHelper.Init("Sample", "Sample");
11+
ConsoleAppHelper.Execute(args);
12+
}
13+
}
14+
[DependentFeature("Sample","Feature0")]
15+
public class Feature0 : IFeature
16+
{
17+
public void Execute(ParameterList Parameters, string MainParameter)
18+
{
19+
Output.Out(new WarnMsg { ID = "Warning.000", Fallback = "Test" });
20+
}
21+
}
22+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net5.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\CLUNL.ConsoleAppHelper\CLUNL.ConsoleAppHelper.csproj" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<None Update="Locales\en-US.lang">
14+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
15+
</None>
16+
</ItemGroup>
17+
18+
</Project>

0 commit comments

Comments
 (0)