private static void PopulateDefaultValues( CommandResult parentCommandResult, ISymbol symbol) { var symbolResult = parentCommandResult.Children.ResultFor(symbol); if (symbolResult == null) { switch (symbol) { case Option option when option.Argument.HasDefaultValue: var optionResult = new OptionResult( option, option.CreateImplicitToken()); var token = new ImplicitToken( optionResult.GetDefaultValueFor(option.Argument), TokenType.Argument); optionResult.Children.Add( new ArgumentResult( option.Argument, token, optionResult)); parentCommandResult.Children.Add(optionResult); optionResult.AddToken(token); break; case Argument argument when argument.HasDefaultValue: var implicitToken = new ImplicitToken(argument.GetDefaultValue(), TokenType.Argument); var argumentResult = new ArgumentResult( argument, implicitToken, parentCommandResult); parentCommandResult.Children.Add(argumentResult); parentCommandResult.AddToken(implicitToken); break; } } if (symbolResult is OptionResult o && o.Option.Argument.Type == typeof(bool) && o.Children.Count == 0) { o.Children.Add( new ArgumentResult( o.Option.Argument, new ImplicitToken(true, TokenType.Argument), o)); } }
private void PopulateDefaultValues() { var commandResults = _innermostCommandResult .RecurseWhileNotNull(c => c.Parent as CommandResult); foreach (var commandResult in commandResults) { foreach (var symbol in commandResult.Command.Children) { var symbolResult = _rootCommandResult.FindResultFor(symbol); if (symbolResult == null) { switch (symbol) { case Option option when option.Argument.HasDefaultValue: var optionResult = new OptionResult( option, option.CreateImplicitToken()); var token = new ImplicitToken( optionResult.GetDefaultValueFor(option.Argument), TokenType.Argument); optionResult.Children.Add( new ArgumentResult( option.Argument, token, optionResult)); commandResult.Children.Add(optionResult); optionResult.AddToken(token); _rootCommandResult.AddToSymbolMap(optionResult); break; case Argument argument when argument.HasDefaultValue: var implicitToken = new ImplicitToken(argument.GetDefaultValue(), TokenType.Argument); var argumentResult = new ArgumentResult( argument, implicitToken, commandResult); commandResult.Children.Add(argumentResult); commandResult.AddToken(implicitToken); _rootCommandResult.AddToSymbolMap(argumentResult); break; } } if (symbolResult is OptionResult o && o.Option.Argument.Type == typeof(bool) && o.Children.Count == 0) { o.Children.Add( new ArgumentResult( o.Option.Argument, new ImplicitToken(true, TokenType.Argument), o)); } } } }