@@ -6,22 +6,29 @@ use std::{error::Error, io::Write};
66#[ derive( Parser ) ]
77#[ command( arg_required_else_help = true ) ]
88pub ( crate ) struct Mob {
9- /// Sets active co-author(s) for pair/mob programming session
9+ /// Sets co-author(s) from team member(s) in the mob/pair programming session
10+ ///
11+ /// This will clear any existing co-author(s) in current session
1012 ///
1113 /// Usage example: git mob pair --with lm mj
1214 #[ arg( short='w' , long="with" , num_args=0 .., value_name="COAUTHOR_KEY" ) ]
1315 pub ( crate ) with : Option < Vec < String > > ,
14- /// Clears mob/pair programming session. Going solo!
16+ /// Adds co-author to the mob/pair programming session (usually non-team member)
17+ ///
18+ /// Usage example: git mob --add "Leo Messi" [email protected] 19+ #[ arg( short = 'a' , long = "add" , num_args=2 , value_names=[ "COAUTHOR_NAME" , "COAUTHOR_EMAIL" ] ) ]
20+ pub ( crate ) add : Option < Vec < String > > ,
21+ /// Clears the mob/pair programming session. Going solo!
1522 ///
1623 /// Usage example: git mob --clear
1724 #[ arg( short = 'c' , long = "clear" ) ]
1825 pub ( crate ) clear : bool ,
19- /// Lists co-author(s) in current mob/pair programming session
26+ /// Lists co-author(s) in the mob/pair programming session
2027 ///
2128 /// Usage example: git mob --list
2229 #[ arg( short = 'l' , long = "list" ) ]
2330 pub ( crate ) list : bool ,
24- /// Lists Co-authored-by trailers in current mob/pair programming session
31+ /// Lists Co-authored-by trailers in the mob/pair programming session
2532 ///
2633 /// Usage example: git mob --trailers
2734 #[ arg( short = 't' , long = "trailers" ) ]
@@ -99,6 +106,12 @@ impl Mob {
99106 }
100107 }
101108
109+ if let Some ( [ name, email] ) = self . add . as_deref ( ) {
110+ let coauthor = format ! ( "{name} <{email}>" ) ;
111+ coauthor_repo. add_to_mob ( & coauthor) ?;
112+ writeln ! ( out, "{coauthor}" ) ?
113+ }
114+
102115 Ok ( ( ) )
103116 }
104117}
@@ -124,6 +137,7 @@ mod tests {
124137 with : None ,
125138 list : false ,
126139 trailers : false ,
140+ add : None ,
127141 } ;
128142
129143 let mut out = Vec :: new ( ) ;
@@ -152,6 +166,7 @@ mod tests {
152166 clear : false ,
153167 with : None ,
154168 trailers : false ,
169+ add : None ,
155170 } ;
156171
157172 let mut out = Vec :: new ( ) ;
@@ -175,6 +190,7 @@ mod tests {
175190 clear : false ,
176191 with : None ,
177192 trailers : false ,
193+ add : None ,
178194 } ;
179195
180196 let mut out = Vec :: new ( ) ;
@@ -203,6 +219,7 @@ mod tests {
203219 clear : false ,
204220 with : None ,
205221 trailers : true ,
222+ add : None ,
206223 } ;
207224
208225 let mut out = Vec :: new ( ) ;
@@ -230,6 +247,7 @@ mod tests {
230247 clear : false ,
231248 with : None ,
232249 trailers : true ,
250+ add : None ,
233251 } ;
234252
235253 let mut out = Vec :: new ( ) ;
@@ -256,6 +274,7 @@ mod tests {
256274 clear : false ,
257275 list : false ,
258276 trailers : false ,
277+ add : None ,
259278 } ;
260279
261280 let mut out = Vec :: new ( ) ;
@@ -306,6 +325,7 @@ mod tests {
306325 clear : false ,
307326 list : false ,
308327 trailers : false ,
328+ add : None ,
309329 } ;
310330
311331 let mut out = Vec :: new ( ) ;
@@ -336,6 +356,7 @@ mod tests {
336356 clear : false ,
337357 list : false ,
338358 trailers : false ,
359+ add : None ,
339360 } ;
340361
341362 let mut out = Vec :: new ( ) ;
@@ -346,4 +367,32 @@ mod tests {
346367
347368 Ok ( ( ) )
348369 }
370+
371+ #[ test]
372+ fn test_add_to_mob ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
373+ let name = "Leo Messi" ;
374+ 375+
376+ let mut mock_coauthor_repo = MockCoauthorRepo :: new ( ) ;
377+ mock_coauthor_repo
378+ . expect_add_to_mob ( )
379+ . with ( predicate:: eq ( format ! ( "{name} <{email}>" ) ) )
380+ . once ( )
381+ . returning ( |_| Ok ( ( ) ) ) ;
382+
383+ let mob_cmd = Mob {
384+ add : Some ( vec ! [ name. to_owned( ) , email. to_owned( ) ] ) ,
385+ with : None ,
386+ clear : false ,
387+ list : false ,
388+ trailers : false ,
389+ } ;
390+
391+ let mut out = Vec :: new ( ) ;
392+ mob_cmd. handle ( & mock_coauthor_repo, & mut out) ?;
393+
394+ assert_eq ! ( out, format!( "{name} <{email}>\n " ) . as_bytes( ) ) ;
395+
396+ Ok ( ( ) )
397+ }
349398}
0 commit comments