@@ -35,18 +35,18 @@ pub struct Config {
3535}
3636
3737impl Config {
38- pub fn load_config ( ) -> Result < Self > {
38+ pub fn load_config ( ) -> Self {
3939 if let Some ( config_file) = config_file_path ( ) {
4040 if config_file. exists ( ) {
4141 if let Ok ( config_str) = read_to_string ( config_file) {
4242 if let Ok ( config) = serde_json:: from_str :: < Self > ( & config_str) {
43- return Ok ( config) ;
43+ return config;
4444 }
4545 }
4646 }
4747 } ;
4848
49- Ok ( Self :: default ( ) )
49+ Self :: default ( )
5050 }
5151
5252 pub fn reset ( ) -> Result < ( ) > {
@@ -82,89 +82,65 @@ impl Config {
8282 }
8383
8484 pub fn save_creator ( value : String ) -> Result < ( ) > {
85- if let Ok ( mut config) = Config :: load_config ( ) {
86- config. creator = Some ( value) ;
87- config. save ( ) ?;
88- } else {
89- raise_error ( ) ?;
90- }
85+ let mut config = Config :: load_config ( ) ;
86+ config. creator = Some ( value) ;
87+ config. save ( ) ?;
9188
9289 Ok ( ( ) )
9390 }
9491
9592 pub fn save_creator_email ( value : String ) -> Result < ( ) > {
96- if let Ok ( mut config) = Config :: load_config ( ) {
97- config. creator_email = Some ( value) ;
98- config. save ( ) ?;
99- } else {
100- raise_error ( ) ?;
101- }
93+ let mut config = Config :: load_config ( ) ;
94+ config. creator_email = Some ( value) ;
95+ config. save ( ) ?;
10296
10397 Ok ( ( ) )
10498 }
10599
106100 pub fn save_license ( value : LicenseType ) -> Result < ( ) > {
107- if let Ok ( mut config) = Config :: load_config ( ) {
108- config. license = Some ( value) ;
109- config. save ( ) ?;
110- } else {
111- raise_error ( ) ?;
112- }
101+ let mut config = Config :: load_config ( ) ;
102+ config. license = Some ( value) ;
103+ config. save ( ) ?;
113104
114105 Ok ( ( ) )
115106 }
116107
117108 pub fn save_python_version ( value : String ) -> Result < ( ) > {
118- if let Ok ( mut config) = Config :: load_config ( ) {
119- config. python_version = Some ( value) ;
120- config. save ( ) ?;
121- } else {
122- raise_error ( ) ?;
123- }
109+ let mut config = Config :: load_config ( ) ;
110+ config. python_version = Some ( value) ;
111+ config. save ( ) ?;
124112
125113 Ok ( ( ) )
126114 }
127115
128116 pub fn save_min_python_version ( value : String ) -> Result < ( ) > {
129- if let Ok ( mut config) = Config :: load_config ( ) {
130- config. min_python_version = Some ( value) ;
131- config. save ( ) ?;
132- } else {
133- raise_error ( ) ?;
134- }
117+ let mut config = Config :: load_config ( ) ;
118+ config. min_python_version = Some ( value) ;
119+ config. save ( ) ?;
135120
136121 Ok ( ( ) )
137122 }
138123
139124 pub fn save_project_manager ( value : ProjectManager ) -> Result < ( ) > {
140- if let Ok ( mut config) = Config :: load_config ( ) {
141- config. project_manager = Some ( value) ;
142- config. save ( ) ?;
143- } else {
144- raise_error ( ) ?;
145- }
125+ let mut config = Config :: load_config ( ) ;
126+ config. project_manager = Some ( value) ;
127+ config. save ( ) ?;
146128
147129 Ok ( ( ) )
148130 }
149131
150132 pub fn save_is_async_project ( value : bool ) -> Result < ( ) > {
151- if let Ok ( mut config) = Config :: load_config ( ) {
152- config. is_async_project = Some ( value) ;
153- config. save ( ) ?;
154- } else {
155- raise_error ( ) ?;
156- }
133+ let mut config = Config :: load_config ( ) ;
134+ config. is_async_project = Some ( value) ;
135+ config. save ( ) ?;
157136
158137 Ok ( ( ) )
159138 }
160139
161140 pub fn save_is_application ( value : bool ) -> Result < ( ) > {
162- if let Ok ( mut config) = Config :: load_config ( ) {
163- config. is_application = Some ( value) ;
164- config. save ( ) ?;
165- } else {
166- raise_error ( ) ?;
167- }
141+ let mut config = Config :: load_config ( ) ;
142+ config. is_application = Some ( value) ;
143+ config. save ( ) ?;
168144
169145 Ok ( ( ) )
170146 }
@@ -182,117 +158,87 @@ impl Config {
182158 }
183159 }
184160
185- if let Ok ( mut config) = Config :: load_config ( ) {
186- config. github_actions_python_test_versions = Some ( versions) ;
187- config. save ( ) ?;
188- } else {
189- raise_error ( ) ?;
190- }
161+ let mut config = Config :: load_config ( ) ;
162+ config. github_actions_python_test_versions = Some ( versions) ;
163+ config. save ( ) ?;
191164
192165 Ok ( ( ) )
193166 }
194167
195168 pub fn save_max_line_length ( value : u8 ) -> Result < ( ) > {
196- if let Ok ( mut config) = Config :: load_config ( ) {
197- config. max_line_length = Some ( value) ;
198- config. save ( ) ?;
199- } else {
200- raise_error ( ) ?;
201- }
169+ let mut config = Config :: load_config ( ) ;
170+ config. max_line_length = Some ( value) ;
171+ config. save ( ) ?;
202172
203173 Ok ( ( ) )
204174 }
205175
206176 pub fn save_use_dependabot ( value : bool ) -> Result < ( ) > {
207- if let Ok ( mut config) = Config :: load_config ( ) {
208- config. use_dependabot = Some ( value) ;
209- config. save ( ) ?;
210- } else {
211- raise_error ( ) ?;
212- }
177+ let mut config = Config :: load_config ( ) ;
178+ config. use_dependabot = Some ( value) ;
179+ config. save ( ) ?;
213180
214181 Ok ( ( ) )
215182 }
216183
217184 pub fn save_dependabot_schedule ( value : DependabotSchedule ) -> Result < ( ) > {
218- if let Ok ( mut config) = Config :: load_config ( ) {
219- config. dependabot_schedule = Some ( value) ;
220- config. save ( ) ?;
221- } else {
222- raise_error ( ) ?;
223- }
185+ let mut config = Config :: load_config ( ) ;
186+ config. dependabot_schedule = Some ( value) ;
187+ config. save ( ) ?;
224188
225189 Ok ( ( ) )
226190 }
227191
228192 pub fn save_dependabot_day ( value : Day ) -> Result < ( ) > {
229- if let Ok ( mut config) = Config :: load_config ( ) {
230- config. dependabot_day = Some ( value) ;
231- config. save ( ) ?;
232- } else {
233- raise_error ( ) ?;
234- }
193+ let mut config = Config :: load_config ( ) ;
194+ config. dependabot_day = Some ( value) ;
195+ config. save ( ) ?;
235196
236197 Ok ( ( ) )
237198 }
238199
239200 pub fn save_use_continuous_deployment ( value : bool ) -> Result < ( ) > {
240- if let Ok ( mut config) = Config :: load_config ( ) {
241- config. use_continuous_deployment = Some ( value) ;
242- config. save ( ) ?;
243- } else {
244- raise_error ( ) ?;
245- }
201+ let mut config = Config :: load_config ( ) ;
202+ config. use_continuous_deployment = Some ( value) ;
203+ config. save ( ) ?;
246204
247205 Ok ( ( ) )
248206 }
249207
250208 pub fn save_use_release_drafter ( value : bool ) -> Result < ( ) > {
251- if let Ok ( mut config) = Config :: load_config ( ) {
252- config. use_release_drafter = Some ( value) ;
253- config. save ( ) ?;
254- } else {
255- raise_error ( ) ?;
256- }
209+ let mut config = Config :: load_config ( ) ;
210+ config. use_release_drafter = Some ( value) ;
211+ config. save ( ) ?;
257212
258213 Ok ( ( ) )
259214 }
260215
261216 pub fn save_use_multi_os_ci ( value : bool ) -> Result < ( ) > {
262- if let Ok ( mut config) = Config :: load_config ( ) {
263- config. use_multi_os_ci = Some ( value) ;
264- config. save ( ) ?;
265- } else {
266- raise_error ( ) ?;
267- }
217+ let mut config = Config :: load_config ( ) ;
218+ config. use_multi_os_ci = Some ( value) ;
219+ config. save ( ) ?;
268220
269221 Ok ( ( ) )
270222 }
271223
272224 pub fn save_include_docs ( value : bool ) -> Result < ( ) > {
273- if let Ok ( mut config) = Config :: load_config ( ) {
274- config. include_docs = Some ( value) ;
275- config. save ( ) ?;
276- } else {
277- raise_error ( ) ?;
278- }
225+ let mut config = Config :: load_config ( ) ;
226+ config. include_docs = Some ( value) ;
227+ config. save ( ) ?;
279228
280229 Ok ( ( ) )
281230 }
282231
283232 pub fn save_download_latest_packages ( value : bool ) -> Result < ( ) > {
284- if let Ok ( mut config) = Config :: load_config ( ) {
285- config. download_latest_packages = Some ( value) ;
286- config. save ( ) ?;
287- } else {
288- raise_error ( ) ?;
289- }
233+ let mut config = Config :: load_config ( ) ;
234+ config. download_latest_packages = Some ( value) ;
235+ config. save ( ) ?;
290236
291237 Ok ( ( ) )
292238 }
293239
294240 pub fn show ( ) {
295- let config = Config :: load_config ( ) . unwrap_or_default ( ) ;
241+ let config = Config :: load_config ( ) ;
296242 print_config_value ( "Creator" , & config. creator ) ;
297243 print_config_value ( "Creator Email" , & config. creator_email ) ;
298244 print_config_value ( "License" , & config. license ) ;
@@ -355,10 +301,6 @@ fn config_file_path() -> Option<PathBuf> {
355301 None
356302}
357303
358- fn raise_error ( ) -> Result < ( ) > {
359- bail ! ( "Error saving config" )
360- }
361-
362304fn print_config_value < T : Display > ( label : & str , value : & Option < T > ) {
363305 if let Some ( v) = value {
364306 println ! ( "{}: {}" , label. blue( ) , v) ;
0 commit comments