Skip to content

Commit e175eb3

Browse files
committed
Reduced mutability of ParserSettings instance.
1 parent 0958edd commit e175eb3

9 files changed

Lines changed: 175 additions & 151 deletions

File tree

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.69.1 rc2 for CLR.
1+
Command Line Parser Library 1.9.69.3 rc2 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.__

doc/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2013-02-26 Giacomo Stelluti Scala <[email protected]>
2+
3+
* Reduced mutability of ParserSettings, instance can be used once.
4+
15
2013-02-25 Giacomo Stelluti Scala <[email protected]>
26

37
* Reverted same StyleCop default (see doc/Contribution).

doc/INFO

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ 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.62.15 rc1 (*1)
7-
Latest Update: 2013-02-25
86

97
Git home:
108
https://github.com/gsscoder/commandline

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.69.1")]
32-
[assembly: AssemblyFileVersion("1.9.69.1")]
31+
[assembly: AssemblyVersion("1.9.69.3")]
32+
[assembly: AssemblyFileVersion("1.9.69.3")]
3333

3434
[assembly: AssemblyInformationalVersion("1.9.62-rc2")]
3535
[assembly: NeutralResourcesLanguage("en-US")]

src/libcmdline/CommandLine.csproj

Lines changed: 138 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,145 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
3-
<PropertyGroup>
4-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6-
<ProductVersion>9.0.30729</ProductVersion>
7-
<SchemaVersion>2.0</SchemaVersion>
8-
<ProjectGuid>{5DEA2811-2FFA-4959-830B-CAD3ACACABEB}</ProjectGuid>
9-
<OutputType>Library</OutputType>
10-
<AppDesignerFolder>Properties</AppDesignerFolder>
11-
<RootNamespace>CommandLine</RootNamespace>
12-
<AssemblyName>CommandLine</AssemblyName>
13-
<FileUpgradeFlags>
14-
</FileUpgradeFlags>
15-
<OldToolsVersion>3.5</OldToolsVersion>
16-
<UpgradeBackupLocation>
17-
</UpgradeBackupLocation>
18-
<IsWebBootstrapper>false</IsWebBootstrapper>
19-
<PublishUrl>publish\</PublishUrl>
20-
<Install>true</Install>
21-
<InstallFrom>Disk</InstallFrom>
22-
<UpdateEnabled>false</UpdateEnabled>
23-
<UpdateMode>Foreground</UpdateMode>
24-
<UpdateInterval>7</UpdateInterval>
25-
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
26-
<UpdatePeriodically>false</UpdatePeriodically>
27-
<UpdateRequired>false</UpdateRequired>
28-
<MapFileExtensions>true</MapFileExtensions>
29-
<ApplicationRevision>0</ApplicationRevision>
30-
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
31-
<UseApplicationTrust>false</UseApplicationTrust>
32-
<BootstrapperEnabled>true</BootstrapperEnabled>
33-
</PropertyGroup>
34-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
35-
<DebugSymbols>true</DebugSymbols>
36-
<DebugType>full</DebugType>
37-
<Optimize>false</Optimize>
38-
<OutputPath>bin\Debug\</OutputPath>
39-
<DefineConstants>TRACE;DEBUG</DefineConstants>
40-
<ErrorReport>prompt</ErrorReport>
41-
<WarningLevel>4</WarningLevel>
42-
<DocumentationFile>bin\Debug\CommandLine.XML</DocumentationFile>
43-
</PropertyGroup>
44-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
45-
<DebugType>pdbonly</DebugType>
46-
<Optimize>true</Optimize>
47-
<OutputPath>bin\Release\</OutputPath>
48-
<DefineConstants>
49-
</DefineConstants>
50-
<ErrorReport>prompt</ErrorReport>
51-
<WarningLevel>4</WarningLevel>
52-
<DocumentationFile>bin\Release\CommandLine.XML</DocumentationFile>
53-
<GenerateDocumentation>true</GenerateDocumentation>
54-
</PropertyGroup>
55-
<PropertyGroup>
56-
<SignAssembly>true</SignAssembly>
57-
</PropertyGroup>
58-
<PropertyGroup>
59-
<AssemblyOriginatorKeyFile>CommandLine.snk</AssemblyOriginatorKeyFile>
60-
</PropertyGroup>
61-
<ItemGroup>
62-
<Reference Include="System" />
63-
</ItemGroup>
64-
<ItemGroup>
65-
<Compile Include="..\SharedAssemblyInfo.cs">
66-
<Link>Properties\SharedAssemblyInfo.cs</Link>
67-
</Compile>
68-
<Compile Include="Attributes\BaseOptionAttribute.cs" />
69-
<Compile Include="Attributes\OptionAttribute.cs" />
70-
<Compile Include="Attributes\OptionArrayAttribute.cs" />
71-
<Compile Include="Attributes\HelpOptionAttribute.cs" />
72-
<Compile Include="Attributes\OptionListAttribute.cs" />
73-
<Compile Include="Attributes\ParserStateAttribute.cs" />
74-
<Compile Include="Attributes\ValueListAttribute.cs" />
75-
<Compile Include="Attributes\ValueOptionAttribute.cs" />
76-
<Compile Include="Extensions\CharExtensions.cs" />
77-
<Compile Include="GlobalSuppressions.cs" />
78-
<Compile Include="Infrastructure\PropertyWriter.cs" />
79-
<Compile Include="Infrastructure\SR.strings.cs">
80-
<AutoGen>True</AutoGen>
81-
<DesignTime>True</DesignTime>
82-
<DependentUpon>SR.tt</DependentUpon>
83-
</Compile>
84-
<Compile Include="Helpers\Assumes.cs" />
85-
<Compile Include="Helpers\ReflectionCache.cs" />
86-
<Compile Include="Extensions\StringExtensions.cs" />
87-
<Compile Include="Helpers\ReflectionUtil.cs" />
88-
<Compile Include="Helpers\Pair.cs" />
89-
<Compile Include="Infrastructure\ValueMapper.cs" />
90-
<Compile Include="Infrastructure\LongOptionParser.cs" />
91-
<Compile Include="Infrastructure\OptionGroupParser.cs" />
92-
<Compile Include="Infrastructure\OptionInfo.cs" />
93-
<Compile Include="Infrastructure\OptionMap.cs" />
94-
<Compile Include="Infrastructure\OneCharStringEnumerator.cs" />
95-
<Compile Include="Infrastructure\StringArrayEnumerator.cs" />
96-
<Compile Include="Infrastructure\ArgumentParser.cs" />
97-
<Compile Include="Infrastructure\IArgumentEnumerator.cs" />
98-
<Compile Include="Infrastructure\PresentParserState.cs" />
99-
<Compile Include="Properties\AssemblyInfo.cs" />
100-
<Compile Include="Text\HelpText.cs" />
101-
<Compile Include="Text\BaseSentenceBuilder.cs" />
102-
<Compile Include="Text\EnglishSentenceBuilder.cs" />
103-
<Compile Include="Text\CopyrightInfo.cs" />
104-
<Compile Include="Text\HeadingInfo.cs" />
105-
<Compile Include="Attributes\MultiLineTextAttribute.cs" />
106-
<Compile Include="Attributes\AssemblyLicenseAttribute.cs" />
107-
<Compile Include="Attributes\AssemblyUsageAttribute.cs" />
108-
<Compile Include="Text\FormatOptionHelpTextEventArgs.cs" />
109-
<Compile Include="Attributes\HelpVerbOptionAttribute.cs" />
110-
<Compile Include="Attributes\VerbOptionAttribute.cs" />
111-
<Compile Include="BadOptionInfo.cs" />
112-
<Compile Include="Parser.cs" />
113-
<Compile Include="ParserException.cs" />
114-
<Compile Include="ParserSettings.cs" />
115-
<Compile Include="IParserState.cs" />
116-
<Compile Include="ParserState.cs" />
117-
<Compile Include="ParsingError.cs" />
118-
<Compile Include="Extensions\ObjectExtensions.cs" />
119-
</ItemGroup>
120-
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>9.0.30729</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{5DEA2811-2FFA-4959-830B-CAD3ACACABEB}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>CommandLine</RootNamespace>
12+
<AssemblyName>CommandLine</AssemblyName>
13+
<FileUpgradeFlags>
14+
</FileUpgradeFlags>
15+
<OldToolsVersion>3.5</OldToolsVersion>
16+
<UpgradeBackupLocation>
17+
</UpgradeBackupLocation>
18+
<IsWebBootstrapper>false</IsWebBootstrapper>
19+
<PublishUrl>publish\</PublishUrl>
20+
<Install>true</Install>
21+
<InstallFrom>Disk</InstallFrom>
22+
<UpdateEnabled>false</UpdateEnabled>
23+
<UpdateMode>Foreground</UpdateMode>
24+
<UpdateInterval>7</UpdateInterval>
25+
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
26+
<UpdatePeriodically>false</UpdatePeriodically>
27+
<UpdateRequired>false</UpdateRequired>
28+
<MapFileExtensions>true</MapFileExtensions>
29+
<ApplicationRevision>0</ApplicationRevision>
30+
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
31+
<UseApplicationTrust>false</UseApplicationTrust>
32+
<BootstrapperEnabled>true</BootstrapperEnabled>
33+
</PropertyGroup>
34+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
35+
<DebugSymbols>true</DebugSymbols>
36+
<DebugType>full</DebugType>
37+
<Optimize>false</Optimize>
38+
<OutputPath>bin\Debug\</OutputPath>
39+
<DefineConstants>TRACE;DEBUG</DefineConstants>
40+
<ErrorReport>prompt</ErrorReport>
41+
<WarningLevel>4</WarningLevel>
42+
<DocumentationFile>bin\Debug\CommandLine.XML</DocumentationFile>
43+
</PropertyGroup>
44+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
45+
<DebugType>pdbonly</DebugType>
46+
<Optimize>true</Optimize>
47+
<OutputPath>bin\Release\</OutputPath>
48+
<DefineConstants>
49+
</DefineConstants>
50+
<ErrorReport>prompt</ErrorReport>
51+
<WarningLevel>4</WarningLevel>
52+
<DocumentationFile>bin\Release\CommandLine.XML</DocumentationFile>
53+
<GenerateDocumentation>true</GenerateDocumentation>
54+
</PropertyGroup>
55+
<PropertyGroup>
56+
<SignAssembly>true</SignAssembly>
57+
</PropertyGroup>
58+
<PropertyGroup>
59+
<AssemblyOriginatorKeyFile>CommandLine.snk</AssemblyOriginatorKeyFile>
60+
</PropertyGroup>
61+
<ItemGroup>
62+
<Reference Include="System" />
63+
</ItemGroup>
64+
<ItemGroup>
65+
<Compile Include="..\SharedAssemblyInfo.cs">
66+
<Link>Properties\SharedAssemblyInfo.cs</Link>
67+
</Compile>
68+
<Compile Include="Attributes\BaseOptionAttribute.cs" />
69+
<Compile Include="Attributes\OptionAttribute.cs" />
70+
<Compile Include="Attributes\OptionArrayAttribute.cs" />
71+
<Compile Include="Attributes\HelpOptionAttribute.cs" />
72+
<Compile Include="Attributes\OptionListAttribute.cs" />
73+
<Compile Include="Attributes\ParserStateAttribute.cs" />
74+
<Compile Include="Attributes\ValueListAttribute.cs" />
75+
<Compile Include="Attributes\ValueOptionAttribute.cs" />
76+
<Compile Include="Extensions\CharExtensions.cs" />
77+
<Compile Include="GlobalSuppressions.cs" />
78+
<Compile Include="Infrastructure\PropertyWriter.cs" />
79+
<Compile Include="Infrastructure\SR.strings.cs">
80+
<AutoGen>True</AutoGen>
81+
<DesignTime>True</DesignTime>
82+
<DependentUpon>SR.tt</DependentUpon>
83+
</Compile>
84+
<Compile Include="Helpers\Assumes.cs" />
85+
<Compile Include="Helpers\ReflectionCache.cs" />
86+
<Compile Include="Extensions\StringExtensions.cs" />
87+
<Compile Include="Helpers\ReflectionUtil.cs" />
88+
<Compile Include="Helpers\Pair.cs" />
89+
<Compile Include="Infrastructure\ValueMapper.cs" />
90+
<Compile Include="Infrastructure\LongOptionParser.cs" />
91+
<Compile Include="Infrastructure\OptionGroupParser.cs" />
92+
<Compile Include="Infrastructure\OptionInfo.cs" />
93+
<Compile Include="Infrastructure\OptionMap.cs" />
94+
<Compile Include="Infrastructure\OneCharStringEnumerator.cs" />
95+
<Compile Include="Infrastructure\StringArrayEnumerator.cs" />
96+
<Compile Include="Infrastructure\ArgumentParser.cs" />
97+
<Compile Include="Infrastructure\IArgumentEnumerator.cs" />
98+
<Compile Include="Infrastructure\PresentParserState.cs" />
99+
<Compile Include="Properties\AssemblyInfo.cs" />
100+
<Compile Include="Text\HelpText.cs" />
101+
<Compile Include="Text\BaseSentenceBuilder.cs" />
102+
<Compile Include="Text\EnglishSentenceBuilder.cs" />
103+
<Compile Include="Text\CopyrightInfo.cs" />
104+
<Compile Include="Text\HeadingInfo.cs" />
105+
<Compile Include="Attributes\MultiLineTextAttribute.cs" />
106+
<Compile Include="Attributes\AssemblyLicenseAttribute.cs" />
107+
<Compile Include="Attributes\AssemblyUsageAttribute.cs" />
108+
<Compile Include="Text\FormatOptionHelpTextEventArgs.cs" />
109+
<Compile Include="Attributes\HelpVerbOptionAttribute.cs" />
110+
<Compile Include="Attributes\VerbOptionAttribute.cs" />
111+
<Compile Include="BadOptionInfo.cs" />
112+
<Compile Include="Parser.cs" />
113+
<Compile Include="ParserException.cs" />
114+
<Compile Include="ParserSettings.cs" />
115+
<Compile Include="IParserState.cs" />
116+
<Compile Include="ParserState.cs" />
117+
<Compile Include="ParsingError.cs" />
118+
<Compile Include="Extensions\ObjectExtensions.cs" />
119+
</ItemGroup>
120+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
121121
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
122122
Other similar extension points exist, see Microsoft.Common.targets.
123123
<Target Name="BeforeBuild">
124124
</Target>
125125
<Target Name="AfterBuild">
126126
</Target>
127-
-->
128-
<ItemGroup>
129-
<None Include="CommandLine.snk" />
130-
<None Include="Infrastructure\SR.tt">
131-
<Generator>TextTemplatingFileGenerator</Generator>
132-
<LastGenOutput>SR.strings.cs</LastGenOutput>
133-
</None>
134-
</ItemGroup>
135-
<ItemGroup>
136-
<CodeAnalysisDictionary Include="CustomDictionary.xml" />
137-
</ItemGroup>
138-
<ItemGroup>
139-
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
140-
</ItemGroup>
141-
<PropertyGroup>
142-
<PreBuildEvent>
143-
</PreBuildEvent>
144-
</PropertyGroup>
127+
-->
128+
<ItemGroup>
129+
<None Include="CommandLine.snk" />
130+
<None Include="Infrastructure\SR.tt">
131+
<Generator>TextTemplatingFileGenerator</Generator>
132+
<LastGenOutput>SR.strings.cs</LastGenOutput>
133+
</None>
134+
</ItemGroup>
135+
<ItemGroup>
136+
<CodeAnalysisDictionary Include="CustomDictionary.xml" />
137+
</ItemGroup>
138+
<ItemGroup>
139+
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
140+
</ItemGroup>
141+
<PropertyGroup>
142+
<PreBuildEvent>
143+
</PreBuildEvent>
144+
</PropertyGroup>
145145
</Project>

