Skip to content

Commit 46c8a6a

Browse files
committed
set the parent CommandResult for implicit tokens
1 parent 3e225df commit 46c8a6a

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

src/System.CommandLine.Tests/ArgumentTests.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public void custom_parsing_of_scalar_value_from_an_argument_with_multiple_tokens
190190
}
191191

192192
[Fact]
193-
public void ArgumentResult_Parent_is_set_correctly_when_token_is_present()
193+
public void Option_ArgumentResult_Parent_is_set_correctly_when_token_is_implicit()
194194
{
195195
ArgumentResult argumentResult = null;
196196

@@ -202,19 +202,20 @@ public void ArgumentResult_Parent_is_set_correctly_when_token_is_present()
202202
{
203203
argumentResult = argResult;
204204
return null;
205-
})
205+
}, isDefault: true)
206206
};
207207

208-
command.Parse("-x abc");
208+
command.Parse("");
209209

210210
argumentResult
211211
.Parent
212+
.Symbol
212213
.Should()
213-
.NotBeNull();
214+
.Be(command.Options.Single());
214215
}
215216

216217
[Fact]
217-
public void Option_ArgumentResult_Parent_is_set_correctly_when_token_is_implicit()
218+
public void Option_ArgumentResult_parentage_to_root_symbol_is_set_correctly_when_token_is_implicit()
218219
{
219220
ArgumentResult argumentResult = null;
220221

@@ -232,10 +233,11 @@ public void Option_ArgumentResult_Parent_is_set_correctly_when_token_is_implicit
232233
command.Parse("");
233234

234235
argumentResult
236+
.Parent
235237
.Parent
236238
.Symbol
237239
.Should()
238-
.Be(command.Options.Single());
240+
.Be(command);
239241
}
240242

241243
[Fact]

src/System.CommandLine/Parsing/OptionResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class OptionResult : SymbolResult
1313
internal OptionResult(
1414
IOption option,
1515
Token token,
16-
CommandResult parent = null) :
16+
CommandResult parent) :
1717
base(option ?? throw new ArgumentNullException(nameof(option)),
1818
parent)
1919
{

src/System.CommandLine/Parsing/ParseResultVisitor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ private void PopulateDefaultValues()
320320

321321
var optionResult = new OptionResult(
322322
option,
323-
option.CreateImplicitToken());
323+
option.CreateImplicitToken(),
324+
commandResult);
324325

325326
var token = new ImplicitToken(
326327
optionResult.GetDefaultValueFor(option.Argument),

src/System.CommandLine/Parsing/SymbolResult.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

44
using System.Collections.Generic;
5-
using System.CommandLine.Binding;
65
using System.Linq;
76

87
namespace System.CommandLine.Parsing
@@ -15,7 +14,7 @@ public abstract class SymbolResult
1514

1615
private protected SymbolResult(
1716
ISymbol symbol,
18-
SymbolResult parent = null)
17+
SymbolResult parent)
1918
{
2019
Symbol = symbol ?? throw new ArgumentNullException(nameof(symbol));
2120

0 commit comments

Comments
 (0)