public IEnumerable <string> Suggest(IShellState shellState, HttpState programState, ICoreParseResult parseResult) { if (parseResult.SelectedSection == 0 && (string.IsNullOrEmpty(parseResult.Sections[parseResult.SelectedSection]) || Name.StartsWith(parseResult.Sections[0].Substring(0, parseResult.CaretPositionWithinSelectedSection), StringComparison.OrdinalIgnoreCase))) { return(new[] { Name }); } if (parseResult.SelectedSection == 1 && string.Equals(parseResult.Sections[0], Name, StringComparison.OrdinalIgnoreCase)) { return(FileSystemCompletion.GetCompletions(parseResult.Sections[1].Substring(0, parseResult.CaretPositionWithinSelectedSection))); } return(null); }
protected override IEnumerable <string> GetOptionValueCompletions(IShellState shellState, HttpState programState, string optionId, DefaultCommandInput <ICoreParseResult> commandInput, ICoreParseResult parseResult, string normalizedCompletionText) { if (string.Equals(optionId, BodyFileOption, StringComparison.Ordinal) || string.Equals(optionId, ResponseFileOption, StringComparison.OrdinalIgnoreCase) || string.Equals(optionId, ResponseBodyFileOption, StringComparison.OrdinalIgnoreCase) || string.Equals(optionId, ResponseHeadersFileOption, StringComparison.OrdinalIgnoreCase)) { return(FileSystemCompletion.GetCompletions(normalizedCompletionText)); } if (string.Equals(optionId, HeaderOption, StringComparison.Ordinal)) { HashSet <string> alreadySpecifiedHeaders = new HashSet <string>(StringComparer.Ordinal); IReadOnlyList <InputElement> options = commandInput.Options[HeaderOption]; for (int i = 0; i < options.Count; ++i) { if (options[i] == commandInput.SelectedElement) { continue; } string elementText = options[i].Text; string existingHeaderName = elementText.Split(HeaderSeparatorChars)[0]; alreadySpecifiedHeaders.Add(existingHeaderName); } //Check to see if the selected element is in a header name or value int equalsIndex = normalizedCompletionText.IndexOfAny(HeaderSeparatorChars); string path = commandInput.Arguments.Count > 0 ? commandInput.Arguments[0].Text : string.Empty; if (equalsIndex < 0) { IEnumerable <string> headerNameOptions = HeaderCompletion.GetCompletions(alreadySpecifiedHeaders, normalizedCompletionText); List <string> allSuggestions = new List <string>(); foreach (string suggestion in headerNameOptions.Select(x => x)) { allSuggestions.Add(suggestion + ":"); IEnumerable <string> suggestions = HeaderCompletion.GetValueCompletions(Verb, path, suggestion, string.Empty, programState); if (suggestions != null) { foreach (string valueSuggestion in suggestions) { allSuggestions.Add(suggestion + ":" + valueSuggestion); } } } return(allSuggestions); } else { //Didn't exit from the header name check, so must be a value string headerName = normalizedCompletionText.Substring(0, equalsIndex); IEnumerable <string> suggestions = HeaderCompletion.GetValueCompletions(Verb, path, headerName, normalizedCompletionText.Substring(equalsIndex + 1), programState); if (suggestions == null) { return(null); } return(suggestions.Select(x => normalizedCompletionText.Substring(0, equalsIndex + 1) + x)); } } return(null); }