aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/io/null_io.rs
blob: b0e11f1451ce17fd48bc4ea8d9548f1bb6ee9c47 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//! ref: composer/src/Composer/IO/NullIO.php

use crate::io::BaseIO;
use crate::io::IOInterface;
use crate::io::IOInterfaceImmutable;
use crate::io::IOInterfaceMutable;
use shirabe_php_shim::PhpMixed;

#[derive(Debug)]
pub struct NullIO {
    authentications: indexmap::IndexMap<String, indexmap::IndexMap<String, Option<String>>>,
}

impl NullIO {
    pub fn new() -> Self {
        Self {
            authentications: indexmap::IndexMap::new(),
        }
    }
}

impl IOInterfaceImmutable for NullIO {
    fn is_interactive(&self) -> bool {
        false
    }

    fn is_verbose(&self) -> bool {
        false
    }

    fn is_very_verbose(&self) -> bool {
        false
    }

    fn is_debug(&self) -> bool {
        false
    }

    fn is_decorated(&self) -> bool {
        false
    }

    fn write3(&self, _message: &str, _newline: bool, _verbosity: i64) {}

    fn write_error3(&self, _message: &str, _newline: bool, _verbosity: i64) {}

    fn write_raw3(&self, _message: &str, _newline: bool, _verbosity: i64) {}

    fn write_error_raw3(&self, _message: &str, _newline: bool, _verbosity: i64) {}

    fn overwrite4(&self, _message: &str, _newline: bool, _size: Option<i64>, _verbosity: i64) {}

    fn overwrite_error4(
        &self,
        _message: &str,
        _newline: bool,
        _size: Option<i64>,
        _verbosity: i64,
    ) {
    }

    fn ask(&self, _question: String, default: PhpMixed) -> PhpMixed {
        default
    }

    fn ask_confirmation(&self, _question: String, default: bool) -> bool {
        default
    }

    fn ask_and_validate(
        &self,
        _question: String,
        _validator: Box<dyn Fn(PhpMixed) -> PhpMixed>,
        _attempts: Option<i64>,
        default: PhpMixed,
    ) -> PhpMixed {
        default
    }

    fn ask_and_hide_answer(&self, _question: String) -> Option<String> {
        None
    }

    fn select(
        &self,
        _question: String,
        _choices: Vec<String>,
        default: PhpMixed,
        _attempts: PhpMixed,
        _error_message: String,
        _multiselect: bool,
    ) -> PhpMixed {
        default
    }

    fn get_authentications(
        &self,
    ) -> indexmap::IndexMap<String, indexmap::IndexMap<String, Option<String>>> {
        <Self as BaseIO>::get_authentications(self)
    }

    fn has_authentication(&self, repository_name: &str) -> bool {
        <Self as BaseIO>::has_authentication(self, repository_name)
    }

    fn get_authentication(
        &self,
        repository_name: &str,
    ) -> indexmap::IndexMap<String, Option<String>> {
        <Self as BaseIO>::get_authentication(self, repository_name)
    }

    fn error(&self, _message: &str, _context: &[(&str, &str)]) {
        todo!()
    }

    fn warning(&self, _message: &str, _context: &[(&str, &str)]) {
        todo!()
    }

    fn debug(&self, _message: &str, _context: &[(&str, &str)]) {
        todo!()
    }
}

impl IOInterfaceMutable for NullIO {
    fn set_authentication(
        &mut self,
        repository_name: String,
        username: String,
        password: Option<String>,
    ) {
        <Self as BaseIO>::set_authentication(self, repository_name, username, password)
    }

    fn load_configuration(&mut self, config: &mut crate::config::Config) -> anyhow::Result<()> {
        <Self as BaseIO>::load_configuration(self, config)
    }
}

impl IOInterface for NullIO {}

impl BaseIO for NullIO {
    fn authentications(
        &self,
    ) -> &indexmap::IndexMap<String, indexmap::IndexMap<String, Option<String>>> {
        &self.authentications
    }

    fn authentications_mut(
        &mut self,
    ) -> &mut indexmap::IndexMap<String, indexmap::IndexMap<String, Option<String>>> {
        &mut self.authentications
    }
}