@@ -24,6 +24,12 @@ pub mod args;
24
24
pub mod display;
25
25
pub mod infra;
26
26
27
+ fn panic_if_err < T > ( result : & Result < T > ) {
28
+ if let Err ( e) = result {
29
+ panic ! ( "{}" , e)
30
+ }
31
+ }
32
+
27
33
#[ tokio:: main( flavor = "multi_thread" ) ]
28
34
async fn main ( ) -> Result < ( ) > {
29
35
let args_vec = env:: args ( ) . collect :: < Vec < _ > > ( ) ;
@@ -39,74 +45,86 @@ async fn main() -> Result<()> {
39
45
let pat = args. with_pat . clone ( ) . or_eval_result ( session:: get_pat) ;
40
46
let style = & args. style ;
41
47
let rev = args. rev ;
42
- // TODO
43
- let _fail_on_error = args. fail_on_error ;
48
+ let foe = args. fail_on_error ;
44
49
45
50
match args {
46
51
_ if let Some ( pat) = parser:: login ( & args) => {
47
52
let cfg_path = session:: login ( pat) ;
53
+ foe. then ( ||panic_if_err ( & cfg_path) ) ;
48
54
display:: login ( style, & cfg_path) ;
49
55
}
50
56
_ if parser:: logout ( & args) => {
51
- let cfg_path = session:: logout ( ) ;
52
- display:: logout ( style, & cfg_path) ;
57
+ let cfg_path = & session:: logout ( ) ;
58
+ foe. then ( ||panic_if_err ( cfg_path) ) ;
59
+ display:: logout ( style, cfg_path) ;
53
60
}
54
61
_ if parser:: user_info ( & args) => {
55
62
let user_info = try {
56
63
User :: new ( pat?) . get_info ( ) . await ?
57
64
} ;
65
+ foe. then ( ||panic_if_err ( & user_info) ) ;
58
66
display:: user_info ( style, & user_info) ;
59
67
}
60
68
_ if let Some ( ( skip, take) ) = parser:: list_ing ( & args) => {
61
69
let ing_type = IngType :: Public ;
62
70
let ing_vec = try {
63
71
Ing :: new ( pat?) . get_list ( skip, take, & ing_type) . await ?
64
72
} ;
73
+ foe. then ( ||panic_if_err ( & ing_vec) ) ;
65
74
display:: list_ing ( style, & ing_vec, rev) ;
66
75
}
67
76
_ if let Some ( content) = parser:: publish_ing ( & args) => {
68
77
let content = try {
69
78
Ing :: new ( pat?) . publish ( content) . await ?;
70
79
content
71
80
} ;
81
+ foe. then ( ||panic_if_err ( & content) ) ;
72
82
display:: publish_ing ( style, & content) ;
73
83
}
74
84
_ if let Some ( ( content, id) ) = parser:: comment_ing ( & args) => {
75
85
let content = try {
76
86
Ing :: new ( pat?) . comment ( id, content. clone ( ) , None , None ) . await ?;
77
87
content
78
88
} ;
89
+ foe. then ( ||panic_if_err ( & content) ) ;
79
90
display:: comment_ing ( style, & content) ;
80
91
}
81
92
_ if let Some ( id) = parser:: show_post ( & args) => {
82
93
let entry = try { Post :: new ( pat?) . get_one ( id) . await ? } ;
94
+ foe. then ( ||panic_if_err ( & entry) ) ;
83
95
display:: show_post ( style, & entry) ;
84
96
}
85
97
_ if let Some ( id) = parser:: show_post_meta ( & args) => {
86
98
let entry = try { Post :: new ( pat?) . get_one ( id) . await ? } ;
99
+ foe. then ( ||panic_if_err ( & entry) ) ;
87
100
display:: show_post_meta ( style, & entry) ;
88
101
}
89
102
_ if let Some ( ( skip, take) ) = parser:: list_post ( & args) => {
90
103
let result = try { Post :: new ( pat?) . get_meta_list ( skip, take) . await ? } ;
104
+ foe. then ( ||panic_if_err ( & result) ) ;
91
105
display:: list_post ( style, & result, rev) ;
92
106
}
93
107
_ if let Some ( id) = parser:: delete_post ( & args) => {
94
108
let id = try {
95
109
Post :: new ( pat?) . del_one ( id) . await ?;
96
110
id
97
111
} ;
112
+ foe. then ( ||panic_if_err ( & id) ) ;
98
113
display:: delete_post ( style, & id) ;
99
114
}
100
115
_ if let Some ( ( kw, skip, take) ) = parser:: search_post ( & args) => {
101
116
let result = try { Post :: new ( pat?) . search ( skip, take, kw) . await ? } ;
117
+ foe. then ( ||panic_if_err ( & result) ) ;
102
118
display:: search_post ( style, & result, rev) ;
103
119
}
104
120
_ if let Some ( ( title, body, publish) ) = parser:: create_post ( & args) => {
105
121
let id = try { Post :: new ( pat?) . create ( title, body, publish) . await ? } ;
122
+ foe. then ( ||panic_if_err ( & id) ) ;
106
123
display:: create_post ( style, & id) ;
107
124
}
108
125
_ if let Some ( ( id, title, body, publish) ) = parser:: update_post ( & args) => {
109
126
let id = try { Post :: new ( pat?) . update ( id, title, body, publish) . await ? } ;
127
+ foe. then ( ||panic_if_err ( & id) ) ;
110
128
display:: update_post ( style, & id) ;
111
129
}
112
130
0 commit comments