Repository navigation
Move directives to CliRootCommand - #2224
Conversation
adamsitnik
left a comment
There was a problem hiding this comment.
Overall the fix looks very good, thank you @jonsequitur !
I am curious why you have decided to move the directives from config to root command now. I am not against it, but it's going to have non-trivial impact on the future of RootCommand (we won't be able to delete it). Are you planning to move more things from the config to the root command?
| CliDirective configurationDirective = parseResult.Configuration.Directives.Single(d => d.Name == "config"); | ||
| hostBuilder.ConfigureHostConfiguration(config => { config.AddCommandLineDirectives(parseResult, configurationDirective); }); | ||
| if (parseResult.Configuration.RootCommand is CliRootCommand root && | ||
| root.Directives.SingleOrDefault(d => d.Name == HostingDirectiveName) is { } directive) |
There was a problem hiding this comment.
subjective: I find is { } directive very unintuitive
| _children = new(); | ||
| } | ||
|
|
||
| internal bool HasDirectives => | ||
| RootCommand switch | ||
| { | ||
| CliRootCommand root => root.Directives.Count > 0, | ||
| _ => false | ||
| }; |
There was a problem hiding this comment.
subjective: IMO a switch statement for two possibilities is not worth it
internal bool HasDirectives => RootCommand is CliRootCommand root && root.Directives.Count > 0;| ? (CliDirective)directiveToken.Symbol! | ||
| : null; | ||
| CliDirective? directive; | ||
| if (knownTokens.TryGetValue($"[{directiveName}]", out var directiveToken)) |
There was a problem hiding this comment.
So the actual parse error fix was to wrap the directive name in []?
May I ask why have you decided to move CliDirective from config to root command then? I am not against it, I am just curious whether overall you got to a conclusion that it's where it belongs or whether I can't see some other aspect of the actual fix.
There was a problem hiding this comment.
This change isn't ideal but it's a step toward reducing the impact of a larger bug (#2223). It can't be fully fixed without incorporating directives into the symbol model, which is why moving them to CliRootCommand at this point was helpful. It's a design decision we discussed a few times for the sake of consistency. Tactically, this was a good time to do it since it related to this bug.
There was a problem hiding this comment.
It can't be fully fixed without incorporating directives into the symbol model
Thanks, now I know all I needed! 👍
| Dictionary<string, CliToken> tokens = new(StringComparer.Ordinal); | ||
|
|
||
| if (directives is not null) | ||
| if (command is CliRootCommand { Directives: IList<CliDirective> directives }) |
There was a problem hiding this comment.
again subjective on style: what do we benefit from using this syntax here?
if (command is CliRootCommand { Directives: IList<CliDirective> directives })
{
for (int i = 0; i < directives.Count; i++)if (command is CliRootCommand rootCommand)
{
for (int i = 0; i < rootCommand.Directives.Count; i++)There was a problem hiding this comment.
This avoids an intermediate assignment of a CliRootCommand variable when all we need from it is the directives:
if (command is CliRootCommand { Directives: IList<CliDirective> directives })I don't know if this makes any difference from a performance perspective but I find it (subjectively, again) to be less cluttered.
The sense from a few design discussions we've had about this is that since directives are only valid at the root, and since they're symbols, it's consistent and intuitive for them to be children of The other changes we've discussed making to |
No description provided.