Skip to content

Commit e26a222

Browse files
committed
Allow nested searches for feature values
1 parent 608cdae commit e26a222

4 files changed

Lines changed: 22 additions & 6 deletions

File tree

SabreTools.CommandLine.Test/CommandSetTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public void GetFeature_Exists_Returns()
188188
}
189189

190190
[Fact]
191-
public void GetFeature_NestedExists_Null()
191+
public void GetFeature_NestedExists_Returns()
192192
{
193193
var commandSet = new CommandSet();
194194
var child = new MockUserInput("b", "b", "b");
@@ -200,7 +200,9 @@ public void GetFeature_NestedExists_Null()
200200
subChild.ProcessInput(["c"], ref index);
201201

202202
Feature? actual = commandSet.GetFeature("c");
203-
Assert.Null(actual);
203+
Assert.NotNull(actual);
204+
Assert.Equal("c", actual.Name);
205+
Assert.True(actual.Value);
204206
}
205207

206208
#endregion

SabreTools.CommandLine.Test/Inputs/UserInputTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public void GetFeature_Exists_Returns()
154154
}
155155

156156
[Fact]
157-
public void GetFeature_NestedExists_Null()
157+
public void GetFeature_NestedExists_Returns()
158158
{
159159
UserInput userInput = new MockUserInput("a", "a", "a");
160160
var child = new MockUserInput("b", "b", "b");
@@ -166,7 +166,9 @@ public void GetFeature_NestedExists_Null()
166166
subChild.ProcessInput(["c"], ref index);
167167

168168
Feature? actual = userInput.GetFeature("c");
169-
Assert.Null(actual);
169+
Assert.NotNull(actual);
170+
Assert.Equal("c", actual.Name);
171+
Assert.True(actual.Value);
170172
}
171173

172174
#endregion

SabreTools.CommandLine/CommandSet.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,13 @@ public bool TryGetFeature(string key, out Feature? value)
325325
return true;
326326
}
327327

328-
// TODO: Investigate if nested features should be supported
328+
// Check all children recursively
329+
foreach (var child in _inputs.Values)
330+
{
331+
if (child.TryGetFeature(key, out value))
332+
return true;
333+
}
334+
329335
value = null;
330336
return false;
331337
}

SabreTools.CommandLine/Inputs/UserInput.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,13 @@ public bool TryGetFeature(string key, out Feature? value)
343343
return true;
344344
}
345345

346-
// TODO: Investigate if nested features should be supported
346+
// Check all children recursively
347+
foreach (var child in Children.Values)
348+
{
349+
if (child.TryGetFeature(key, out value))
350+
return true;
351+
}
352+
347353
value = null;
348354
return false;
349355
}

0 commit comments

Comments
 (0)