blob: 2fb617ab7d3794c32649dce2a24d03e8212195fc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
//! ref: composer/vendor/symfony/console/Completion/CompletionSuggestions.php
use crate::symfony::console::completion::suggestion::Suggestion;
use crate::symfony::console::input::input_option::InputOption;
/// PHP union type `string|Suggestion` used by `suggestValue`/`suggestValues`.
#[derive(Debug)]
pub enum StringOrSuggestion {
String(String),
Suggestion(Suggestion),
}
/// Stores all completion suggestions for the current input.
#[derive(Debug)]
pub struct CompletionSuggestions {
value_suggestions: Vec<Suggestion>,
option_suggestions: Vec<InputOption>,
}
impl Default for CompletionSuggestions {
fn default() -> Self {
Self::new()
}
}
impl CompletionSuggestions {
pub fn new() -> Self {
Self {
value_suggestions: vec![],
option_suggestions: vec![],
}
}
/// Add a suggested value for an input option or argument.
pub fn suggest_value(&mut self, value: StringOrSuggestion) -> &mut Self {
self.value_suggestions.push(match value {
StringOrSuggestion::Suggestion(value) => value,
StringOrSuggestion::String(value) => Suggestion::new(value),
});
self
}
/// Add multiple suggested values at once for an input option or argument.
pub fn suggest_values(&mut self, values: Vec<StringOrSuggestion>) -> &mut Self {
for value in values {
self.suggest_value(value);
}
self
}
/// Add a suggestion for an input option name.
pub fn suggest_option(&mut self, option: InputOption) -> &mut Self {
self.option_suggestions.push(option);
self
}
/// Add multiple suggestions for input option names at once.
pub fn suggest_options(&mut self, options: Vec<InputOption>) -> &mut Self {
for option in options {
self.suggest_option(option);
}
self
}
pub fn get_option_suggestions(&self) -> &Vec<InputOption> {
&self.option_suggestions
}
pub fn get_value_suggestions(&self) -> &Vec<Suggestion> {
&self.value_suggestions
}
}
|