Skip to content

Commit c04643b

Browse files
committed
Refactoring on OptionInfo, OptionMap. Added SwitchExtensions.
1 parent df07e71 commit c04643b

19 files changed

+186
-170
lines changed

CommandLine.sln

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommandLine.Tests", "src\te
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommandLine.Demo", "src\demo\CommandLine.Demo.csproj", "{9E573FFF-4ECB-4C59-A914-C0B74D44D2E8}"
99
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Files", "Files", "{4F498B61-A7BC-4B32-9ACB-901D4F50659B}"
11+
ProjectSection(SolutionItems) = preProject
12+
CommandLine.FxCop = CommandLine.FxCop
13+
Rakefile.rb = Rakefile.rb
14+
EndProjectSection
15+
EndProject
16+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NuGet", "NuGet", "{CC062800-4709-4A04-8A0D-DD972C1BFFC5}"
17+
ProjectSection(SolutionItems) = preProject
18+
nuget\CommandLine.nuspec = nuget\CommandLine.nuspec
19+
nuget\readme.txt = nuget\readme.txt
20+
EndProjectSection
21+
EndProject
22+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{18282A82-E36C-4938-8397-C0A1166983BA}"
23+
ProjectSection(SolutionItems) = preProject
24+
doc\ChangeLog = doc\ChangeLog
25+
doc\LICENSE = doc\LICENSE
26+
README.md = README.md
27+
EndProjectSection
28+
EndProject
1029
Global
1130
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1231
Debug|Any CPU = Debug|Any CPU
@@ -50,6 +69,10 @@ Global
5069
GlobalSection(SolutionProperties) = preSolution
5170
HideSolutionNode = FALSE
5271
EndGlobalSection
72+
GlobalSection(NestedProjects) = preSolution
73+
{CC062800-4709-4A04-8A0D-DD972C1BFFC5} = {4F498B61-A7BC-4B32-9ACB-901D4F50659B}
74+
{18282A82-E36C-4938-8397-C0A1166983BA} = {4F498B61-A7BC-4B32-9ACB-901D4F50659B}
75+
EndGlobalSection
5376
GlobalSection(MonoDevelopProperties) = preSolution
5477
StartupItem = src\demo\CommandLine.Demo.csproj
5578
Policies = $0

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Command Line Parser Library 1.9.4.123 Beta for CLR.
1+
Command Line Parser Library 1.9.4.125 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,8 @@ Compatibility:
1111

