Skip to content

Commit 59cfdcb

Browse files
committed
extended the FluentCommandLineBuilder to provide the IsCaseSensitive and SetupHelp items
1 parent 05ef282 commit 59cfdcb

File tree

3 files changed

+91
-6
lines changed

3 files changed

+91
-6
lines changed

FluentCommandLineParser/FluentCommandLineBuilder.cs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@
2929
namespace Fclp
3030
{
3131
/// <summary>
32-
/// Prototype parser that constructs and populates the specified type of object from command line arguments.
32+
/// Parser that constructs and populates the specified type of object from command line arguments.
3333
/// </summary>
34-
public class FluentCommandLineBuilder<TBuildType> where TBuildType : new()
34+
public class FluentCommandLineBuilder<TBuildType> : IFluentCommandLineBuilder<TBuildType> where TBuildType : new()
3535
{
36-
private readonly FluentCommandLineParser _parser;
36+
/// <summary>
37+
/// Gets the <see cref="IFluentCommandLineParser"/>.
38+
/// </summary>
39+
public IFluentCommandLineParser Parser { get; private set; }
3740

3841
/// <summary>
3942
/// Gets the constructed object.
@@ -46,15 +49,15 @@ namespace Fclp
4649
public FluentCommandLineBuilder()
4750
{
4851
Object = new TBuildType();
49-
_parser = new FluentCommandLineParser();
52+
Parser = new FluentCommandLineParser();
5053
}
5154

5255
/// <summary>
5356
/// Sets up an Option for a write-able property on the type being built.
5457
/// </summary>
5558
public ICommandLineOptionBuilderFluent<TProperty> Setup<TProperty>(Expression<Func<TBuildType, TProperty>> propertyPicker)
5659
{
57-
return new CommandLineOptionBuilderFluent<TBuildType, TProperty>(_parser, Object, propertyPicker);
60+
return new CommandLineOptionBuilderFluent<TBuildType, TProperty>(Parser, Object, propertyPicker);
5861
}
5962

6063
/// <summary>
@@ -64,7 +67,25 @@ public ICommandLineOptionBuilderFluent<TProperty> Setup<TProperty>(Expression<Fu
6467
/// <returns>An <see cref="ICommandLineParserResult"/> representing the results of the parse operation.</returns>
6568
public ICommandLineParserResult Parse(string[] args)
6669
{
67-
return _parser.Parse(args);
70+
return Parser.Parse(args);
71+
}
72+
73+
/// <summary>
74+
/// Setup the help args.
75+
/// </summary>
76+
/// <param name="helpArgs">The help arguments to register.</param>
77+
public IHelpCommandLineOptionFluent SetupHelp(params string[] helpArgs)
78+
{
79+
return Parser.SetupHelp(helpArgs);
80+
}
81+
82+
/// <summary>
83+
/// Gets or sets whether values that differ by case are considered different.
84+
/// </summary>
85+
public bool IsCaseSensitive
86+
{
87+
get { return Parser.IsCaseSensitive; }
88+
set { Parser.IsCaseSensitive = value; }
6889
}
6990
}
7091
}

FluentCommandLineParser/FluentCommandLineParser.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<Compile Include="FluentCommandLineBuilder.cs" />
5959
<Compile Include="ICommandLineOptionBuilderFluent.cs" />
6060
<Compile Include="ICommandLineParserErrorFormatter.cs" />
61+
<Compile Include="IFluentCommandLineBuilder.cs" />
6162
<Compile Include="IHelpCommandLineOptionFluent.cs" />
6263
<Compile Include="Internals\CommandLineOptionBuilderFluent.cs" />
6364
<Compile Include="Internals\CommandLineParserEngineMark2.cs" />
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#region License
2+
// IFluentCommandLineBuilder.cs
3+
// Copyright (c) 2013, Simon Williams
4+
// All rights reserved.
5+
//
6+
// Redistribution and use in source and binary forms, with or without modification, are permitted provide
7+
// d that the following conditions are met:
8+
//
9+
// Redistributions of source code must retain the above copyright notice, this list of conditions and the
10+
// following disclaimer.
11+
//
12+
// Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
13+
// the following disclaimer in the documentation and/or other materials provided with the distribution.
14+
//
15+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
16+
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17+
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18+
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
19+
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20+
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22+
// POSSIBILITY OF SUCH DAMAGE.
23+
#endregion
24+
25+
using System;
26+
using System.Linq.Expressions;
27+
28+
namespace Fclp
29+
{
30+
/// <summary>
31+
/// Parser that constructs and populates the specified type of object from command line arguments.
32+
/// </summary>
33+
public interface IFluentCommandLineBuilder<TBuildType> where TBuildType : new()
34+
{
35+
/// <summary>
36+
/// Gets the constructed object.
37+
/// </summary>
38+
TBuildType Object { get; }
39+
40+
/// <summary>
41+
/// Sets up an Option for a write-able property on the type being built.
42+
/// </summary>
43+
ICommandLineOptionBuilderFluent<TProperty> Setup<TProperty>(Expression<Func<TBuildType, TProperty>> propertyPicker);
44+
45+
/// <summary>
46+
/// Parses the specified <see><cref>T:System.String[]</cref></see> using the setup Options.
47+
/// </summary>
48+
/// <param name="args">The <see><cref>T:System.String[]</cref></see> to parse.</param>
49+
/// <returns>An <see cref="ICommandLineParserResult"/> representing the results of the parse operation.</returns>
50+
ICommandLineParserResult Parse(string[] args);
51+
52+
/// <summary>
53+
/// Setup the help args.
54+
/// </summary>
55+
/// <param name="helpArgs">The help arguments to register.</param>
56+
IHelpCommandLineOptionFluent SetupHelp(params string[] helpArgs);
57+
58+
/// <summary>
59+
/// Gets or sets whether values that differ by case are considered different.
60+
/// </summary>
61+
bool IsCaseSensitive { get; set; }
62+
}
63+
}

0 commit comments

Comments
 (0)