cli: Option for caching COBs for all repositories
To make it easier for caching COBs across all the repositories in storage, add an option `--storage` that iterates over all the repositories and performs the cache operation for each.
This commit is contained in:
parent
df44cee9ef
commit
23f8cf0d84
|
|
@ -47,7 +47,7 @@ Usage
|
|||
rad issue comment <issue-id> [--message <message>] [--reply-to <comment-id>] [<option>...]
|
||||
rad issue show <issue-id> [<option>...]
|
||||
rad issue state <issue-id> [--closed | --open | --solved] [<option>...]
|
||||
rad issue cache [<issue-id>] [<option>...]
|
||||
rad issue cache [<issue-id>] [--storage] [<option>...]
|
||||
|
||||
Assign options
|
||||
|
||||
|
|
@ -150,6 +150,7 @@ pub enum Operation {
|
|||
},
|
||||
Cache {
|
||||
id: Option<Rev>,
|
||||
storage: bool,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -197,6 +198,7 @@ impl Args for Options {
|
|||
let mut assign_opts = AssignOptions::default();
|
||||
let mut label_opts = LabelOptions::default();
|
||||
let mut repo = None;
|
||||
let mut cache_storage = false;
|
||||
|
||||
while let Some(arg) = parser.next()? {
|
||||
match arg {
|
||||
|
|
@ -333,6 +335,11 @@ impl Args for Options {
|
|||
label_opts.delete.insert(label);
|
||||
}
|
||||
|
||||
// Cache options.
|
||||
Long("storage") if matches!(op, Some(OperationName::Cache)) => {
|
||||
cache_storage = true;
|
||||
}
|
||||
|
||||
// Options.
|
||||
Long("no-announce") => {
|
||||
announce = false;
|
||||
|
|
@ -415,7 +422,10 @@ impl Args for Options {
|
|||
opts: label_opts,
|
||||
},
|
||||
OperationName::List => Operation::List { assigned, state },
|
||||
OperationName::Cache => Operation::Cache { id },
|
||||
OperationName::Cache => Operation::Cache {
|
||||
id,
|
||||
storage: cache_storage,
|
||||
},
|
||||
};
|
||||
|
||||
Ok((
|
||||
|
|
@ -591,9 +601,19 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
|||
let id = id.resolve(&repo.backend)?;
|
||||
issues.remove(&id, &signer)?;
|
||||
}
|
||||
Operation::Cache { id } => {
|
||||
let id = id.map(|id| id.resolve(&repo.backend)).transpose()?;
|
||||
cache::run(id, &repo, &profile)?;
|
||||
Operation::Cache { id, storage } => {
|
||||
let mode = if storage {
|
||||
cache::CacheMode::Storage
|
||||
} else {
|
||||
let issue_id = id.map(|id| id.resolve(&repo.backend)).transpose()?;
|
||||
issue_id.map_or(cache::CacheMode::Repository { repository: &repo }, |id| {
|
||||
cache::CacheMode::Issue {
|
||||
id,
|
||||
repository: &repo,
|
||||
}
|
||||
})
|
||||
};
|
||||
cache::run(mode, &profile)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,41 @@ use std::ops::ControlFlow;
|
|||
|
||||
use radicle::issue::IssueId;
|
||||
use radicle::storage::git::Repository;
|
||||
use radicle::storage::ReadStorage as _;
|
||||
use radicle::Profile;
|
||||
|
||||
use crate::terminal as term;
|
||||
|
||||
pub fn run(id: Option<IssueId>, repository: &Repository, profile: &Profile) -> anyhow::Result<()> {
|
||||
pub enum CacheMode<'a> {
|
||||
Storage,
|
||||
Repository {
|
||||
repository: &'a Repository,
|
||||
},
|
||||
Issue {
|
||||
id: IssueId,
|
||||
repository: &'a Repository,
|
||||
},
|
||||
}
|
||||
|
||||
pub fn run(mode: CacheMode, profile: &Profile) -> anyhow::Result<()> {
|
||||
match mode {
|
||||
CacheMode::Storage => {
|
||||
let repos = profile.storage.repositories()?;
|
||||
for info in repos {
|
||||
term::info!("Caching all issues for {}", info.rid);
|
||||
cache(None, &profile.storage.repository(info.rid)?, profile)?
|
||||
}
|
||||
}
|
||||
CacheMode::Repository { repository: repo } => cache(None, repo, profile)?,
|
||||
CacheMode::Issue {
|
||||
id,
|
||||
repository: repo,
|
||||
} => cache(Some(id), repo, profile)?,
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn cache(id: Option<IssueId>, repository: &Repository, profile: &Profile) -> anyhow::Result<()> {
|
||||
let mut issues = profile.issues_mut(repository)?;
|
||||
|
||||
match id {
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ Usage
|
|||
rad patch edit <patch-id> [<option>...]
|
||||
rad patch set <patch-id> [<option>...]
|
||||
rad patch comment <patch-id | revision-id> [<option>...]
|
||||
rad patch cache [<patch-id>] [<option>...]
|
||||
rad patch cache [<patch-id>] [--storage] [<option>...]
|
||||
|
||||
Show options
|
||||
|
||||
|
|
@ -279,6 +279,7 @@ pub enum Operation {
|
|||
},
|
||||
Cache {
|
||||
patch_id: Option<Rev>,
|
||||
storage: bool,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -345,6 +346,7 @@ impl Args for Options {
|
|||
let mut review_op = review::Operation::default();
|
||||
let mut base_id = None;
|
||||
let mut repo = None;
|
||||
let mut cache_storage = false;
|
||||
|
||||
while let Some(arg) = parser.next()? {
|
||||
match arg {
|
||||
|
|
@ -565,6 +567,11 @@ impl Args for Options {
|
|||
authors.push(term::args::did(&parser.value()?)?);
|
||||
}
|
||||
|
||||
// Cache options.
|
||||
Long("storage") if op == Some(OperationName::Cache) => {
|
||||
cache_storage = true;
|
||||
}
|
||||
|
||||
// Common.
|
||||
Long("verbose") | Short('v') => {
|
||||
verbose = true;
|
||||
|
|
@ -711,7 +718,10 @@ impl Args for Options {
|
|||
patch_id: patch_id.ok_or_else(|| anyhow!("a patch must be provided"))?,
|
||||
remote,
|
||||
},
|
||||
OperationName::Cache => Operation::Cache { patch_id },
|
||||
OperationName::Cache => Operation::Cache {
|
||||
patch_id,
|
||||
storage: cache_storage,
|
||||
},
|
||||
};
|
||||
|
||||
Ok((
|
||||
|
|
@ -934,11 +944,24 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
|||
true,
|
||||
)?;
|
||||
}
|
||||
Operation::Cache { patch_id } => {
|
||||
let patch_id = patch_id
|
||||
.map(|id| id.resolve(&repository.backend))
|
||||
.transpose()?;
|
||||
cache::run(patch_id, &repository, &profile)?;
|
||||
Operation::Cache { patch_id, storage } => {
|
||||
let mode = if storage {
|
||||
cache::CacheMode::Storage
|
||||
} else {
|
||||
let patch_id = patch_id
|
||||
.map(|id| id.resolve(&repository.backend))
|
||||
.transpose()?;
|
||||
patch_id.map_or(
|
||||
cache::CacheMode::Repository {
|
||||
repository: &repository,
|
||||
},
|
||||
|id| cache::CacheMode::Patch {
|
||||
id,
|
||||
repository: &repository,
|
||||
},
|
||||
)
|
||||
};
|
||||
cache::run(mode, &profile)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,41 @@ use std::ops::ControlFlow;
|
|||
|
||||
use radicle::patch::PatchId;
|
||||
use radicle::storage::git::Repository;
|
||||
use radicle::storage::ReadStorage as _;
|
||||
use radicle::Profile;
|
||||
|
||||
use crate::terminal as term;
|
||||
|
||||
pub fn run(id: Option<PatchId>, repository: &Repository, profile: &Profile) -> anyhow::Result<()> {
|
||||
pub enum CacheMode<'a> {
|
||||
Storage,
|
||||
Repository {
|
||||
repository: &'a Repository,
|
||||
},
|
||||
Patch {
|
||||
id: PatchId,
|
||||
repository: &'a Repository,
|
||||
},
|
||||
}
|
||||
|
||||
pub fn run(mode: CacheMode, profile: &Profile) -> anyhow::Result<()> {
|
||||
match mode {
|
||||
CacheMode::Storage => {
|
||||
let repos = profile.storage.repositories()?;
|
||||
for info in repos {
|
||||
term::info!("Caching all patches for {}", info.rid);
|
||||
cache(None, &profile.storage.repository(info.rid)?, profile)?
|
||||
}
|
||||
}
|
||||
CacheMode::Repository { repository: repo } => cache(None, repo, profile)?,
|
||||
CacheMode::Patch {
|
||||
id,
|
||||
repository: repo,
|
||||
} => cache(Some(id), repo, profile)?,
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn cache(id: Option<PatchId>, repository: &Repository, profile: &Profile) -> anyhow::Result<()> {
|
||||
let mut patches = profile.patches_mut(repository)?;
|
||||
|
||||
match id {
|
||||
|
|
|
|||
Loading…
Reference in New Issue