1use crate::{
2 application::{Application, Authenticator, Cache, Clock, Config},
3 client::{github::GithubClient, synd_api::Client},
4 config::Categories,
5 interact::Interact,
6 terminal::Terminal,
7 ui::theme::Theme,
8};
9
10pub struct ApplicationBuilder<
11 Terminal = (),
12 Client = (),
13 Categories = (),
14 Cache = (),
15 Config = (),
16 Theme = (),
17 Interactor = (),
18> {
19 pub(super) terminal: Terminal,
20 pub(super) client: Client,
21 pub(super) categories: Categories,
22 pub(super) cache: Cache,
23 pub(super) config: Config,
24 pub(super) theme: Theme,
25 pub(super) interactor: Interactor,
26
27 pub(super) authenticator: Option<Authenticator>,
28 pub(super) github_client: Option<GithubClient>,
29 pub(super) clock: Option<Box<dyn Clock>>,
30 pub(super) dry_run: bool,
31}
32
33impl Default for ApplicationBuilder {
34 fn default() -> Self {
35 Self {
36 terminal: (),
37 client: (),
38 categories: (),
39 cache: (),
40 config: (),
41 theme: (),
42 interactor: (),
43 authenticator: None,
44 github_client: None,
45 clock: None,
46 dry_run: false,
47 }
48 }
49}
50
51impl<T1, T2, T3, T4, T5, T6> ApplicationBuilder<(), T1, T2, T3, T4, T5, T6> {
52 #[must_use]
53 pub fn terminal(
54 self,
55 terminal: Terminal,
56 ) -> ApplicationBuilder<Terminal, T1, T2, T3, T4, T5, T6> {
57 ApplicationBuilder {
58 terminal,
59 client: self.client,
60 categories: self.categories,
61 cache: self.cache,
62 config: self.config,
63 theme: self.theme,
64 interactor: self.interactor,
65 authenticator: self.authenticator,
66 github_client: self.github_client,
67 clock: self.clock,
68 dry_run: self.dry_run,
69 }
70 }
71}
72
73impl<T1, T2, T3, T4, T5, T6> ApplicationBuilder<T1, (), T2, T3, T4, T5, T6> {
74 #[must_use]
75 pub fn client(self, client: Client) -> ApplicationBuilder<T1, Client, T2, T3, T4, T5, T6> {
76 ApplicationBuilder {
77 terminal: self.terminal,
78 client,
79 categories: self.categories,
80 cache: self.cache,
81 config: self.config,
82 theme: self.theme,
83 interactor: self.interactor,
84 authenticator: self.authenticator,
85 github_client: self.github_client,
86 clock: self.clock,
87 dry_run: self.dry_run,
88 }
89 }
90}
91
92impl<T1, T2, T3, T4, T5, T6> ApplicationBuilder<T1, T2, (), T3, T4, T5, T6> {
93 #[must_use]
94 pub fn categories(
95 self,
96 categories: Categories,
97 ) -> ApplicationBuilder<T1, T2, Categories, T3, T4, T5, T6> {
98 ApplicationBuilder {
99 terminal: self.terminal,
100 client: self.client,
101 categories,
102 cache: self.cache,
103 config: self.config,
104 theme: self.theme,
105 interactor: self.interactor,
106 authenticator: self.authenticator,
107 github_client: self.github_client,
108 clock: self.clock,
109 dry_run: self.dry_run,
110 }
111 }
112}
113
114impl<T1, T2, T3, T4, T5, T6> ApplicationBuilder<T1, T2, T3, (), T4, T5, T6> {
115 #[must_use]
116 pub fn cache(self, cache: Cache) -> ApplicationBuilder<T1, T2, T3, Cache, T4, T5, T6> {
117 ApplicationBuilder {
118 terminal: self.terminal,
119 client: self.client,
120 categories: self.categories,
121 cache,
122 config: self.config,
123 theme: self.theme,
124 interactor: self.interactor,
125 authenticator: self.authenticator,
126 github_client: self.github_client,
127 clock: self.clock,
128 dry_run: self.dry_run,
129 }
130 }
131}
132
133impl<T1, T2, T3, T4, T5, T6> ApplicationBuilder<T1, T2, T3, T4, (), T5, T6> {
134 #[must_use]
135 pub fn config(self, config: Config) -> ApplicationBuilder<T1, T2, T3, T4, Config, T5, T6> {
136 ApplicationBuilder {
137 terminal: self.terminal,
138 client: self.client,
139 categories: self.categories,
140 cache: self.cache,
141 config,
142 theme: self.theme,
143 interactor: self.interactor,
144 authenticator: self.authenticator,
145 github_client: self.github_client,
146 clock: self.clock,
147 dry_run: self.dry_run,
148 }
149 }
150}
151
152impl<T1, T2, T3, T4, T5, T6> ApplicationBuilder<T1, T2, T3, T4, T5, (), T6> {
153 #[must_use]
154 pub fn theme(self, theme: Theme) -> ApplicationBuilder<T1, T2, T3, T4, T5, Theme, T6> {
155 ApplicationBuilder {
156 terminal: self.terminal,
157 client: self.client,
158 categories: self.categories,
159 cache: self.cache,
160 config: self.config,
161 theme,
162 interactor: self.interactor,
163 authenticator: self.authenticator,
164 github_client: self.github_client,
165 clock: self.clock,
166 dry_run: self.dry_run,
167 }
168 }
169}
170
171impl<T1, T2, T3, T4, T5, T6> ApplicationBuilder<T1, T2, T3, T4, T5, T6, ()> {
172 #[must_use]
173 pub fn interactor(
174 self,
175 interactor: Box<dyn Interact>,
176 ) -> ApplicationBuilder<T1, T2, T3, T4, T5, T6, Box<dyn Interact>> {
177 ApplicationBuilder {
178 terminal: self.terminal,
179 client: self.client,
180 categories: self.categories,
181 cache: self.cache,
182 config: self.config,
183 theme: self.theme,
184 interactor,
185 authenticator: self.authenticator,
186 github_client: self.github_client,
187 clock: self.clock,
188 dry_run: self.dry_run,
189 }
190 }
191}
192
193impl<T1, T2, T3, T4, T5, T6, T7> ApplicationBuilder<T1, T2, T3, T4, T5, T6, T7> {
194 #[must_use]
195 pub fn authenticator(self, authenticator: Authenticator) -> Self {
196 Self {
197 authenticator: Some(authenticator),
198 ..self
199 }
200 }
201
202 #[must_use]
203 pub fn github_client(self, github_client: GithubClient) -> Self {
204 Self {
205 github_client: Some(github_client),
206 ..self
207 }
208 }
209
210 #[must_use]
211 pub fn clock(self, clock: Box<dyn Clock>) -> Self {
212 Self {
213 clock: Some(clock),
214 ..self
215 }
216 }
217
218 #[must_use]
219 pub fn dry_run(self, dry_run: bool) -> Self {
220 Self { dry_run, ..self }
221 }
222}
223
224impl ApplicationBuilder<Terminal, Client, Categories, Cache, Config, Theme, Box<dyn Interact>> {
225 #[must_use]
226 pub fn build(self) -> Application {
227 Application::new(self)
228 }
229}