@@ -27,6 +27,12 @@ const ABOUT: &str = "Deletes old branches from the GIT repository";
27
27
28
28
const ACTIONS : & str = "k(eep)/d(elete)/s(how)/q(uit)" ;
29
29
30
+ #[ derive( Debug , Eq , PartialEq ) ]
31
+ enum Interrupt {
32
+ Quit ,
33
+ Continue ,
34
+ }
35
+
30
36
/// delete-branch function tries to remove branch from the repository
31
37
/// Uses all ssh keys found in user's .ssh directory, and tries the one by one.
32
38
/// If any of the succeed, operation is considered successful.
@@ -62,7 +68,7 @@ fn do_action_on_branch<'a>(
62
68
mut branch : GitBranch < ' a > ,
63
69
keys : & Vec < String > ,
64
70
passphrase : Option < & ' a str > ,
65
- ) {
71
+ ) -> Interrupt {
66
72
let _ = writeln ! (
67
73
stdout,
68
74
"Actions: {}\n Branch -> {}\n Last Commit -> {}\n Commit Hash: {}" ,
@@ -94,7 +100,8 @@ fn do_action_on_branch<'a>(
94
100
break ;
95
101
}
96
102
} ,
97
- BranchAction :: Keep | BranchAction :: Quit => break ,
103
+ BranchAction :: Keep => break ,
104
+ BranchAction :: Quit => return Interrupt :: Quit ,
98
105
BranchAction :: Show => {
99
106
println ! (
100
107
"Commit Hash -> {} | Commit Message -> {}" ,
@@ -107,6 +114,8 @@ fn do_action_on_branch<'a>(
107
114
}
108
115
}
109
116
}
117
+
118
+ Interrupt :: Continue
110
119
}
111
120
112
121
fn main ( ) -> Result < ( ) , GitError > {
@@ -153,7 +162,11 @@ fn main() -> Result<(), GitError> {
153
162
None => None ,
154
163
} ;
155
164
156
- do_action_on_branch ( & mut stdin, & mut stdout, & repo, branch, & keys, c. as_deref ( ) ) ;
165
+ if Interrupt :: Quit
166
+ == do_action_on_branch ( & mut stdin, & mut stdout, & repo, branch, & keys, c. as_deref ( ) )
167
+ {
168
+ return Ok ( ( ) ) ;
169
+ }
157
170
}
158
171
159
172
Ok ( ( ) )
0 commit comments