i3status_rs/blocks/packages/
apk.rs

1use tokio::process::Command;
2
3use super::*;
4
5#[derive(Default)]
6pub struct Apk;
7
8impl Apk {
9    pub fn new() -> Self {
10        Default::default()
11    }
12}
13
14#[async_trait]
15impl Backend for Apk {
16    fn name(&self) -> Cow<'static, str> {
17        "apk".into()
18    }
19
20    async fn get_updates_list(&self) -> Result<Vec<String>> {
21        let stdout = Command::new("apk")
22            .env("LC_LANG", "C")
23            .args(["--no-cache", "-q", "list", "--upgradable"])
24            .output()
25            .await
26            .error("Problem running apk command")?
27            .stdout;
28
29        let updates = String::from_utf8(stdout).expect("apk produced non-UTF8 output");
30        let updates_list: Vec<String> = updates
31            .lines()
32            .filter(|line| line.len() > 1)
33            .map(|line| line.to_string())
34            .collect();
35
36        Ok(updates_list)
37    }
38}