Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
patch: Add repo option
Erik Kundt committed 2 years ago
commit 2a6f390ea56d0ac514d0c01734d35d5e06069d8d
parent 055edfe49adf506f2bdedef92fe3007d03f79952
2 files changed +13 -9
modified bin/commands/patch.rs
@@ -11,6 +11,7 @@ use std::ffi::OsString;

use anyhow::anyhow;

+
use radicle::identity::RepoId;
use radicle_tui as tui;

use tui::common::cob::patch::{self, State};
@@ -52,6 +53,7 @@ Other options

pub struct Options {
    op: Operation,
+
    repo: Option<RepoId>,
}

pub enum Operation {
@@ -75,6 +77,7 @@ impl Args for Options {

        let mut parser = lexopt::Parser::from_args(args);
        let mut op: Option<OperationName> = None;
+
        let mut repo = None;
        let mut select_opts = SelectOptions::default();

        while let Some(arg) = parser.next()? {
@@ -118,6 +121,13 @@ impl Args for Options {
                        .with_author(terminal::args::did(&parser.value()?)?);
                }

+
                Long("repo") => {
+
                    let val = parser.value()?;
+
                    let rid = terminal::args::rid(&val)?;
+

+
                    repo = Some(rid);
+
                }
+

                Value(val) if op.is_none() => match val.to_string_lossy().as_ref() {
                    "select" => op = Some(OperationName::Select),
                    unknown => anyhow::bail!("unknown operation '{}'", unknown),
@@ -129,7 +139,7 @@ impl Args for Options {
        let op = match op.ok_or_else(|| anyhow!("an operation must be provided"))? {
            OperationName::Select => Operation::Select { opts: select_opts },
        };
-
        Ok((Options { op }, vec![]))
+
        Ok((Options { op, repo }, vec![]))
    }
}

@@ -174,6 +184,7 @@ pub async fn run(options: Options, _ctx: impl terminal::Context) -> anyhow::Resu
    match options.op {
        Operation::Select { opts } => {
            let profile = terminal::profile()?;
+
            let rid = options.repo.unwrap_or(rid);
            let repository = profile.storage.repository(rid).unwrap();

            log::enable(&profile, "patch", "select")?;
modified src/common/cob/patch.rs
@@ -125,14 +125,7 @@ pub fn all(profile: &Profile, repository: &Repository) -> Result<Vec<(PatchId, P
    let cache = profile.patches(repository)?;
    let patches = cache.list()?;

-
    let mut all = vec![];
-
    for patch in patches {
-
        if let Ok((id, patch)) = patch {
-
            all.push((id, patch))
-
        }
-
    }
-

-
    Ok(all)
+
    Ok(patches.flatten().collect())
}

pub fn find(profile: &Profile, repository: &Repository, id: &PatchId) -> Result<Option<Patch>> {