aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-external-packages/src/symfony/console/completion/output/bash_completion_output.rs
blob: b781f5123d70f832fe093590e7639af26993433b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use crate::symfony::console::completion::completion_suggestions::CompletionSuggestions;
use crate::symfony::console::completion::output::completion_output_interface::CompletionOutputInterface;
use crate::symfony::console::output::output_interface::OutputInterface;

#[derive(Debug)]
pub struct BashCompletionOutput;

impl CompletionOutputInterface for BashCompletionOutput {
    fn write(&self, suggestions: &CompletionSuggestions, output: &dyn OutputInterface) {
        let mut values: Vec<String> = suggestions
            .get_value_suggestions()
            .iter()
            .map(|suggestion| suggestion.get_value())
            .collect();
        for option in suggestions.get_option_suggestions() {
            values.push(format!("--{}", option.get_name()));
            if option.is_negatable() {
                values.push(format!("--no-{}", option.get_name()));
            }
        }
        output.writeln(&[values.join("\n")], 0);
    }
}