src/libcmdline/Parser.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public sealed class Parser : IDisposable
5555
/// </summary>
5656
public Parser()
5757
{
58-
_settings = new ParserSettings();
58+
_settings = new ParserSettings { Consumed = true };
5959
}
6060

6161
/// <summary>
@@ -68,22 +68,29 @@ public Parser()
6868
public Parser(ParserSettings settings)
6969
{
7070
Assumes.NotNull(settings, "settings", SR.ArgumentNullException_CommandLineParserSettingsInstanceCannotBeNull);
71+
72+
if (settings.Consumed)
73+
{
74+
throw new InvalidOperationException("ParserSettings instance cannnot be used more than once.");
75+
}
7176

7277
_settings = settings;
78+
_settings.Consumed = true;
7379
}
7480

7581
/// <summary>
7682
/// Initializes a new instance of the <see cref="Parser"/> class,
7783
/// configurable with <see cref="ParserSettings"/> using a delegate.
7884
/// </summary>
79-
/// <param name="settings">The <see cref="Action&lt;ParserSettings&gt;"/> object used to configure
85+
/// <param name="configuration">The <see cref="Action&lt;ParserSettings&gt;"/> delegate used to configure
8086
/// aspects and behaviors of the parser.</param>
81-
public Parser(Action<ParserSettings> settings)
82-
: this()
87+
public Parser(Action<ParserSettings> configuration)
8388
{
84-
Assumes.NotNull(settings, "settings", SR.ArgumentNullException_CommandLineParserSettingsDelegateCannotBeNull);
89+
Assumes.NotNull(configuration, "configuration", SR.ArgumentNullException_CommandLineParserSettingsDelegateCannotBeNull);
8590

86-
settings.Invoke(_settings);
91+
_settings = new ParserSettings();
92+
configuration.Invoke(Settings);
93+
_settings.Consumed = true;
8794
}
8895

8996
[SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "singleton", Justification = "The constructor that accepts a boolean is designed to support default singleton, the parameter is ignored")]

src/libcmdline/ParserSettings.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ namespace CommandLine
3636
public sealed class ParserSettings
3737
{
3838
private const bool CaseSensitiveDefault = true;
39-
4039
private bool _disposed;
4140

4241
/// <summary>
@@ -130,6 +129,8 @@ public ParserSettings(bool caseSensitive, bool mutuallyExclusive, bool ignoreUnk
130129
Dispose(false);
131130
}
132131

132+
internal bool Consumed { get; set; }
133+
133134
/// <summary>
134135
/// Gets or sets a value indicating whether perform case sensitive comparisons.
135136
/// </summary>

0 commit comments

Comments
 (0)