Skip to content

Commit 2aa31c5

Browse files
committed
CommandLineParser refactored using ParserContext, TargetExtensions.
1 parent df983ba commit 2aa31c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+448
-396
lines changed

CommandLine.FxCop

+28-77
Original file line numberDiff line numberDiff line change
@@ -94,69 +94,8 @@
9494
</Namespace>
9595
<Namespace Name="CommandLine.Internal">
9696
<Types>
97-
<Type Name="Assumes">
98-
<Members>
99-
<Member Name="#NotNullOrEmpty(System.String,System.String,System.String)">
100-
<Messages>
101-
<Message TypeName="AvoidUncalledPrivateCode" Category="Microsoft.Performance" CheckId="CA1811" Created="2013-01-20 13:57:34Z">
102-
<Issue>
103-
<Item>'Assumes.NotNullOrEmpty(string, string, string)'</Item>
104-
</Issue>
105-
</Message>
106-
</Messages>
107-
</Member>
108-
<Member Name="#NotZeroLength`1(!!0[],System.String,System.String)">
109-
<Messages>
110-
<Message TypeName="AvoidUncalledPrivateCode" Category="Microsoft.Performance" CheckId="CA1811" Created="2013-01-20 13:57:34Z">
111-
<Issue>
112-
<Item>'Assumes.NotZeroLength&lt;T&gt;(T[], string, string)'</Item>
113-
</Issue>
114-
</Message>
115-
</Messages>
116-
</Member>
117-
</Members>
118-
</Type>
119-
<Type Name="OneCharStringEnumerator">
120-
<Members>
121-
<Member Name="#Reset()">
122-
<Messages>
123-
<Message TypeName="AvoidUncalledPrivateCode" Category="Microsoft.Performance" CheckId="CA1811" Created="2013-01-20 13:57:34Z">
124-
<Issue>
125-
<Item>'OneCharStringEnumerator.Reset()'</Item>
126-
</Issue>
127-
</Message>
128-
</Messages>
129-
</Member>
130-
</Members>
131-
</Type>
13297
<Type Name="OptionInfo">
13398
<Members>
134-
<Member Name="#HelpText">
135-
<Accessors>
136-
<Accessor Name="#get_HelpText()">
137-
<Messages>
138-
<Message TypeName="AvoidUncalledPrivateCode" Category="Microsoft.Performance" CheckId="CA1811" Created="2013-01-20 13:57:34Z">
139-
<Issue>
140-
<Item>'OptionInfo.HelpText.get()'</Item>
141-
</Issue>
142-
</Message>
143-
</Messages>
144-
</Accessor>
145-
</Accessors>
146-
</Member>
147-
<Member Name="#NameWithSwitch">
148-
<Accessors>
149-
<Accessor Name="#get_NameWithSwitch()">
150-
<Messages>
151-
<Message TypeName="AvoidUncalledPrivateCode" Category="Microsoft.Performance" CheckId="CA1811" Created="2013-01-20 13:57:34Z">
152-
<Issue>
153-
<Item>'OptionInfo.NameWithSwitch.get()'</Item>
154-
</Issue>
155-
</Message>
156-
</Messages>
157-
</Accessor>
158-
</Accessors>
159-
</Member>
16099
<Member Name="#SetNullableValue(System.String,System.Object)">
161100
<Messages>
162101
<Message TypeName="DoNotCatchGeneralExceptionTypes" Category="Microsoft.Design" CheckId="CA1031" Status="Excluded" Created="2013-01-20 13:57:34Z">
@@ -174,19 +113,6 @@
174113
</Member>
175114
</Members>
176115
</Type>
177-
<Type Name="StringArrayEnumerator">
178-
<Members>
179-
<Member Name="#Reset()">
180-
<Messages>
181-
<Message TypeName="AvoidUncalledPrivateCode" Category="Microsoft.Performance" CheckId="CA1811" Created="2013-01-20 13:57:34Z">
182-
<Issue>
183-
<Item>'StringArrayEnumerator.Reset()'</Item>
184-
</Issue>
185-
</Message>
186-
</Messages>
187-
</Member>
188-
</Members>
189-
</Type>
190116
</Types>
191117
</Namespace>
192118
<Namespace Name="CommandLine.Text">
@@ -221,6 +147,29 @@
221147
</Type>
222148
</Types>
223149
</Namespace>
150+
<Namespace Name="CommandLine.Utils">
151+
<Types>
152+
<Type Name="ReflectionCache">
153+
<Members>
154+
<Member Name="#.cctor()">
155+
<Messages>
156+
<Message TypeName="InitializeReferenceTypeStaticFieldsInline" Category="Microsoft.Performance" CheckId="CA1810" Status="Excluded" Created="2013-01-24 13:11:50Z">
157+
<Issue>
158+
<Item>'ReflectionCache'</Item>
159+
</Issue>
160+
<Notes>
161+
<User Name="vmuser">
162+
<Note Id="3" />
163+
<Note Id="4" />
164+
</User>
165+
</Notes>
166+
</Message>
167+
</Messages>
168+
</Member>
169+
</Members>
170+
</Type>
171+
</Types>
172+
</Namespace>
224173
</Namespaces>
225174
</Module>
226175
</Modules>
@@ -231,15 +180,14 @@
231180
<Note Id="0" Modified="2013-01-20 14:49:13Z">The char Separator property matches shortName char constructor argument because the ShortName property is defined in BaseOptionAttribute as nullable char.</Note>
232181
<Note Id="1" Modified="2013-01-20 16:14:59Z">FormatException (thrown by ConvertFromString) is thrown as Exception.InnerException, so we've to catch directly System.Exception.</Note>
233182
<Note Id="2" Modified="2013-01-22 20:28:56Z">The constructor that accepts a boolean is designed to support default singleton, the parameter is ignored.</Note>
183+
<Note Id="3" Modified="2013-01-24 13:17:29Z">Singleton, by design.</Note>
184+
<Note Id="4" Modified="2013-01-24 13:22:57Z">Singleton, by design.</Note>
234185
</User>
235186
</Notes>
236187
<Rules>
237188
<Rule TypeName="AvoidOutParameters" Category="Microsoft.Design" CheckId="CA1021">
238189
<Resolution Name="Default">Consider a design that does not require that {0} be an out parameter.</Resolution>
239190
</Rule>
240-
<Rule TypeName="AvoidUncalledPrivateCode" Category="Microsoft.Performance" CheckId="CA1811">
241-
<Resolution Name="Default">{0} appears to have no upstream public or protected callers.</Resolution>
242-
</Rule>
243191
<Rule TypeName="DefineAccessorsForAttributeArguments" Category="Microsoft.Design" CheckId="CA1019">
244192
<Resolution Name="RemoveSetter">Remove the property setter from {0} or reduce its accessibility because it corresponds to positional argument {1}.</Resolution>
245193
</Rule>
@@ -249,6 +197,9 @@
249197
<Rule TypeName="DoNotCatchGeneralExceptionTypes" Category="Microsoft.Design" CheckId="CA1031">
250198
<Resolution Name="Default">Modify {0} to catch a more specific exception than {1} or rethrow the exception.</Resolution>
251199
</Rule>
200+
<Rule TypeName="InitializeReferenceTypeStaticFieldsInline" Category="Microsoft.Performance" CheckId="CA1810">
201+
<Resolution Name="Default">Initialize all static fields in {0} when those fields are declared and remove the explicit static constructor.</Resolution>
202+
</Rule>
252203
<Rule TypeName="ReviewUnusedParameters" Category="Microsoft.Usage" CheckId="CA1801">
253204
<Resolution Name="Default">Parameter {0} of {1} is never used. Remove the parameter or use it in the method body.</Resolution>
254205
</Rule>

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Command Line Parser Library 1.9.4.131 Beta for CLR.
1+
Command Line Parser Library 1.9.4.139 beta 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
__The search for the command line parser for your application is over, with this library you got a solid parsing API constantly updated since 2005.__
@@ -11,6 +11,7 @@ Compatibility:
1111

