@@ -18,6 +18,7 @@ use anyhow::Result;
18
18
use clap:: CommandFactory ;
19
19
use clap:: Parser ;
20
20
use std:: env;
21
+ use std:: ops:: Not ;
21
22
22
23
pub mod api;
23
24
pub mod args;
@@ -46,86 +47,87 @@ async fn main() -> Result<()> {
46
47
let style = & args. style ;
47
48
let rev = args. rev ;
48
49
let foe = args. fail_on_error ;
50
+ let quiet = args. quiet ;
49
51
50
52
match args {
51
53
_ if let Some ( pat) = parser:: login ( & args) => {
52
54
let cfg_path = session:: login ( pat) ;
53
55
foe. then ( ||panic_if_err ( & cfg_path) ) ;
54
- display:: login ( style, & cfg_path) ;
56
+ quiet . not ( ) . then ( || display:: login ( style, & cfg_path) ) ;
55
57
}
56
58
_ if parser:: logout ( & args) => {
57
59
let cfg_path = & session:: logout ( ) ;
58
60
foe. then ( ||panic_if_err ( cfg_path) ) ;
59
- display:: logout ( style, cfg_path) ;
61
+ quiet . not ( ) . then ( || display:: logout ( style, cfg_path) ) ;
60
62
}
61
63
_ if parser:: user_info ( & args) => {
62
64
let user_info = try {
63
65
User :: new ( pat?) . get_info ( ) . await ?
64
66
} ;
65
67
foe. then ( ||panic_if_err ( & user_info) ) ;
66
- display:: user_info ( style, & user_info) ;
68
+ quiet . not ( ) . then ( || display:: user_info ( style, & user_info) ) ;
67
69
}
68
70
_ if let Some ( ( skip, take) ) = parser:: list_ing ( & args) => {
69
71
let ing_type = IngType :: Public ;
70
72
let ing_vec = try {
71
73
Ing :: new ( pat?) . get_list ( skip, take, & ing_type) . await ?
72
74
} ;
73
75
foe. then ( ||panic_if_err ( & ing_vec) ) ;
74
- display:: list_ing ( style, & ing_vec, rev) ;
76
+ quiet . not ( ) . then ( || display:: list_ing ( style, & ing_vec, rev) ) ;
75
77
}
76
78
_ if let Some ( content) = parser:: publish_ing ( & args) => {
77
79
let content = try {
78
80
Ing :: new ( pat?) . publish ( content) . await ?;
79
81
content
80
82
} ;
81
83
foe. then ( ||panic_if_err ( & content) ) ;
82
- display:: publish_ing ( style, & content) ;
84
+ quiet . not ( ) . then ( || display:: publish_ing ( style, & content) ) ;
83
85
}
84
86
_ if let Some ( ( content, id) ) = parser:: comment_ing ( & args) => {
85
87
let content = try {
86
88
Ing :: new ( pat?) . comment ( id, content. clone ( ) , None , None ) . await ?;
87
89
content
88
90
} ;
89
91
foe. then ( ||panic_if_err ( & content) ) ;
90
- display:: comment_ing ( style, & content) ;
92
+ quiet . not ( ) . then ( || display:: comment_ing ( style, & content) ) ;
91
93
}
92
94
_ if let Some ( id) = parser:: show_post ( & args) => {
93
95
let entry = try { Post :: new ( pat?) . get_one ( id) . await ? } ;
94
96
foe. then ( ||panic_if_err ( & entry) ) ;
95
- display:: show_post ( style, & entry) ;
97
+ quiet . not ( ) . then ( || display:: show_post ( style, & entry) ) ;
96
98
}
97
99
_ if let Some ( id) = parser:: show_post_meta ( & args) => {
98
100
let entry = try { Post :: new ( pat?) . get_one ( id) . await ? } ;
99
101
foe. then ( ||panic_if_err ( & entry) ) ;
100
- display:: show_post_meta ( style, & entry) ;
102
+ quiet . not ( ) . then ( || display:: show_post_meta ( style, & entry) ) ;
101
103
}
102
104
_ if let Some ( ( skip, take) ) = parser:: list_post ( & args) => {
103
105
let result = try { Post :: new ( pat?) . get_meta_list ( skip, take) . await ? } ;
104
106
foe. then ( ||panic_if_err ( & result) ) ;
105
- display:: list_post ( style, & result, rev) ;
107
+ quiet . not ( ) . then ( || display:: list_post ( style, & result, rev) ) ;
106
108
}
107
109
_ if let Some ( id) = parser:: delete_post ( & args) => {
108
110
let id = try {
109
111
Post :: new ( pat?) . del_one ( id) . await ?;
110
112
id
111
113
} ;
112
114
foe. then ( ||panic_if_err ( & id) ) ;
113
- display:: delete_post ( style, & id) ;
115
+ quiet . not ( ) . then ( || display:: delete_post ( style, & id) ) ;
114
116
}
115
117
_ if let Some ( ( kw, skip, take) ) = parser:: search_post ( & args) => {
116
118
let result = try { Post :: new ( pat?) . search ( skip, take, kw) . await ? } ;
117
119
foe. then ( ||panic_if_err ( & result) ) ;
118
- display:: search_post ( style, & result, rev) ;
120
+ quiet . not ( ) . then ( || display:: search_post ( style, & result, rev) ) ;
119
121
}
120
122
_ if let Some ( ( title, body, publish) ) = parser:: create_post ( & args) => {
121
123
let id = try { Post :: new ( pat?) . create ( title, body, publish) . await ? } ;
122
124
foe. then ( ||panic_if_err ( & id) ) ;
123
- display:: create_post ( style, & id) ;
125
+ quiet . not ( ) . then ( || display:: create_post ( style, & id) ) ;
124
126
}
125
127
_ if let Some ( ( id, title, body, publish) ) = parser:: update_post ( & args) => {
126
128
let id = try { Post :: new ( pat?) . update ( id, title, body, publish) . await ? } ;
127
129
foe. then ( ||panic_if_err ( & id) ) ;
128
- display:: update_post ( style, & id) ;
130
+ quiet . not ( ) . then ( || display:: update_post ( style, & id) ) ;
129
131
}
130
132
131
133
_ if no_operation ( & args) => {
0 commit comments