/// <summary> /// Binds option inputs in command instance. /// </summary> public static void BindOptions(this CommandSchema commandSchema, ICommand instance, IReadOnlyList <CommandOptionInput> optionInputs, IOptionFallbackProvider optionFallbackProvider) { IReadOnlyList <CommandOptionSchema> options = commandSchema.Options; // All inputs must be bound HashSet <CommandOptionInput> remainingOptionInputs = optionInputs.ToHashSet(); // All required options must be set HashSet <CommandOptionSchema> unsetRequiredOptions = options.Where(o => o.IsRequired) .ToHashSet(); // Direct or fallback input foreach (CommandOptionSchema option in options) { IEnumerable <CommandOptionInput> inputs = optionInputs.Where(i => option.MatchesNameOrShortName(i.Alias)); bool inputsProvided = inputs.Any(); // Check fallback value if (!inputsProvided && option.FallbackVariableName is string v && optionFallbackProvider.TryGetValue(v, option.Property !.PropertyType, out string?value)) { string[] values = option.IsScalar ? new[] { value ! } : value !.Split(Path.PathSeparator);
private void BindOptions(ICommand instance, IReadOnlyList <CommandOptionInput> optionInputs, IOptionFallbackProvider optionFallbackProvider) { // All inputs must be bound List <CommandOptionInput> remainingOptionInputs = optionInputs.ToList(); // All required options must be set List <CommandOptionSchema> unsetRequiredOptions = Options.Where(o => o.IsRequired) .ToList(); // Direct or fallback input foreach (CommandOptionSchema option in Options) { CommandOptionInput[] inputs = optionInputs.Where(i => option.MatchesNameOrShortName(i.Alias)) .ToArray(); bool inputsProvided = inputs.Any(); // Check fallback value if (!inputsProvided && option.FallbackVariableName is string v && optionFallbackProvider.TryGetValue(v, option.Property !.PropertyType, out string value)) { string[] values = option.IsScalar ? new[] { value } : value.Split(Path.PathSeparator); option.BindOn(instance, values); unsetRequiredOptions.Remove(option); continue; }
public BindInput(IOptionFallbackProvider optionFallbackProvider, ICliApplicationLifetime applicationLifetime) { _applicationLifetime = applicationLifetime; _optionFallbackProvider = optionFallbackProvider; }
public ExecuteCommand(IServiceProvider serviceProvider, IOptionFallbackProvider optionFallbackProvider) { _serviceProvider = serviceProvider; _optionFallbackProvider = optionFallbackProvider; }