@@ -14,12 +14,8 @@ use crate::cmd::CoffeeArgs;
14
14
use crate :: cmd:: CoffeeCommand ;
15
15
use crate :: cmd:: RemoteAction ;
16
16
17
- #[ tokio:: main]
18
- async fn main ( ) -> Result < ( ) , CoffeeError > {
19
- env_logger:: init ( ) ;
20
- let args = CoffeeArgs :: parse ( ) ;
21
- let mut coffee = CoffeeManager :: new ( & args) . await ?;
22
- let result = match args. command {
17
+ async fn run ( args : CoffeeArgs , mut coffee : CoffeeManager ) -> Result < ( ) , CoffeeError > {
18
+ match args. command {
23
19
CoffeeCommand :: Install {
24
20
plugin,
25
21
verbose,
@@ -40,7 +36,6 @@ async fn main() -> Result<(), CoffeeError> {
40
36
} else if result. is_ok ( ) {
41
37
term:: success!( "Plugin {plugin} Compiled and Installed" )
42
38
}
43
- result
44
39
}
45
40
CoffeeCommand :: Remove { plugin } => {
46
41
let mut spinner = term:: spinner ( format ! ( "Uninstalling plugin {plugin}" ) ) ;
@@ -51,11 +46,10 @@ async fn main() -> Result<(), CoffeeError> {
51
46
}
52
47
spinner. message ( "Plugin uninstalled!" ) ;
53
48
spinner. finish ( ) ;
54
- Ok ( ( ) )
55
49
}
56
50
CoffeeCommand :: List { } => {
57
51
let remotes = coffee. list ( ) . await ;
58
- coffee_term:: show_list ( remotes)
52
+ coffee_term:: show_list ( remotes) ? ;
59
53
}
60
54
CoffeeCommand :: Upgrade { repo, verbose } => {
61
55
let spinner = if !verbose {
@@ -83,7 +77,6 @@ async fn main() -> Result<(), CoffeeError> {
83
77
return Err ( err) ;
84
78
}
85
79
}
86
- Ok ( ( ) )
87
80
}
88
81
CoffeeCommand :: Remote {
89
82
action,
@@ -92,7 +85,7 @@ async fn main() -> Result<(), CoffeeError> {
92
85
} => {
93
86
if plugins {
94
87
let result = coffee. get_plugins_in_remote ( & name. unwrap ( ) ) . await ;
95
- coffee_term:: show_list ( result)
88
+ coffee_term:: show_list ( result) ? ;
96
89
} else {
97
90
match action {
98
91
Some ( RemoteAction :: Add { name, url } ) => {
@@ -104,7 +97,6 @@ async fn main() -> Result<(), CoffeeError> {
104
97
}
105
98
spinner. message ( "Remote added!" ) ;
106
99
spinner. finish ( ) ;
107
- Ok ( ( ) )
108
100
}
109
101
Some ( RemoteAction :: Rm { name } ) => {
110
102
let mut spinner = term:: spinner ( format ! ( "Removing remote {name}" ) ) ;
@@ -115,11 +107,10 @@ async fn main() -> Result<(), CoffeeError> {
115
107
}
116
108
spinner. message ( "Remote removed!" ) ;
117
109
spinner. finish ( ) ;
118
- Ok ( ( ) )
119
110
}
120
111
Some ( RemoteAction :: List { } ) => {
121
112
let remotes = coffee. list_remotes ( ) . await ;
122
- coffee_term:: show_remote_list ( remotes)
113
+ coffee_term:: show_remote_list ( remotes) ? ;
123
114
}
124
115
None => {
125
116
// This is the case when the user does not provides the
@@ -144,51 +135,51 @@ async fn main() -> Result<(), CoffeeError> {
144
135
let remote = Ok ( CoffeeRemote {
145
136
remotes : Some ( vec ! [ remote. clone( ) ] ) ,
146
137
} ) ;
147
- coffee_term:: show_remote_list ( remote)
138
+ coffee_term:: show_remote_list ( remote) ? ;
148
139
}
149
140
}
150
141
}
151
142
}
152
143
CoffeeCommand :: Setup { cln_conf } => {
153
144
// FIXME: read the core lightning config
154
145
// and the coffee script
155
- coffee. setup ( & cln_conf) . await
146
+ coffee. setup ( & cln_conf) . await ?;
147
+ }
148
+ CoffeeCommand :: Show { plugin } => {
149
+ let val = coffee. show ( & plugin) . await ?;
150
+
151
+ // FIXME: modify the radicle_term markdown
152
+ let val = val. readme . as_str ( ) ;
153
+ term:: markdown ( val) ;
154
+ }
155
+ CoffeeCommand :: Search { plugin } => {
156
+ let val = coffee. search ( & plugin) . await ?;
157
+ let repository_url = val. repository_url . as_str ( ) ;
158
+ term:: success!( "found plugin {plugin} in remote repository {repository_url}" ) ;
156
159
}
157
- CoffeeCommand :: Show { plugin } => match coffee. show ( & plugin) . await {
158
- Ok ( val) => {
159
- // FIXME: modify the radicle_term markdown
160
- let val = val. readme . as_str ( ) ;
161
- term:: markdown ( val) ;
162
- Ok ( ( ) )
163
- }
164
- Err ( err) => Err ( err) ,
165
- } ,
166
- CoffeeCommand :: Search { plugin } => match coffee. search ( & plugin) . await {
167
- Ok ( val) => {
168
- let repository_url = val. repository_url . as_str ( ) ;
169
- term:: success!( "found plugin {plugin} in remote repository {repository_url}" ) ;
170
- Ok ( ( ) )
171
- }
172
- Err ( err) => Err ( err) ,
173
- } ,
174
160
CoffeeCommand :: Nurse { verify } => {
175
161
if verify {
176
162
let result = coffee. nurse_verify ( ) . await ?;
177
163
term:: info!( "{}" , result) ;
178
164
if !result. is_sane ( ) {
179
165
term:: info!( "Coffee local directory is damaged, please run `coffee nurse` to try to fix it" ) ;
180
166
}
181
- Ok ( ( ) )
182
167
} else {
183
168
let nurse_result = coffee. nurse ( ) . await ;
184
- coffee_term:: show_nurse_result ( nurse_result)
169
+ coffee_term:: show_nurse_result ( nurse_result) ? ;
185
170
}
186
171
}
187
172
} ;
173
+ Ok ( ( ) )
174
+ }
188
175
189
- if let Err ( err) = result {
190
- term:: error ( format ! ( "{err}" ) ) ;
176
+ #[ tokio:: main]
177
+ async fn main ( ) -> Result < ( ) , CoffeeError > {
178
+ env_logger:: init ( ) ;
179
+ let args = CoffeeArgs :: parse ( ) ;
180
+ let coffee = CoffeeManager :: new ( & args) . await ?;
181
+ if let Err ( err) = run ( args, coffee) . await {
182
+ term:: error ( format ! ( "{err}" ) )
191
183
}
192
-
193
184
Ok ( ( ) )
194
185
}
0 commit comments