wtg_cli/
notice.rs

1//! Notices emitted during backend/git operations.
2//!
3//! All notices are delivered via callback - the CLI layer decides how to display them.
4
5use std::sync::Arc;
6
7use crate::remote::{RemoteHost, RemoteInfo};
8
9/// Notices emitted during backend/git operations.
10/// All notices are delivered via callback - the CLI layer decides how to display them.
11#[derive(Debug, Clone)]
12#[non_exhaustive]
13pub enum Notice {
14    // --- Backend capability notices ---
15    /// No remotes configured at all
16    NoRemotes,
17    /// Single host type detected but it's not GitHub
18    UnsupportedHost {
19        /// The best remote we found (by priority: upstream > origin > other)
20        best_remote: RemoteInfo,
21    },
22    /// Multiple different hosts detected, none of them GitHub
23    MixedRemotes {
24        /// All the unique hosts we found
25        hosts: Vec<RemoteHost>,
26        /// Total remote count
27        count: usize,
28    },
29    /// GitHub remote found but API client couldn't be created
30    UnreachableGitHub {
31        /// The GitHub remote we found
32        remote: RemoteInfo,
33    },
34    /// Local git repo couldn't be opened, using pure API
35    ApiOnly,
36
37    // --- Operational notices ---
38    /// Failed to update a cached repository
39    CacheUpdateFailed { error: String },
40    /// Repository is shallow, falling back to API
41    ShallowRepoDetected,
42    /// Starting to clone a remote repository
43    CloningRepo { url: String },
44    /// Clone succeeded
45    CloneSucceeded { used_filter: bool },
46    /// Filter clone failed, falling back to bare clone
47    CloneFallbackToBare { error: String },
48    /// Starting to update a cached repository
49    UpdatingCache,
50    /// Cache update completed
51    CacheUpdated,
52    /// Cross-project reference falling back to API-only
53    CrossProjectFallbackToApi {
54        owner: String,
55        repo: String,
56        error: String,
57    },
58}
59
60/// Callback for emitting notices during operations.
61pub type NoticeCallback = Arc<dyn Fn(Notice) + Send + Sync>;
62
63/// Create a no-op callback for when notices should be ignored.
64#[must_use]
65pub fn no_notices() -> NoticeCallback {
66    Arc::new(|_| {})
67}