Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
feat: change cibtool to list runs
Lars Wirzenius committed 1 year ago
commit 86884cbe433a967c3da5b0d9df0223a0ea60e527
parent 21ef36aa234ce83fa950e2ccd665568a10ea0fb7
2 files changed +37 -30
modified src/bin/cibtool.rs
@@ -57,6 +57,7 @@ impl Args {
        match &self.cmd {
            Cmd::Counter(x) => x.run(self)?,
            Cmd::Event(x) => x.run(self)?,
+
            Cmd::Run(x) => x.run(self)?,
        }
        Ok(())
    }
@@ -70,6 +71,7 @@ impl Args {
enum Cmd {
    Counter(Counter),
    Event(Event),
+
    Run(Run),
}

#[derive(Parser)]
@@ -422,6 +424,41 @@ impl Shutdown {
    }
}

+
#[derive(Parser)]
+
struct Run {
+
    #[clap(subcommand)]
+
    cmd: RunCmd,
+
}
+

+
impl Run {
+
    fn run(&self, args: &Args) -> Result<(), CibToolError> {
+
        match &self.cmd {
+
            RunCmd::List(x) => x.run(args)?,
+
        }
+
        Ok(())
+
    }
+
}
+

+
#[derive(Parser)]
+
enum RunCmd {
+
    List(ListRuns),
+
}
+

+
#[derive(Parser)]
+
struct ListRuns {}
+

+
impl ListRuns {
+
    fn run(&self, args: &Args) -> Result<(), CibToolError> {
+
        let db = args.open_db()?;
+

+
        for run_id in db.list_runs()? {
+
            println!("{run_id}");
+
        }
+

+
        Ok(())
+
    }
+
}
+

#[derive(Debug, thiserror::Error)]
enum CibToolError {
    #[error("failed to look up node profile")]
deleted src/bin/list_runs.rs
@@ -1,30 +0,0 @@
-
use std::{error::Error, path::PathBuf};
-

-
use radicle_ci_broker::{db::Db, error::BrokerError};
-

-
fn main() {
-
    if let Err(e) = fallible_main() {
-
        eprintln!("ERROR: {}", e);
-
        let mut e = e.source();
-
        while let Some(source) = e {
-
            eprintln!("caused by: {}", source);
-
            e = source.source();
-
        }
-
    }
-
}
-

-
fn fallible_main() -> Result<(), BrokerError> {
-
    let mut args = std::env::args().skip(1);
-
    let filename: PathBuf = if let Some(filename) = args.next() {
-
        PathBuf::from(filename)
-
    } else {
-
        return Err(BrokerError::Usage);
-
    };
-

-
    let mut db = Db::new(&filename)?;
-
    for run in db.all_runs()? {
-
        println!("{run:#?}");
-
    }
-

-
    Ok(())
-
}