Skip to content

Commit 23f51e8

Browse files
author
Dusan
committed
Fixing issue with Quit action
Signed-off-by: Dusan <dmalusev@nanointeractive.com>
1 parent f1f7b36 commit 23f51e8

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/main.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ const ABOUT: &str = "Deletes old branches from the GIT repository";
2727

2828
const ACTIONS: &str = "k(eep)/d(elete)/s(how)/q(uit)";
2929

30+
#[derive(Debug, Eq, PartialEq)]
31+
enum Interrupt {
32+
Quit,
33+
Continue,
34+
}
35+
3036
/// delete-branch function tries to remove branch from the repository
3137
/// Uses all ssh keys found in user's .ssh directory, and tries the one by one.
3238
/// If any of the succeed, operation is considered successful.
@@ -62,7 +68,7 @@ fn do_action_on_branch<'a>(
6268
mut branch: GitBranch<'a>,
6369
keys: &Vec<String>,
6470
passphrase: Option<&'a str>,
65-
) {
71+
) -> Interrupt {
6672
let _ = writeln!(
6773
stdout,
6874
"Actions: {}\nBranch -> {}\nLast Commit -> {}\nCommit Hash: {}",
@@ -94,7 +100,8 @@ fn do_action_on_branch<'a>(
94100
break;
95101
}
96102
},
97-
BranchAction::Keep | BranchAction::Quit => break,
103+
BranchAction::Keep => break,
104+
BranchAction::Quit => return Interrupt::Quit,
98105
BranchAction::Show => {
99106
println!(
100107
"Commit Hash -> {} | Commit Message -> {}",
@@ -107,6 +114,8 @@ fn do_action_on_branch<'a>(
107114
}
108115
}
109116
}
117+
118+
Interrupt::Continue
110119
}
111120

112121
fn main() -> Result<(), GitError> {
@@ -153,7 +162,11 @@ fn main() -> Result<(), GitError> {
153162
None => None,
154163
};
155164

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+
}
157170
}
158171

159172
Ok(())

0 commit comments

Comments
 (0)