Skip to main content

purple_ssh/app/
update.rs

1/// Update availability state.
2///
3/// `hint` defaults to `""` via `#[derive(Default)]`. In practice `App::new()`
4/// always overwrites it with the detected install method, so the empty default
5/// is only visible when constructing `UpdateState` in isolation (e.g. tests).
6#[derive(Default)]
7pub struct UpdateState {
8    /// Available version string (None if up to date or unchecked).
9    pub(in crate::app) available: Option<String>,
10    /// Update announcement headline.
11    pub(in crate::app) headline: Option<String>,
12    /// Update hint string (install command suggestion).
13    pub(in crate::app) hint: &'static str,
14}
15
16impl UpdateState {
17    /// Construct with the current install-method hint detected at runtime.
18    pub fn with_current_hint() -> Self {
19        Self {
20            hint: crate::update::update_hint(),
21            ..Self::default()
22        }
23    }
24
25    pub fn available(&self) -> Option<&String> {
26        self.available.as_ref()
27    }
28
29    pub fn headline(&self) -> Option<&str> {
30        self.headline.as_deref()
31    }
32
33    pub fn hint(&self) -> &'static str {
34        self.hint
35    }
36
37    pub fn announce(&mut self, version: String, headline: Option<String>) {
38        self.available = Some(version);
39        self.headline = headline;
40    }
41}