1212
News:
1313
---
14+
- ``CommandLineParser`` refactored (also using new ``ParserContext`` type).
1415
- ``ReflectionUtil`` now caches data using ``ReflectionCache``.
1516
- Added ``strings`` task to Rakefile used to regenerate ``SR.strings.cs``.
1617
- Internal refactoring on ``OptionMap`` and ``OptionInfo``.

Rakefile.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PRODUCT = "Command Line Parser Library"
22
DESCRIPTION = "Command Line Parser Library allows CLR applications to define a syntax for parsing command line arguments."
33
INF_VERSION = "1.9"
4-
VERSION = INF_VERSION + ".4.131"
4+
VERSION = INF_VERSION + ".4.139"
55
COPYRIGHT = "Copyright (c) 2005 - 2013 Giacomo Stelluti Scala"
66
LICENSE_URL = "https://raw.github.com/gsscoder/commandline/master/doc/LICENSE"
77
PROJECT_URL = "https://github.com/gsscoder/commandline"

doc/ChangeLog

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2013-01-24 Giacomo Stelluti Scala <[email protected]>
2+
3+
* Sources in Utils dir moved to CommandLine.Utils namespace.
4+
* Added type TargetExtensions to increase readability/reuse of code (now with ReflectionCache we can
5+
query target instance without fear of performance loss).
6+
* CommandLineParser refactored (also using new ParserContext type).
7+
* Removed uncalled private code where detected by FxCop (CA1811).
8+
* Minor generalized refactoring.
9+
* Version incremented to 1.9.4.139 beta.
10+
111
2013-01-24 Giacomo Stelluti Scala <[email protected]>
212

