@@ -4,59 +4,58 @@ mod cli;
44mod config;
55mod error;
66mod image;
7+ mod result;
78mod runtime;
89mod user_data;
9- mod result;
1010mod util;
1111
12- use error:: AppError ;
13- use cli:: Args ;
1412use clap:: Parser ;
13+ use cli:: Args ;
1514use config:: Config ;
16- use runtime:: Runtime ;
17- use result:: * ;
18-
15+ use error:: AppError ;
1916use image:: Image ;
20-
17+ use result:: * ;
18+ use runtime:: Runtime ;
2119use std:: { env:: set_current_dir, process} ;
20+ use tracing_subscriber:: EnvFilter ;
21+
22+ fn mainmain ( ) -> Result < ( ) , AppError > {
23+ let trace_format = tracing_subscriber:: fmt:: format ( )
24+ . without_time ( )
25+ . pretty ( ) ;
26+ let trace_filter = EnvFilter :: from_default_env ( ) ;
27+ tracing_subscriber:: fmt ( )
28+ . event_format ( trace_format)
29+ . with_env_filter ( trace_filter)
30+ . init ( ) ;
2231
23- fn main ( ) {
2432 let args = Args :: parse ( ) ;
2533
26- match & args. command {
27- Some ( c) => {
28- question_mark ( c. run ( & args) ) ;
29- process:: exit ( 0 )
30- }
31- None => { }
32- }
34+ if let Some ( c) = & args. command { return c. run ( & args) }
3335
3436 // TODO make dir if nonexistent? populate with default config?
3537 if let Err ( e) = set_current_dir ( config:: config_dir ( ) ) {
36- println ! ( "Failed to open configuration directory {}:\n {}" , config:: config_dir( ) , e) ;
37- process:: exit ( 1 )
38+ return Err ( AppError :: Runtime (
39+ format ! ( "Failed to open configuration directory {}:\n {}" , config:: config_dir( ) , e)
40+ ) )
3841 }
3942
40- let config = question_mark ( Config :: parse ( ) ) ;
41- let runtime = question_mark ( Runtime :: from_config ( config ) ) ;
43+ let runtime = Runtime :: from_config ( Config :: parse ( ) ? ) ? ;
44+ let path = runtime . save_path ( & args . path ) ;
4245
43- let result = ResultAnchors :: new ( & runtime) ;
44- let result = question_mark ( result . to_tiles ( & runtime) ) ;
45- let result = result . to_infos ( ) ;
46- let result = question_mark ( result . to_colors ( & runtime) ) ;
47- let result = result . finalize ( ) ;
46+ let result = ResultAnchors :: new ( & runtime)
47+ . to_tiles ( & runtime) ?
48+ . to_infos ( )
49+ . to_colors ( & runtime) ?
50+ . finalize ( ) ;
4851
49- let path = runtime. save_path ( & args. path ) ;
50- question_mark ( result. save ( & path) ) ;
52+ result. save ( & path)
5153}
5254
53- fn question_mark < T > ( input : Result < T , AppError > ) -> T {
54- match input {
55- Ok ( result) => result,
56- Err ( e) => {
57- println ! ( "{}" , e) ;
58- process:: exit ( 1 )
59- }
60- }
61- }
55+ fn main ( ) {
56+ if let Err ( err) = mainmain ( ) {
57+ println ! ( "{err}" ) ;
6258
59+ process:: exit ( 1 )
60+ }
61+ }
0 commit comments