git_x/
lib.rs

1// Core abstractions and utilities
2pub mod core;
3
4// Domain layer - business logic
5pub mod domain;
6
7// Adapter layer - connects CLI to domain
8pub mod adapters;
9
10// Command implementations organized by domain
11pub mod commands;
12
13// CLI interface
14pub mod cli;
15
16// Examples showing architecture migration
17#[cfg(test)]
18pub mod examples;
19
20/// Common error type for git-x operations
21#[derive(Debug)]
22pub enum GitXError {
23    GitCommand(String),
24    Io(std::io::Error),
25    Parse(String),
26    Dialog(String),
27    Join(String),
28    Other(String),
29}
30
31impl std::fmt::Display for GitXError {
32    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33        match self {
34            GitXError::GitCommand(cmd) => write!(f, "Git command failed: {cmd}"),
35            GitXError::Io(err) => write!(f, "IO error: {err}"),
36            GitXError::Parse(msg) => write!(f, "Parse error: {msg}"),
37            GitXError::Dialog(msg) => write!(f, "Dialog error: {msg}"),
38            GitXError::Join(msg) => write!(f, "Join error: {msg}"),
39            GitXError::Other(msg) => write!(f, "{msg}"),
40        }
41    }
42}
43
44impl std::error::Error for GitXError {
45    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
46        match self {
47            GitXError::Io(err) => Some(err),
48            GitXError::GitCommand(_)
49            | GitXError::Parse(_)
50            | GitXError::Dialog(_)
51            | GitXError::Join(_)
52            | GitXError::Other(_) => None,
53        }
54    }
55}
56
57impl From<std::io::Error> for GitXError {
58    fn from(err: std::io::Error) -> Self {
59        GitXError::Io(err)
60    }
61}
62
63impl From<dialoguer::Error> for GitXError {
64    fn from(err: dialoguer::Error) -> Self {
65        GitXError::Dialog(err.to_string())
66    }
67}
68
69impl From<tokio::task::JoinError> for GitXError {
70    fn from(err: tokio::task::JoinError) -> Self {
71        GitXError::Join(err.to_string())
72    }
73}
74
75pub type Result<T> = std::result::Result<T, GitXError>;