Allow nested searches for feature values

This commit is contained in:
Matt Nadareski
2025-10-05 22:32:16 -04:00
parent 608cdae1d8
commit e26a222755
4 changed files with 22 additions and 6 deletions

View File

@@ -188,7 +188,7 @@ namespace SabreTools.CommandLine.Test
}
[Fact]
public void GetFeature_NestedExists_Null()
public void GetFeature_NestedExists_Returns()
{
var commandSet = new CommandSet();
var child = new MockUserInput("b", "b", "b");
@@ -200,7 +200,9 @@ namespace SabreTools.CommandLine.Test
subChild.ProcessInput(["c"], ref index);
Feature? actual = commandSet.GetFeature("c");
Assert.Null(actual);
Assert.NotNull(actual);
Assert.Equal("c", actual.Name);
Assert.True(actual.Value);
}
#endregion

View File

@@ -154,7 +154,7 @@ namespace SabreTools.CommandLine.Test.Inputs
}
[Fact]
public void GetFeature_NestedExists_Null()
public void GetFeature_NestedExists_Returns()
{
UserInput userInput = new MockUserInput("a", "a", "a");
var child = new MockUserInput("b", "b", "b");
@@ -166,7 +166,9 @@ namespace SabreTools.CommandLine.Test.Inputs
subChild.ProcessInput(["c"], ref index);
Feature? actual = userInput.GetFeature("c");
Assert.Null(actual);
Assert.NotNull(actual);
Assert.Equal("c", actual.Name);
Assert.True(actual.Value);
}
#endregion

View File

@@ -325,7 +325,13 @@ namespace SabreTools.CommandLine
return true;
}
// TODO: Investigate if nested features should be supported
// Check all children recursively
foreach (var child in _inputs.Values)
{
if (child.TryGetFeature(key, out value))
return true;
}
value = null;
return false;
}

View File

@@ -343,7 +343,13 @@ namespace SabreTools.CommandLine.Inputs
return true;
}
// TODO: Investigate if nested features should be supported
// Check all children recursively
foreach (var child in Children.Values)
{
if (child.TryGetFeature(key, out value))
return true;
}
value = null;
return false;
}