Skip to content

Commit 293cbc5

Browse files
committed
Internal refactoring in HelpText to comply CodeAnalysis.
1 parent 0450346 commit 293cbc5

File tree

10 files changed

+253
-244
lines changed

10 files changed

+253
-244
lines changed

CommandLine.sln

Lines changed: 82 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,82 @@
1-
2-
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 2012
4-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommandLine", "src\libcmdline\CommandLine.csproj", "{5DEA2811-2FFA-4959-830B-CAD3ACACABEB}"
5-
EndProject
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommandLine.Tests", "src\tests\CommandLine.Tests.csproj", "{86E1AC34-ED2D-4E42-8B95-65208FEA36C2}"
7-
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommandLine.Demo", "src\demo\CommandLine.Demo.csproj", "{9E573FFF-4ECB-4C59-A914-C0B74D44D2E8}"
9-
EndProject
10-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".Welcome", ".Welcome", "{4F498B61-A7BC-4B32-9ACB-901D4F50659B}"
11-
ProjectSection(SolutionItems) = preProject
12-
doc\ChangeLog = doc\ChangeLog
13-
doc\LICENSE = doc\LICENSE
14-
doc\PublicAPI.md = doc\PublicAPI.md
15-
README.md = README.md
16-
EndProjectSection
17-
EndProject
18-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NuGet", "NuGet", "{CC062800-4709-4A04-8A0D-DD972C1BFFC5}"
19-
ProjectSection(SolutionItems) = preProject
20-
nuget\CommandLine.nuspec = nuget\CommandLine.nuspec
21-
nuget\readme.txt = nuget\readme.txt
22-
EndProjectSection
23-
EndProject
24-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{18282A82-E36C-4938-8397-C0A1166983BA}"
25-
ProjectSection(SolutionItems) = preProject
26-
Rakefile.rb = Rakefile.rb
27-
EndProjectSection
28-
EndProject
29-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{350E598F-50C7-45A2-83A6-346AF7D163F5}"
30-
ProjectSection(SolutionItems) = preProject
31-
.nuget\packages.config = .nuget\packages.config
32-
EndProjectSection
33-
EndProject
34-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Develop", "Develop", "{939BEBC0-CE70-4209-A991-0DA4E8F3B9AE}"
35-
EndProject
36-
Global
37-
GlobalSection(SolutionConfigurationPlatforms) = preSolution
38-
Debug|Any CPU = Debug|Any CPU
39-
Debug|x86 = Debug|x86
40-
Release|Any CPU = Release|Any CPU
41-
Release|x86 = Release|x86
42-
EndGlobalSection
43-
GlobalSection(ProjectConfigurationPlatforms) = postSolution
44-
{5DEA2811-2FFA-4959-830B-CAD3ACACABEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45-
{5DEA2811-2FFA-4959-830B-CAD3ACACABEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
46-
{5DEA2811-2FFA-4959-830B-CAD3ACACABEB}.Debug|x86.ActiveCfg = Debug|Any CPU
47-
{5DEA2811-2FFA-4959-830B-CAD3ACACABEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
48-
{5DEA2811-2FFA-4959-830B-CAD3ACACABEB}.Release|Any CPU.Build.0 = Release|Any CPU
49-
{5DEA2811-2FFA-4959-830B-CAD3ACACABEB}.Release|x86.ActiveCfg = Release|Any CPU
50-
{86E1AC34-ED2D-4E42-8B95-65208FEA36C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51-
{86E1AC34-ED2D-4E42-8B95-65208FEA36C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
52-
{86E1AC34-ED2D-4E42-8B95-65208FEA36C2}.Debug|x86.ActiveCfg = Debug|Any CPU
53-
{86E1AC34-ED2D-4E42-8B95-65208FEA36C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
54-
{86E1AC34-ED2D-4E42-8B95-65208FEA36C2}.Release|Any CPU.Build.0 = Release|Any CPU
55-
{86E1AC34-ED2D-4E42-8B95-65208FEA36C2}.Release|x86.ActiveCfg = Release|Any CPU
56-
{9E573FFF-4ECB-4C59-A914-C0B74D44D2E8}.Debug|Any CPU.ActiveCfg = Debug|x86
57-
{9E573FFF-4ECB-4C59-A914-C0B74D44D2E8}.Debug|Any CPU.Build.0 = Debug|x86
58-
{9E573FFF-4ECB-4C59-A914-C0B74D44D2E8}.Debug|x86.ActiveCfg = Debug|x86
59-
{9E573FFF-4ECB-4C59-A914-C0B74D44D2E8}.Debug|x86.Build.0 = Debug|x86
60-
{9E573FFF-4ECB-4C59-A914-C0B74D44D2E8}.Release|Any CPU.ActiveCfg = Release|x86
61-
{9E573FFF-4ECB-4C59-A914-C0B74D44D2E8}.Release|Any CPU.Build.0 = Release|x86
62-
{9E573FFF-4ECB-4C59-A914-C0B74D44D2E8}.Release|x86.ActiveCfg = Release|x86
63-
{9E573FFF-4ECB-4C59-A914-C0B74D44D2E8}.Release|x86.Build.0 = Release|x86
64-
EndGlobalSection
65-
GlobalSection(SolutionProperties) = preSolution
66-
HideSolutionNode = FALSE
67-
EndGlobalSection
68-
GlobalSection(NestedProjects) = preSolution
69-
{939BEBC0-CE70-4209-A991-0DA4E8F3B9AE} = {4F498B61-A7BC-4B32-9ACB-901D4F50659B}
70-
{18282A82-E36C-4938-8397-C0A1166983BA} = {4F498B61-A7BC-4B32-9ACB-901D4F50659B}
71-
{CC062800-4709-4A04-8A0D-DD972C1BFFC5} = {939BEBC0-CE70-4209-A991-0DA4E8F3B9AE}
72-
EndGlobalSection
73-
GlobalSection(MonoDevelopProperties) = preSolution
74-
StartupItem = src\demo\CommandLine.Demo.csproj
75-
Policies = $0
76-
$0.TextStylePolicy = $1
77-
$1.FileWidth = 120
78-
$1.TabsToSpaces = False
79-
$1.inheritsSet = VisualStudio
80-
$1.inheritsScope = text/plain
81-
EndGlobalSection
82-
EndGlobal
1+
2+
Microsoft Visual Studio Solution File, Format Version 11.00
3+
# Visual Studio 2010
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommandLine", "src\libcmdline\CommandLine.csproj", "{5DEA2811-2FFA-4959-830B-CAD3ACACABEB}"
5+
EndProject
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommandLine.Tests", "src\tests\CommandLine.Tests.csproj", "{86E1AC34-ED2D-4E42-8B95-65208FEA36C2}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommandLine.Demo", "src\demo\CommandLine.Demo.csproj", "{9E573FFF-4ECB-4C59-A914-C0B74D44D2E8}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".Welcome", ".Welcome", "{4F498B61-A7BC-4B32-9ACB-901D4F50659B}"
11+
ProjectSection(SolutionItems) = preProject
12+
doc\ChangeLog = doc\ChangeLog
13+
doc\LICENSE = doc\LICENSE
14+
doc\PublicAPI.md = doc\PublicAPI.md
15+
README.md = README.md
16+
EndProjectSection
17+
EndProject
18+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NuGet", "NuGet", "{CC062800-4709-4A04-8A0D-DD972C1BFFC5}"
19+
ProjectSection(SolutionItems) = preProject
20+
nuget\CommandLine.nuspec = nuget\CommandLine.nuspec
21+
nuget\readme.txt = nuget\readme.txt
22+
EndProjectSection
23+
EndProject
24+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{18282A82-E36C-4938-8397-C0A1166983BA}"
25+
ProjectSection(SolutionItems) = preProject
26+
Rakefile.rb = Rakefile.rb
27+
EndProjectSection
28+
EndProject
29+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{350E598F-50C7-45A2-83A6-346AF7D163F5}"
30+
ProjectSection(SolutionItems) = preProject
31+
.nuget\packages.config = .nuget\packages.config
32+
EndProjectSection
33+
EndProject
34+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Develop", "Develop", "{939BEBC0-CE70-4209-A991-0DA4E8F3B9AE}"
35+
EndProject
36+
Global
37+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
38+
Debug|Any CPU = Debug|Any CPU
39+
Debug|x86 = Debug|x86
40+
Release|Any CPU = Release|Any CPU
41+
Release|x86 = Release|x86
42+
EndGlobalSection
43+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
44+
{5DEA2811-2FFA-4959-830B-CAD3ACACABEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45+
{5DEA2811-2FFA-4959-830B-CAD3ACACABEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
46+
{5DEA2811-2FFA-4959-830B-CAD3ACACABEB}.Debug|x86.ActiveCfg = Debug|Any CPU
47+
{5DEA2811-2FFA-4959-830B-CAD3ACACABEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
48+
{5DEA2811-2FFA-4959-830B-CAD3ACACABEB}.Release|Any CPU.Build.0 = Release|Any CPU
49+
{5DEA2811-2FFA-4959-830B-CAD3ACACABEB}.Release|x86.ActiveCfg = Release|Any CPU
50+
{86E1AC34-ED2D-4E42-8B95-65208FEA36C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51+
{86E1AC34-ED2D-4E42-8B95-65208FEA36C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
52+
{86E1AC34-ED2D-4E42-8B95-65208FEA36C2}.Debug|x86.ActiveCfg = Debug|Any CPU
53+
{86E1AC34-ED2D-4E42-8B95-65208FEA36C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
54+
{86E1AC34-ED2D-4E42-8B95-65208FEA36C2}.Release|Any CPU.Build.0 = Release|Any CPU
55+
{86E1AC34-ED2D-4E42-8B95-65208FEA36C2}.Release|x86.ActiveCfg = Release|Any CPU
56+
{9E573FFF-4ECB-4C59-A914-C0B74D44D2E8}.Debug|Any CPU.ActiveCfg = Debug|x86
57+
{9E573FFF-4ECB-4C59-A914-C0B74D44D2E8}.Debug|Any CPU.Build.0 = Debug|x86
58+
{9E573FFF-4ECB-4C59-A914-C0B74D44D2E8}.Debug|x86.ActiveCfg = Debug|x86
59+
{9E573FFF-4ECB-4C59-A914-C0B74D44D2E8}.Debug|x86.Build.0 = Debug|x86
60+
{9E573FFF-4ECB-4C59-A914-C0B74D44D2E8}.Release|Any CPU.ActiveCfg = Release|x86
61+
{9E573FFF-4ECB-4C59-A914-C0B74D44D2E8}.Release|Any CPU.Build.0 = Release|x86
62+
{9E573FFF-4ECB-4C59-A914-C0B74D44D2E8}.Release|x86.ActiveCfg = Release|x86
63+
{9E573FFF-4ECB-4C59-A914-C0B74D44D2E8}.Release|x86.Build.0 = Release|x86
64+
EndGlobalSection
65+
GlobalSection(SolutionProperties) = preSolution
66+
HideSolutionNode = FALSE
67+
EndGlobalSection
68+
GlobalSection(NestedProjects) = preSolution
69+
{939BEBC0-CE70-4209-A991-0DA4E8F3B9AE} = {4F498B61-A7BC-4B32-9ACB-901D4F50659B}
70+
{18282A82-E36C-4938-8397-C0A1166983BA} = {4F498B61-A7BC-4B32-9ACB-901D4F50659B}
71+
{CC062800-4709-4A04-8A0D-DD972C1BFFC5} = {939BEBC0-CE70-4209-A991-0DA4E8F3B9AE}
72+
EndGlobalSection
73+
GlobalSection(MonoDevelopProperties) = preSolution
74+
StartupItem = src\demo\CommandLine.Demo.csproj
75+
Policies = $0
76+
$0.TextStylePolicy = $1
77+
$1.FileWidth = 120
78+
$1.TabsToSpaces = False
79+
$1.inheritsSet = VisualStudio
80+
$1.inheritsScope = text/plain
81+
EndGlobalSection
82+
EndGlobal

CommandLine.sln.DotSettings.user

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Command Line Parser Library 1.9.5.1 rc0 for CLR.
1+
Command Line Parser Library 1.9.5.3 rc0 for CLR.
22
===
33
The Command Line Parser Library offers to CLR applications a clean and concise API for manipulating command line arguments and related tasks defining switches, options and verb commands. It allows you to display an help screen with an high degree of customization and a simple way to report syntax errors to the end user. Everything that is boring and repetitive to be programmed stands up on library shoulders, letting developers concentrate on core logic.
44
__This library provides _hassle free_ command line parsing with a constantly updated API since 2005.__

Rakefile.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PRODUCT = "Command Line Parser Library"
22
DESCRIPTION = "The Command Line Parser Library offers to CLR applications a clean and concise API for manipulating command line arguments and related tasks."
3-
VERSION = "1.9.5.1"
3+
VERSION = "1.9.5.3"
44
INF_VERSION = "1.9.5-rc0"
55
AUTHOR = "Giacomo Stelluti Scala"
66
COPYRIGHT = "Copyright (c) 2005 - 2013 " + AUTHOR

doc/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use HelpText::AutoBuild(object,string)
2727
* HelpText class:
2828
- added HelpText::AutoBuild(object,string)
29+
- internal refactoring to safely suppress a CodeAnalysis warning.
2930
* Namespace Core renamed Infrastructure.
3031
* Extensions methods refacored in one class per group.
3132
* Fixed issue #6.

src/SharedAssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828

2929
[assembly: AssemblyProduct("Command Line Parser Library")]
3030
[assembly: AssemblyCopyright("Copyright (c) 2005 - 2013 Giacomo Stelluti Scala")]
31-
[assembly: AssemblyVersion("1.9.5.1")]
32-
[assembly: AssemblyFileVersion("1.9.5.1")]
31+
[assembly: AssemblyVersion("1.9.5.3")]
32+
[assembly: AssemblyFileVersion("1.9.5.3")]
3333

3434
[assembly: AssemblyInformationalVersion("1.9.5-rc0")]
3535
[assembly: NeutralResourcesLanguage("en-US")]

src/libcmdline/IHideObjectMembers.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public interface IHideObjectMembers
5454
[EditorBrowsable(EditorBrowsableState.Never)]
5555
int GetHashCode();
5656

57-
5857
/// <summary>
5958
/// Hides the <see cref="GetType"/> method.
6059
/// </summary>

src/libcmdline/Text/CopyrightInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public CopyrightInfo(bool isSymbolUpper, string author, params int[] copyrightYe
9191
this.isSymbolUpper = isSymbolUpper;
9292
this.author = author;
9393
this.copyrightYears = copyrightYears;
94-
this.builderSize = this.CopyrightWord.Length + author.Length + (4 * copyrightYears.Length) + ExtraLength;
94+
this.builderSize = 12 + author.Length + (4 * copyrightYears.Length) + ExtraLength;
9595
}
9696

9797
/// <summary>

src/libcmdline/Text/HelpText.cs

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ public HelpText(BaseSentenceBuilder sentenceBuilder, string heading, string copy
146146
/// <param name="copyright">A string with copyright or an instance of <see cref="CommandLine.Text.CopyrightInfo"/>.</param>
147147
/// <param name="options">The instance that collected command line arguments parsed with <see cref="Parser"/> class.</param>
148148
/// <exception cref="System.ArgumentException">Thrown when one or more parameters <paramref name="heading"/> are null or empty strings.</exception>
149+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification = "When DoAddOptions is called with fireEvent=false virtual member is not called")]
149150
public HelpText(string heading, string copyright, object options)
150151
: this()
151152
{
@@ -155,7 +156,7 @@ public HelpText(string heading, string copyright, object options)
155156

156157
this.heading = heading;
157158
this.copyright = copyright;
158-
this.AddOptions(options);
159+
this.DoAddOptions(options, DefaultRequiredWord, this.MaximumDisplayWidth, fireEvent: false);
159160
}
160161

161162
/// <summary>
@@ -442,26 +443,7 @@ public void AddOptions(object options, string requiredWord, int maximumLength)
442443
Assumes.NotNull(options, "options");
443444
Assumes.NotNullOrEmpty(requiredWord, "requiredWord");
444445

445-
var optionList = ReflectionUtil.RetrievePropertyAttributeList<BaseOptionAttribute>(options);
446-
var optionHelp = ReflectionUtil.RetrieveMethodAttributeOnly<HelpOptionAttribute>(options);
447-
448-
if (optionHelp != null)
449-
{
450-
optionList.Add(optionHelp);
451-
}
452-
453-
if (optionList.Count == 0)
454-
{
455-
return;
456-
}
457-
458-
int maxLength = this.GetMaxLength(optionList);
459-
this.optionsHelp = new StringBuilder(BuilderCapacity);
460-
int remainingSpace = maximumLength - (maxLength + 6);
461-
foreach (BaseOptionAttribute option in optionList)
462-
{
463-
this.AddOption(requiredWord, maxLength, option, remainingSpace);
464-
}
446+
this.DoAddOptions(options, requiredWord, maximumLength);
465447
}
466448

467449
/// <summary>
@@ -657,12 +639,36 @@ private static void AddLine(StringBuilder builder, string value, int maximumLeng
657639
builder.Append(value);
658640
}
659641

642+
private void DoAddOptions(object options, string requiredWord, int maximumLength, bool fireEvent = true)
643+
{
644+
var optionList = ReflectionUtil.RetrievePropertyAttributeList<BaseOptionAttribute>(options);
645+
var optionHelp = ReflectionUtil.RetrieveMethodAttributeOnly<HelpOptionAttribute>(options);
646+
647+
if (optionHelp != null)
648+
{
649+
optionList.Add(optionHelp);
650+
}
651+
652+
if (optionList.Count == 0)
653+
{
654+
return;
655+
}
656+
657+
int maxLength = this.GetMaxLength(optionList);
658+
this.optionsHelp = new StringBuilder(BuilderCapacity);
659+
int remainingSpace = maximumLength - (maxLength + 6);
660+
foreach (BaseOptionAttribute option in optionList)
661+
{
662+
this.AddOption(requiredWord, maxLength, option, remainingSpace, fireEvent);
663+
}
664+
}
665+
660666
private void AddPreOptionsLine(string value, int maximumLength)
661667
{
662668
AddLine(this.preOptionsHelp, value, maximumLength);
663669
}
664670

665-
private void AddOption(string requiredWord, int maxLength, BaseOptionAttribute option, int widthOfHelpText)
671+
private void AddOption(string requiredWord, int maxLength, BaseOptionAttribute option, int widthOfHelpText, bool fireEvent = true)
666672
{
667673
this.optionsHelp.Append(" ");
668674
var optionName = new StringBuilder(maxLength);
@@ -716,9 +722,12 @@ private void AddOption(string requiredWord, int maxLength, BaseOptionAttribute o
716722
option.HelpText = "{0} ".FormatInvariant(requiredWord) + option.HelpText;
717723
}
718724

719-
var e = new FormatOptionHelpTextEventArgs(option);
720-
this.OnFormatOptionHelpText(e);
721-
option.HelpText = e.Option.HelpText;
725+
if (fireEvent)
726+
{
727+
var e = new FormatOptionHelpTextEventArgs(option);
728+
this.OnFormatOptionHelpText(e);
729+
option.HelpText = e.Option.HelpText;
730+
}
722731

723732
if (!string.IsNullOrEmpty(option.HelpText))
724733
{

0 commit comments

Comments
 (0)