Skip to content

Commit 352269b

Browse files
committed
tabify
1 parent 7a465d5 commit 352269b

File tree

2 files changed

+126
-126
lines changed

2 files changed

+126
-126
lines changed

FluentCommandLineParser.Tests/FluentCommandLineParserTests.cs

Lines changed: 85 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void Ensure_Description_Can_Be_Set()
107107

108108
const string expected = "my description";
109109

110-
var cmdOption = parser.Setup<string>('s').WithDescription(expected);
110+
var cmdOption = parser.Setup<string>('s').WithDescription(expected);
111111

112112
var actual = ((ICommandLineOption)cmdOption).Description;
113113

@@ -356,39 +356,39 @@ public void Ensure_Parser_Calls_The_Callback_With_Expected_DateTime_When_Using_L
356356

357357
#endregion DateTime Option
358358

359-
#region Long Option Only
359+
#region Long Option Only
360360

361-
[Test]
362-
public void Can_have_long_option_only()
363-
{
364-
var parser = CreateFluentParser();
365-
var s = "";
361+
[Test]
362+
public void Can_have_long_option_only()
363+
{
364+
var parser = CreateFluentParser();
365+
var s = "";
366366

367-
parser.Setup<string>("my-feature")
368-
.Callback(val => s = val);
367+
parser.Setup<string>("my-feature")
368+
.Callback(val => s = val);
369369

370-
var result = parser.Parse(new[] { "--my-feature", "somevalue" });
370+
var result = parser.Parse(new[] { "--my-feature", "somevalue" });
371371

372-
Assert.IsFalse(result.HasErrors);
373-
Assert.IsFalse(result.EmptyArgs);
374-
Assert.IsFalse(result.HelpCalled);
372+
Assert.IsFalse(result.HasErrors);
373+
Assert.IsFalse(result.EmptyArgs);
374+
Assert.IsFalse(result.HelpCalled);
375375

376-
Assert.AreEqual("somevalue", s);
377-
}
376+
Assert.AreEqual("somevalue", s);
377+
}
378378

379-
[Test]
380-
[ExpectedException(typeof(ArgumentOutOfRangeException))]
381-
public void Cannot_have_single_character_long_option()
382-
{
383-
var parser = CreateFluentParser();
384-
parser.Setup<string>("s");
385-
}
379+
[Test]
380+
[ExpectedException(typeof(ArgumentOutOfRangeException))]
381+
public void Cannot_have_single_character_long_option()
382+
{
383+
var parser = CreateFluentParser();
384+
parser.Setup<string>("s");
385+
}
386386

387-
#endregion
387+
#endregion
388388

389-
#region Required
389+
#region Required
390390

