Skip to content

Commit c672158

Browse files
committed
work towards an additional arguments callback
1 parent 23d88ef commit c672158

File tree

7 files changed

+44
-2
lines changed

7 files changed

+44
-2
lines changed

FluentCommandLineParser.Tests/FluentCommandLineParser/when_setting_up_a_new_option/with_a_long_name/with_a_long_name.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class with_a_long_name : SettingUpALongOptionTestContext
4141
It should_have_the_given_long_name = () => option.LongName.ShouldMatch(valid_long_name);
4242
It should_not_be_a_required_option = () => option.IsRequired.ShouldBeFalse();
4343
It should_have_no_callback = () => option.HasCallback.ShouldBeFalse();
44+
It should_have_no_additional_args_callback = () => option.HasAdditionalArgumentsCallback.ShouldBeFalse();
4445
It should_have_no_description = () => option.Description.ShouldBeNull();
4546
It should_have_no_default_value = () => option.HasDefault.ShouldBeFalse();
4647
}

FluentCommandLineParser.Tests/FluentCommandLineParser/when_setting_up_a_new_option/with_a_long_name/with_a_long_name_that_is_empty.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class with_a_long_name_that_is_empty : SettingUpALongOptionTestContext
4141
It should_have_the_given_long_name = () => option.LongName.ShouldMatch(valid_long_name_that_is_empty);
4242
It should_not_be_a_required_option = () => option.IsRequired.ShouldBeFalse();
4343
It should_have_no_callback = () => option.HasCallback.ShouldBeFalse();
44+
It should_have_no_additional_args_callback = () => option.HasAdditionalArgumentsCallback.ShouldBeFalse();
4445
It should_have_no_description = () => option.Description.ShouldBeNull();
4546
It should_have_no_default_value = () => option.HasDefault.ShouldBeFalse();
4647
}

FluentCommandLineParser.Tests/FluentCommandLineParser/when_setting_up_a_new_option/with_a_long_name/with_a_long_name_that_is_valid.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class with_a_long_name_that_is_valid : SettingUpALongOptionTestContext
4141
It should_have_the_given_long_name = () => option.LongName.ShouldBeNull();
4242
It should_not_be_a_required_option = () => option.IsRequired.ShouldBeFalse();
4343
It should_have_no_callback = () => option.HasCallback.ShouldBeFalse();
44+
It should_have_no_additional_args_callback = () => option.HasAdditionalArgumentsCallback.ShouldBeFalse();
4445
It should_have_no_description = () => option.Description.ShouldBeNull();
4546
It should_have_no_default_value = () => option.HasDefault.ShouldBeFalse();
4647
}

FluentCommandLineParser.Tests/FluentCommandLineParser/when_setting_up_a_new_option/with_a_short_name/with_a_short_name.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class with_a_short_name : SettingUpAShortOptionTestContext
4141
It should_have_no_long_name = () => option.HasLongName.ShouldBeFalse();
4242
It should_not_be_a_required_option = () => option.IsRequired.ShouldBeFalse();
4343
It should_have_no_callback = () => option.HasCallback.ShouldBeFalse();
44+
It should_have_no_additional_args_callback = () => option.HasAdditionalArgumentsCallback.ShouldBeFalse();
4445
It should_have_no_description = () => option.Description.ShouldBeNull();
4546
It should_have_no_default_value = () => option.HasDefault.ShouldBeFalse();
4647
}

FluentCommandLineParser/ICommandLineOptionFluent.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#endregion
2424

2525
using System;
26+
using System.Collections.Generic;
2627

