mirror of
https://seed.radicle.dev/rad:z39mP9rQAaGmERfUMPULfPUi473tY.git
synced 2026-11-16 16:30:38 +08:00
issue: Add repo option
This commit is contained in:
+12
-1
@@ -11,6 +11,7 @@ use std::ffi::OsString;
|
||||
|
||||
use anyhow::anyhow;
|
||||
|
||||
use radicle::identity::RepoId;
|
||||
use radicle_tui as tui;
|
||||
|
||||
use tui::common::cob::issue::{self, State};
|
||||
@@ -43,6 +44,7 @@ Other options
|
||||
|
||||
pub struct Options {
|
||||
op: Operation,
|
||||
repo: Option<RepoId>,
|
||||
}
|
||||
|
||||
pub enum Operation {
|
||||
@@ -66,6 +68,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()? {
|
||||
@@ -106,6 +109,13 @@ impl Args for Options {
|
||||
}
|
||||
}
|
||||
|
||||
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),
|
||||
@@ -117,7 +127,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![]))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,6 +172,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, "issue", "select")?;
|
||||
|
||||
@@ -5,7 +5,7 @@ use anyhow::anyhow;
|
||||
|
||||
use radicle::cob::{issue, patch};
|
||||
use radicle::crypto;
|
||||
use radicle::identity::Did;
|
||||
use radicle::identity::{Did, RepoId};
|
||||
|
||||
/// Git revision parameter. Supports extended SHA-1 syntax.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -116,6 +116,11 @@ pub fn did(val: &OsString) -> anyhow::Result<Did> {
|
||||
Ok(peer)
|
||||
}
|
||||
|
||||
pub fn rid(val: &OsString) -> anyhow::Result<RepoId> {
|
||||
let val = val.to_string_lossy();
|
||||
RepoId::from_str(&val).map_err(|_| anyhow!("invalid Repository ID '{}'", val))
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn issue(val: &OsString) -> anyhow::Result<issue::IssueId> {
|
||||
let val = val.to_string_lossy();
|
||||
|
||||
@@ -132,15 +132,8 @@ impl ToString for Filter {
|
||||
pub fn all(profile: &Profile, repository: &Repository) -> Result<Vec<(IssueId, Issue)>> {
|
||||
let cache = profile.issues(repository)?;
|
||||
let issues = cache.list()?;
|
||||
|
||||
let mut all = vec![];
|
||||
for issue in issues {
|
||||
if let Ok((id, issue)) = issue {
|
||||
all.push((id, issue))
|
||||
}
|
||||
}
|
||||
|
||||
Ok(all)
|
||||
Ok(issues.flatten().collect())
|
||||
}
|
||||
|
||||
pub fn find(profile: &Profile, repository: &Repository, id: &IssueId) -> Result<Option<Issue>> {
|
||||
|
||||
Reference in New Issue
Block a user