391-
[Test]
391+
[Test]
392392
public void Ensure_Expected_Error_Is_Returned_If_A_Option_Is_Required_And_Null_Args_Are_Specified()
393393
{
394394
var parser = CreateFluentParser();
@@ -588,66 +588,66 @@ public void Ensure_Defaults_Are_Called_When_Empty_Args_Specified()
588588

589589
#region Example
590590

591-
[Test]
592-
public void Ensure_Example_Works_As_Expected()
593-
{
594-
const int expectedRecordId = 10;
595-
const string expectedValue = "Mr. Smith";
596-
const bool expectedSilentMode = true;
597-
const bool expectedSwitchA = true;
598-
const bool expectedSwitchB = true;
599-
const bool expectedSwitchC = false;
600-
601-
var args = new[] { "-r", expectedRecordId.ToString(CultureInfo.InvariantCulture), "-v", "\"Mr. Smith\"", "--silent", "-ab", "-c-" };
602-
603-
var recordId = 0;
604-
string newValue = null;
605-
var inSilentMode = false;
606-
var switchA = false;
607-
var switchB = false;
608-
var switchC = true;
609-
610-
var parser = CreateFluentParser();
611-
612-
parser.Setup<bool>('a')
613-
.Callback(value => switchA = value);
614-
615-
parser.Setup<bool>('b')
616-
.Callback(value => switchB = value);
617-
618-
parser.Setup<bool>('c')
619-
.Callback(value => switchC = value);
620-
621-
// create a new Option using a short and long name
622-
parser.Setup<int>('r', "record")
623-
.WithDescription("The record id to update (required)")
624-
.Callback(record => recordId = record) // use callback to assign the record value to the local RecordID property
625-
.Required(); // fail if this Option is not provided in the arguments
626-
627-
parser.Setup<bool>("silent")
628-
.WithDescription("Execute the update in silent mode without feedback (default is false)")
629-
.Callback(silent => inSilentMode = silent)
630-
.SetDefault(false); // explicitly set the default value to use if this Option is not specified in the arguments
631-
632-
633-
parser.Setup<string>('v', "value")
634-
.WithDescription("The new value for the record (required)") // used when help is requested e.g -? or --help
635-
.Callback(value => newValue = value)
636-
.Required();
637-
638-
// do the work
639-
ICommandLineParserResult result = parser.Parse(args);
640-
641-
Assert.IsFalse(result.HasErrors);
642-
Assert.IsFalse(result.Errors.Any());
643-
644-
Assert.AreEqual(expectedRecordId, recordId);
645-
Assert.AreEqual(expectedValue, newValue);
646-
Assert.AreEqual(expectedSilentMode, inSilentMode);
647-
Assert.AreEqual(expectedSwitchA, switchA);
648-
Assert.AreEqual(expectedSwitchB, switchB);
649-
Assert.AreEqual(expectedSwitchC, switchC);
650-
}
591+
[Test]
592+
public void Ensure_Example_Works_As_Expected()
593+
{
594+
const int expectedRecordId = 10;
595+
const string expectedValue = "Mr. Smith";
596+
const bool expectedSilentMode = true;
597+
const bool expectedSwitchA = true;
598+
const bool expectedSwitchB = true;
599+
const bool expectedSwitchC = false;
600+
601+
var args = new[] { "-r", expectedRecordId.ToString(CultureInfo.InvariantCulture), "-v", "\"Mr. Smith\"", "--silent", "-ab", "-c-" };
602+
603+
var recordId = 0;
604+
string newValue = null;
605+
var inSilentMode = false;
606+
var switchA = false;
607+
var switchB = false;
608+
var switchC = true;
609+
610+
var parser = CreateFluentParser();
611+
612+
parser.Setup<bool>('a')
613+
.Callback(value => switchA = value);
614+
615+
parser.Setup<bool>('b')
616+
.Callback(value => switchB = value);
617+
618+
parser.Setup<bool>('c')
619+
.Callback(value => switchC = value);
620+
621+
// create a new Option using a short and long name
622+
parser.Setup<int>('r', "record")
623+
.WithDescription("The record id to update (required)")
624+
.Callback(record => recordId = record) // use callback to assign the record value to the local RecordID property
625+
.Required(); // fail if this Option is not provided in the arguments
626+
627+
parser.Setup<bool>("silent")
628+
.WithDescription("Execute the update in silent mode without feedback (default is false)")
629+
.Callback(silent => inSilentMode = silent)
630+
.SetDefault(false); // explicitly set the default value to use if this Option is not specified in the arguments
631+
632+
633+
parser.Setup<string>('v', "value")
634+
.WithDescription("The new value for the record (required)") // used when help is requested e.g -? or --help
635+
.Callback(value => newValue = value)
636+
.Required();
637+
638+
// do the work
639+
ICommandLineParserResult result = parser.Parse(args);
640+
641+
Assert.IsFalse(result.HasErrors);
642+
Assert.IsFalse(result.Errors.Any());
643+
644+
Assert.AreEqual(expectedRecordId, recordId);
645+
Assert.AreEqual(expectedValue, newValue);
646+
Assert.AreEqual(expectedSilentMode, inSilentMode);
647+
Assert.AreEqual(expectedSwitchA, switchA);
648+
Assert.AreEqual(expectedSwitchB, switchB);
649+
Assert.AreEqual(expectedSwitchC, switchC);
650+
}
651651

652652
#endregion
653653

FluentCommandLineParser/FluentCommandLineParser.cs

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -122,38 +122,38 @@ internal IHelpCommandLineOption HelpOption
122122
/// </exception>
123123
public ICommandLineOptionFluent<T> Setup<T>(char shortOption, string longOption)
124124
{
125-
EnsureIsValidShortName(shortOption);
126-
EnsureIsValidLongName(longOption);
127-
//EnsureHasShortNameOrLongName(shortOption, longOption);
125+
EnsureIsValidShortName(shortOption);
126+
EnsureIsValidLongName(longOption);
127+
//EnsureHasShortNameOrLongName(shortOption, longOption);
128128

129-
return SetupInternal<T>(shortOption.ToString(CultureInfo.InvariantCulture), longOption);
129+
return SetupInternal<T>(shortOption.ToString(CultureInfo.InvariantCulture), longOption);
130130
}
131131

132-
private ICommandLineOptionFluent<T> SetupInternal<T>(string shortOption, string longOption)
133-
{
134-
foreach (var option in this.Options)
135-
{
136-
if (shortOption != null && shortOption.Equals(option.ShortName, this.StringComparison))
137-
throw new OptionAlreadyExistsException(shortOption);
132+
private ICommandLineOptionFluent<T> SetupInternal<T>(string shortOption, string longOption)
133+
{
134+
foreach (var option in this.Options)
135+
{
136+
if (shortOption != null && shortOption.Equals(option.ShortName, this.StringComparison))
137+
throw new OptionAlreadyExistsException(shortOption);
138138

139-
if (longOption != null && longOption.Equals(option.LongName, this.StringComparison))
140-
throw new OptionAlreadyExistsException(longOption);
141-
}
139+
if (longOption != null && longOption.Equals(option.LongName, this.StringComparison))
140+
throw new OptionAlreadyExistsException(longOption);
141+
}
142142

143-
var argOption = this.OptionFactory.CreateOption<T>(shortOption, longOption);
143+
var argOption = this.OptionFactory.CreateOption<T>(shortOption, longOption);
144144

145-
if (argOption == null)
146-
throw new InvalidOperationException("OptionFactory is producing unexpected results.");
145+
if (argOption == null)
146+
throw new InvalidOperationException("OptionFactory is producing unexpected results.");
147147

148-
this.Options.Add(argOption);
148+
this.Options.Add(argOption);
149149

150-
return argOption;
151-
}
150+
return argOption;
151+
}
152152

153153
private static void EnsureIsValidShortName(char value)
154154
{
155-
if (char.IsWhiteSpace(value) || char.IsControl(value) || value == ':' || value == '=')
156-
throw new ArgumentOutOfRangeException("value");
155+
if (char.IsWhiteSpace(value) || char.IsControl(value) || value == ':' || value == '=')
156+
throw new ArgumentOutOfRangeException("value");
157157
}
158158

159159
private static void EnsureIsValidLongName(string value)
@@ -168,11 +168,11 @@ private static void EnsureIsValidLongName(string value)
168168
throw new ArgumentOutOfRangeException("value");
169169
}
170170