2728
namespace Fclp
2829
{
@@ -47,6 +48,7 @@ public interface ICommandLineOptionFluent<T>
4748
/// <summary>
4849
/// Specifies the method to invoke when the <see cref="ICommandLineOptionFluent{T}"/>.
4950
/// is parsed. If a callback is not required either do not call it, or specify <c>null</c>.
51+
/// Do no use this if you are using the Fluent Command Line Builder.
5052
/// </summary>
5153
/// <param name="callback">The return callback to execute with the parsed value of the Option.</param>
5254
/// <returns>A <see cref="ICommandLineOptionFluent{T}"/>.</returns>
@@ -58,5 +60,13 @@ public interface ICommandLineOptionFluent<T>
5860
/// <param name="value">The value to use.</param>
5961
/// <returns>A <see cref="ICommandLineOptionFluent{T}"/>.</returns>
6062
ICommandLineOptionFluent<T> SetDefault(T value);
63+
64+
/// <summary>
65+
/// Specified the method to invoke with any addition arguments parsed with the Option.
66+
/// If additional arguments are not required either do not call it, or specify <c>null</c>.
67+
/// </summary>
68+
/// <param name="callback">The return callback to execute with the parsed addition arguments found for this Option.</param>
69+
/// <returns>A <see cref="ICommandLineOptionFluent{T}"/>.</returns>
70+
ICommandLineOptionFluent<T> AdditionalArgumentsCallback(Action<IEnumerable<string>> callback);
6171
}
6272
}

FluentCommandLineParser/Internals/CommandLineOption.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#endregion
2424

2525
using System;
26+
using System.Collections.Generic;
2627
using System.Linq;
2728
using Fclp.Internals.Extensions;
2829
using Fclp.Internals.Parsing;
@@ -72,6 +73,8 @@ public CommandLineOption(string shortName, string longName, ICommandLineOptionPa
7273

7374
internal Action<T> ReturnCallback { get; set; }
7475

76+
internal Action<IEnumerable<string>> ReturnAdditionalArgumentsCallback { get; set; }
77+
7578
internal T Default { get; set; }
7679

7780
/// <summary>
@@ -124,13 +127,21 @@ public bool HasShortName
124127
}
125128

126129
/// <summary>
127-
/// Gets whether this <see cred="ICommandLineOption"/> has a callback setup.
130+
/// Gets whether this <see cref="ICommandLineOption"/> has a callback setup.
128131
/// </summary>
129132
public bool HasCallback
130133
{
131134
get { return this.ReturnCallback != null; }
132135
}
133136

137+
/// <summary>
138+
/// Gets whether this <see cref="ICommandLineOption"/> has an additional arguments callback setup.
139+
/// </summary>
140+
public bool HasAdditionalArgumentsCallback
141+
{
142+
get { return this.ReturnAdditionalArgumentsCallback != null; }
143+
}
144+
134145
#endregion Properties
135146

136147
#region Methods
@@ -173,7 +184,7 @@ public ICommandLineOptionFluent<T> WithDescription(string description)
173184
}
174185

175186
/// <summary>
176-
/// Declares that this <see cref="ICommandLineOptionFluent{T}"/> is required and a value must be specified to fulfill it.
187+
/// Declares that this <see cref="ICommandLineOptionFluent{T}"/> is required and a value must be specified to fulfil it.
177188
/// </summary>
178189
/// <returns>A <see cref="ICommandLineOptionFluent{T}"/>.</returns>
179190
public ICommandLineOptionFluent<T> Required()
@@ -206,6 +217,18 @@ public ICommandLineOptionFluent<T> SetDefault(T value)
206217
return this;
207218
}
208219

220+
/// <summary>
221+
/// Specified the method to invoke with any addition arguments parsed with the Option.
222+
/// If additional arguments are not required either do not call it, or specify <c>null</c>.
223+
/// </summary>
224+
/// <param name="callback">The return callback to execute with the parsed addition arguments found for this Option.</param>
225+
/// <returns>A <see cref="ICommandLineOptionFluent{T}"/>.</returns>
226+
public ICommandLineOptionFluent<T> AdditionalArgumentsCallback(Action<IEnumerable<string>> callback)
227+
{
228+
this.ReturnAdditionalArgumentsCallback = callback;
229+
return this;
230+
}
231+
209232
#endregion Methods
210233
}
211234
}

FluentCommandLineParser/Internals/ICommandLineOption.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ public interface ICommandLineOption
7878
/// </summary>
7979
bool HasCallback { get; }
8080

81+
/// <summary>
82+
/// Gets whether this <see cref="ICommandLineOption"/> has an additional arguments callback setup.
83+
/// </summary>
84+
bool HasAdditionalArgumentsCallback { get; }
85+
8186
/// <summary>
8287
/// Gets whether this <see cref="ICommandLineOption"/> has a default value setup.
8388
/// </summary>

0 commit comments

Comments
 (0)