1use {crate::init::SEP, std::fmt::Display};
2
3#[derive(Debug)]
4pub enum InitError {
5 CouldntCloneRepo(String),
6 PathExistsButIsNotGit(String),
7 BranchDoesntExists(String),
8 ManualExit,
9 CloneNeedsAuthentification,
10 BadCredentials,
11 AlreadyExists(String),
12 IoError(std::io::Error),
13 InvalidPath(String),
14 OtherGitError(git2::Error),
15}
16
17
18impl Display for InitError {
19 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20 f.write_str(&format!(
21 "{SEP}\n\x1b[31m◆\x1b[91;1m {}",
22 match self {
23 Self::CouldntCloneRepo(url) => format!("Couldn't clone repo with url: {url}"),
24 Self::ManualExit => String::from("See you next time!"),
25 Self::BadCredentials => String::from("Bad credentials"),
26 Self::PathExistsButIsNotGit(path) =>
27 format!("The path `{path}` exists, but is not a git repository."),
28 Self::BranchDoesntExists(branch) => format!("Branch {branch} doesn't exists"),
29 Self::InvalidPath(path) => format!("File `{path}` doesn't exists."),
30 Self::CloneNeedsAuthentification =>
31 "You need to authenticate to clone this repository.".to_string(),
32 Self::OtherGitError(err) => format!("{:?}", err.message()),
33 Self::IoError(err) => err.to_string(),
34 Self::AlreadyExists(path) => format!("There is already a directory at {path:#?}"),
35 }
36 ))
37 }
38}