171-
private static void EnsureHasShortNameOrLongName(char shortOption, string longOption)
172-
{
173-
if (char.IsWhiteSpace(shortOption) && longOption.IsNullOrWhiteSpace())
174-
throw new ArgumentOutOfRangeException("shortOption", "Either shortOption or longOption must be specified");
175-
}
171+
private static void EnsureHasShortNameOrLongName(char shortOption, string longOption)
172+
{
173+
if (char.IsWhiteSpace(shortOption) && longOption.IsNullOrWhiteSpace())
174+
throw new ArgumentOutOfRangeException("shortOption", "Either shortOption or longOption must be specified");
175+
}
176176

177177
/// <summary>
178178
/// Setup a new <see cref="ICommandLineOptionFluent{T}"/> using the specified short Option name.
@@ -184,23 +184,23 @@ private static void EnsureHasShortNameOrLongName(char shortOption, string longOp
184184
/// </exception>
185185
public ICommandLineOptionFluent<T> Setup<T>(char shortOption)
186186
{
187-
EnsureIsValidShortName(shortOption);
188-
return SetupInternal<T>(shortOption.ToString(CultureInfo.InvariantCulture), null);
187+
EnsureIsValidShortName(shortOption);
188+
return SetupInternal<T>(shortOption.ToString(CultureInfo.InvariantCulture), null);
189189
}
190190

191-
/// <summary>
192-
/// Setup a new <see cref="ICommandLineOptionFluent{T}"/> using the specified long Option name.
193-
/// </summary>
194-
/// <param name="longOption">The long name for the Option. This must not be <c>null</c>, <c>empty</c> or only <c>whitespace</c>.</param>
195-
/// <returns></returns>
196-
/// <exception cref="OptionAlreadyExistsException">
197-
/// A Option with the same <paramref name="longOption"/> name already exists in the <see cref="IFluentCommandLineParser"/>.
198-
/// </exception>
199-
public ICommandLineOptionFluent<T> Setup<T>(string longOption)
200-
{
201-
EnsureIsValidLongName(longOption);
202-
return SetupInternal<T>(null, longOption);
203-
}
191+
/// <summary>
192+
/// Setup a new <see cref="ICommandLineOptionFluent{T}"/> using the specified long Option name.
193+
/// </summary>
194+
/// <param name="longOption">The long name for the Option. This must not be <c>null</c>, <c>empty</c> or only <c>whitespace</c>.</param>
195+
/// <returns></returns>
196+
/// <exception cref="OptionAlreadyExistsException">
197+
/// A Option with the same <paramref name="longOption"/> name already exists in the <see cref="IFluentCommandLineParser"/>.
198+
/// </exception>
199+
public ICommandLineOptionFluent<T> Setup<T>(string longOption)
200+
{
201+
EnsureIsValidLongName(longOption);
202+
return SetupInternal<T>(null, longOption);
203+
}
204204

205205
/// <summary>
206206
/// Parses the specified <see><cref>T:System.String[]</cref></see> using the setup Options.

0 commit comments

Comments
 (0)