313
* src/CommonAssemblyInfo.cs generated with Rakefile.rb.

doc/README

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Command Line Parser Library
33
Project Author/Coordinator: Giacomo Stelluti Scala
44
Main Contributor(s): Steven Evans, Kevin Moore, Dan Nemec (nemec), Alexander Fast (mizipzor)
55
--------------------------------------------------------------------------------------------
6-
Version 1.9.4.131 Beta (*1)
7-
Latest Update: 23-01-2013
6+
Version 1.9.4.139 beta (*1)
7+
Latest Update: 24-01-2013
88

99
Git home:
1010
https://github.com/gsscoder/commandline
@@ -20,7 +20,11 @@ More info on:
2020
[QUICKSTART] http://commandline.codeplex.com/wikipage?title=Quickstart&referringTitle=Documentation
2121
[GUIDE] http://commandline.codeplex.com/documentation (*2)
2222
[BLOG] http://gsscoder.blogspot.com/
23-
23+
24+
Artifact regeneration:
25+
rake strings -> src/libcmdline/Internal/SR.string.cs
26+
rake assemblyinfo -> src/CommonAssemblyInfo.cs
27+
2428
Build (requires Ruby):
2529
gem install rake
2630
gem install albacore

src/demo/CommandLine.Demo.csproj

+6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
<Compile Include="..\libcmdline\Internal\Target.cs">
4141
<Link>Library\Internal\Target.cs</Link>
4242
</Compile>
43+
<Compile Include="..\libcmdline\ParserContext.cs">
44+
<Link>Library\ParserContext.cs</Link>
45+
</Compile>
4346
<Compile Include="..\libcmdline\ParserState.cs">
4447
<Link>Library\ParserState.cs</Link>
4548
</Compile>
@@ -73,6 +76,9 @@
7376
<Compile Include="..\libcmdline\Utils\SwitchExtensions.cs">
7477
<Link>Library\Utils\SwitchExtensions.cs</Link>
7578
</Compile>
79+
<Compile Include="..\libcmdline\Utils\TargetExtensions.cs">
80+
<Link>Library\Utils\TargetExtensions.cs</Link>
81+
</Compile>
7682
<Compile Include="Program.cs" />
7783
<Compile Include="Properties\AssemblyInfo.cs" />
7884
<Compile Include="..\libcmdline\Internal\ArgumentParser.cs">

src/libcmdline/Attributes/BaseOptionAttribute.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
#endregion
2929
#region Using Directives
3030
using System;
31-
using System.Diagnostics;
3231
using CommandLine.Internal;
32+
using CommandLine.Utils;
3333
#endregion
3434