1212
News:
1313
---
14+
- Added ``strings`` task to Rakefile used to regenerate ``SR.strings.cs``.
15+
- Internal refactoring on ``OptionMap`` and ``OptionInfo``.
1416
- Refactoring in respect of FxCop rules (see ChangeLog). ``HandleParsingErrorsDelegate`` renamed to ``ParsingErrorsHandler``, ``MultiLineTextAttribute`` renamed to ``MultilineTextAttribute``.
1517
- Removed synchronization from ``OptionInfo`` and ``TargetWrapper`` (parsing should occur in one thread;
1618
if not, synchronization must be provided by developer not by the library).
@@ -21,12 +23,6 @@ News:
2123
- ``CommandLineParserSettings``, ``CommandLineParser`` are now correctly disposable.
2224
- Merged pull request #44 from @dbaileychess (Derek Bailey) that adds ``BaseOptionAttribute::MetaKey`` similar to python [argparse](http://docs.python.org/2/library/argparse.html#module-argparse).
2325
- Implemented [strict parsing](https://github.com/gsscoder/commandline/blob/master/src/tests/Parser/StrictFixture.cs) (see issue #32 by @nemec).
24-
- Removed recently added ``#define`` directives.
25-
- Removed dependency from ``CommandLineOptionsBase``; use ``ParserStateAttributed`` and ``IParserState``.
26-
- Short name of ordinary options is now defined as character.
27-
- Introduced support for verb commands (e.g. ``app verb1 --ordinary-option``).
28-
- Internal refactoring and code reorganization for better maintainability.
29-
- No member with public visibility was left without XML comments.
3026

3127
To build:
3228
---

Rakefile.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PRODUCT = "Command Line Parser Library"
22
DESCRIPTION = "Command Line Parser Library allows CLR applications to define a syntax for parsing command line arguments."
3-
VERSION = "1.9.4.119"
3+
VERSION = "1.9.4.125"
44
COPYRIGHT = "Copyright (c) 2005 - 2013 Giacomo Stelluti Scala"
55
LICENSE_URL = "https://raw.github.com/gsscoder/commandline/master/doc/LICENSE"
66
PROJECT_URL = "https://github.com/gsscoder/commandline"
@@ -36,6 +36,8 @@ def invoke_runtime(cmd)
3636
BUILD_DIR = File.expand_path("build")
3737
OUTPUT_DIR = "#{BUILD_DIR}/out"
3838
BIN_DIR = "#{BUILD_DIR}/bin"
39+
SOURCE_DIR = File.expand_path("src")
40+
LIB_DIR = "#{SOURCE_DIR}/libcmdline"
3941

4042
msbuild :build_msbuild do |b|
4143
b.properties :configuration => CONFIGURATION, "OutputPath" => OUTPUT_DIR
@@ -59,6 +61,11 @@ def invoke_runtime(cmd)
5961
sh "#{nunit} -labels #{OUTPUT_DIR}/CommandLine.Tests.dll"
6062
end
6163

64+
task :strings do
65+
invstrtool = invoke_runtime("tools/invariantstr.exe")
66+
sh "#{invstrtool} -i #{LIB_DIR}/Internal/SR.strings -n CommandLine.Internal"
67+
end
68+
6269
task :clean do
6370
FileUtils.rm_rf BUILD_DIR
6471
FileUtils.rm_rf "src/libcmdline/bin"

doc/ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2013-01-22 Giacomo Stelluti Scala <gsscoder@gmail.com>
2+
3+
* Added solution folder "Files" to CommandLine.sln.
4+
* OptionMap constructor is now private. Instance is now created by two factory methods '::Create()'
5+
derived by 'OptionInfo::CreateMap()'.
6+
* OptionInfo.verbs.cs merged with OptionInfo.cs
7+
* Added rake task 'strings' to regenerate SR.string.cs from SR.string.
8+
* Version incremented to 1.9.4.125 Beta.
9+
110
2013-01-22 Giacomo Stelluti Scala <gsscoder@gmail.com>
211

312
* CommandLine.snk regenerated, the current prevented the build process.

doc/README

Lines changed: 2 additions & 2 deletions
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.123 Beta (*1)
7-
Latest Update: 20-01-2013
6+
Version 1.9.4.125 Beta (*1)
7+
Latest Update: 22-01-2013
88

99
Git home:
1010
https://github.com/gsscoder/commandline

src/demo/CommandLine.Demo.csproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
<Compile Include="..\libcmdline\Utils\StringExtensions.cs">
5656
<Link>Library\Utils\StringExtensions.cs</Link>
5757
</Compile>
58+
<Compile Include="..\libcmdline\Utils\SwitchExtensions.cs">
59+
<Link>Library\Utils\SwitchExtensions.cs</Link>
60+
</Compile>
5861
<Compile Include="Program.cs" />
5962
<Compile Include="Properties\AssemblyInfo.cs" />
6063
<Compile Include="Properties\ThisAssembly.cs" />
@@ -76,10 +79,6 @@
7679
<Compile Include="..\libcmdline\Internal\OptionInfo.cs">
7780
<Link>Library\Internal\OptionInfo.cs</Link>
7881
</Compile>
79-
<Compile Include="..\libcmdline\Internal\OptionInfo.Verbs.cs">
80-
<Link>Library\Internal\OptionInfo.Verbs.cs</Link>
81-
<DependentUpon>OptionInfo.cs</DependentUpon>
82-
</Compile>
8382
<Compile Include="..\libcmdline\Internal\OptionMap.cs">
8483
<Link>Library\Internal\OptionMap.cs</Link>
8584
</Compile>

src/libcmdline/CommandLine.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,14 @@
8383
<Compile Include="Internal\SR.strings.cs">
8484
<DependentUpon>SR.strings</DependentUpon>
8585
</Compile>
86+
<Compile Include="Utils\SwitchExtensions.cs" />
8687
<Compile Include="Utils\StringExtensions.cs" />
8788
<Compile Include="Internal\ReflectionUtil.cs" />
8889
<Compile Include="Utils\Pair.cs" />
8990
<Compile Include="Internal\TargetWrapper.cs" />
9091
<Compile Include="Internal\LongOptionParser.cs" />
9192
<Compile Include="Internal\OptionGroupParser.cs" />
9293
<Compile Include="Internal\OptionInfo.cs" />
93-
<Compile Include="Internal\OptionInfo.Verbs.cs">
94-
<DependentUpon>OptionInfo.cs</DependentUpon>
95-
</Compile>
9694
<Compile Include="Internal\OptionMap.cs" />
9795
<Compile Include="Internal\OneCharStringEnumerator.cs" />
9896
<Compile Include="Internal\StringArrayEnumerator.cs" />

src/libcmdline/CommandLineParser.Verbs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private bool DoParseArgumentsUsingVerbs(string[] args, object options)
9494
}
9595
return false;
9696
}
97-
var optionMap = OptionInfo.CreateMap(options, verbs, _settings);
97+
var optionMap = OptionMap.Create(options, verbs, _settings);
9898
// Read the verb from command line arguments
9999
if (TryParseHelpVerb(args, options, helpInfo, optionMap))
100100
{

src/libcmdline/CommandLineParser.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ private bool DoParseArguments(string[] args, object options)
142142
private bool DoParseArgumentsCore(string[] args, object options)
143143
{
144144
bool hadError = false;
145-
var optionMap = OptionInfo.CreateMap(options, _settings);
145+
var optionMap = OptionMap.Create(options, _settings);
146146
optionMap.SetDefaults();
147147
var target = new TargetWrapper(options);
148148

@@ -152,7 +152,7 @@ private bool DoParseArgumentsCore(string[] args, object options)
152152
string argument = arguments.Current;
153153
if (!string.IsNullOrEmpty(argument))
154154
{
155-
ArgumentParser parser = ArgumentParser.Create(argument, _settings.IgnoreUnknownArguments);
155+
var parser = ArgumentParser.Create(argument, _settings.IgnoreUnknownArguments);
156156
if (parser != null)
157157
{
158158
Internal.ParserState result = parser.Parse(arguments, optionMap, options);
@@ -164,7 +164,9 @@ private bool DoParseArgumentsCore(string[] args, object options)
164164
}
165165

166166
if ((result & Internal.ParserState.MoveOnNextElement) == Internal.ParserState.MoveOnNextElement)
167+
{
167168
arguments.MoveNext();
169+
}
168170
}
169171
else if (target.IsValueListDefined)
170172
{

src/libcmdline/Internal/ArgumentParser.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ protected void DefineOptionThatViolatesFormat(OptionInfo option)
5959
public static ArgumentParser Create(string argument, bool ignoreUnknownArguments = false)
6060
{
6161
if (argument.IsNumeric()) { return null; }
62-
if (string.CompareOrdinal(argument, "-") == 0) { return null; }
63-
if (argument[0] == '-' && argument[1] == '-')
62+
if (argument.IsDash()) { return null; }
63+
if (argument.IsLongOption())
6464
{
6565
return new LongOptionParser(ignoreUnknownArguments);
6666
}
67-
if (argument[0] == '-')
67+
if (argument.IsShortOption())
6868
{
6969
return new OptionGroupParser(ignoreUnknownArguments);
7070
}
@@ -76,7 +76,7 @@ public static bool IsInputValue(string argument)
7676
if (argument.IsNumeric()) { return true; }
7777
if (argument.Length > 0)
7878
{
79-
return string.CompareOrdinal(argument, "-") == 0 || argument[0] != '-';
79+
return argument.IsDash() || !argument.IsShortOption();
8080
}
8181
return true;
8282
}
@@ -100,17 +100,13 @@ protected static IList<string> GetNextInputValues(IArgumentEnumerator ae)
100100

101101
public static bool CompareShort(string argument, char? option, bool caseSensitive)
102102
{
103-
var completeShortName = string.Concat("-", new string(option.Value, 1));
104-
105-
return string.Compare(argument, completeShortName,
103+
return string.Compare(argument, option.ToOption(),
106104
caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase) == 0;
107105
}
108106

109107
public static bool CompareLong(string argument, string option, bool caseSensitive)
110108
{
111-
var completeLongName = string.Concat("--", option);
112-
113-
return string.Compare(argument, completeLongName,
109+
return string.Compare(argument, option.ToOption(),
114110
caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase) == 0;
115111
}
116112

0 commit comments

Comments
 (0)