3535
namespace CommandLine
@@ -41,6 +41,12 @@ public abstract class BaseOptionAttribute : Attribute
4141
{
4242
internal const string DefaultMutuallyExclusiveSet = "Default";
4343

44+
/// <summary>
45+
/// Create an instance of <see cref="BaseOptionAttribute"/> derived class, validating <paramref name="shortName"/>
46+
/// and <paramref name="longName"/>.
47+
/// </summary>
48+
/// <param name="shortName">Short name of the option.</param>
49+
/// <param name="longName">Long name of the option.</param>
4450
protected BaseOptionAttribute(char shortName, string longName)
4551
{
4652
_shortName = shortName;
@@ -52,6 +58,12 @@ protected BaseOptionAttribute(char shortName, string longName)
5258
LongName = longName;
5359
}
5460

61+
/// <summary>
62+
/// Create an instance of <see cref="BaseOptionAttribute"/> derived class, validating <paramref name="shortName"/>
63+
/// and <paramref name="longName"/>. This constructor accepts a nullable character as short name.
64+
/// </summary>
65+
/// <param name="shortName">Short name of the option.</param>
66+
/// <param name="longName">Long name of the option.</param>
5567
protected BaseOptionAttribute(char? shortName, string longName)
5668
{
5769
_shortName = shortName;

src/libcmdline/Attributes/HelpOptionAttribute.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#region Using Directives
3030
using System;
3131
using System.Reflection;
32-
using CommandLine.Internal;
32+
using CommandLine.Utils;
3333
#endregion
3434

3535
namespace CommandLine

src/libcmdline/Attributes/HelpVerbOptionAttribute.cs

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
using System;
3131
using System.Reflection;
3232
using CommandLine.Internal;
33+
using CommandLine.Utils;
34+
3335
#endregion
3436

3537
namespace CommandLine

src/libcmdline/Attributes/ValueListAttribute.cs

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
using System.Collections.Generic;
3232
using System.Reflection;
3333
using CommandLine.Internal;
34+
using CommandLine.Utils;
35+
3436
#endregion
3537

3638
namespace CommandLine
@@ -73,6 +75,9 @@ public ValueListAttribute(Type concreteType)
7375
/// </summary>
7476
public int MaximumElements { get; set; }
7577

78+
/// <summary>
79+
/// Gets the concrete type specified during initialization.
80+
/// </summary>
7681
public Type ConcreteType { get { return _concreteType; } }
7782

7883
internal static IList<string> GetReference(object target)

src/libcmdline/Attributes/VerbOptionAttribute.cs

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#region Using Directives
3030
using System;
3131
using CommandLine.Internal;
32+
using CommandLine.Utils;
33+
3234
#endregion
3335

3436
namespace CommandLine

src/libcmdline/BadOptionInfo.cs

-11
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,6 @@
2626
// THE SOFTWARE.
2727
//
2828
#endregion
29-
#region Using Directives
30-
using System;
31-
using System.Collections.Generic;
32-
using System.ComponentModel;
33-
using System.Diagnostics;
34-
using System.IO;
35-
using System.Reflection;
36-
using System.Runtime.Serialization;
37-
using System.Threading;
38-
using CommandLine.Internal;
39-
#endregion
4029

4130
namespace CommandLine
4231
{

src/libcmdline/CommandLine.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
<Compile Include="Attributes\OptionListAttribute.cs" />
8080
<Compile Include="Attributes\ParserStateAttribute.cs" />
8181
<Compile Include="Attributes\ValueListAttribute.cs" />
82+
<Compile Include="ParserContext.cs" />
8283
<Compile Include="Utils\Assumes.cs" />
8384
<Compile Include="Internal\SR.strings.cs">
8485
<DependentUpon>SR.strings</DependentUpon>
@@ -122,6 +123,7 @@
122123
<Compile Include="..\CommonAssemblyInfo.cs">
123124
<Link>Properties\CommonAssemblyInfo.cs</Link>
124125
</Compile>
126+
<Compile Include="Utils\TargetExtensions.cs" />
125127
</ItemGroup>
126128
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
127129
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

src/libcmdline/CommandLine.csproj.DotSettings

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=Attributes/@EntryIndexedValue">True</s:Boolean>
33
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=Core/@EntryIndexedValue">True</s:Boolean>
44
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=Text_005CAttributes/@EntryIndexedValue">True</s:Boolean>
5-
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=Utils/@EntryIndexedValue">True</s:Boolean>
5+
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=Utils/@EntryIndexedValue">False</s:Boolean>
66
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=Verbs/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

0 commit comments

Comments
 (0)