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 comment <issue-id> [--message <message>] [--reply-to <comment-id>] [<option>...]
|
||||||
rad issue show <issue-id> [<option>...]
|
rad issue show <issue-id> [<option>...]
|
||||||
rad issue state <issue-id> [--closed | --open | --solved] [<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
|
Assign options
|
||||||
|
|
||||||
|
|
@ -150,6 +150,7 @@ pub enum Operation {
|
||||||
},
|
},
|
||||||
Cache {
|
Cache {
|
||||||
id: Option<Rev>,
|
id: Option<Rev>,
|
||||||
|
storage: bool,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -197,6 +198,7 @@ impl Args for Options {
|
||||||
let mut assign_opts = AssignOptions::default();
|
let mut assign_opts = AssignOptions::default();
|
||||||
let mut label_opts = LabelOptions::default();
|
let mut label_opts = LabelOptions::default();
|
||||||
let mut repo = None;
|
let mut repo = None;
|
||||||
|
let mut cache_storage = false;
|
||||||
|
|
||||||
while let Some(arg) = parser.next()? {
|
while let Some(arg) = parser.next()? {
|
||||||
match arg {
|
match arg {
|
||||||
|
|
@ -333,6 +335,11 @@ impl Args for Options {
|
||||||
label_opts.delete.insert(label);
|
label_opts.delete.insert(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cache options.
|
||||||
|
Long("storage") if matches!(op, Some(OperationName::Cache)) => {
|
||||||
|
cache_storage = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Options.
|
// Options.
|
||||||
Long("no-announce") => {
|
Long("no-announce") => {
|
||||||
announce = false;
|
announce = false;
|
||||||
|
|
@ -415,7 +422,10 @@ impl Args for Options {
|
||||||
opts: label_opts,
|
opts: label_opts,
|
||||||
},
|
},
|
||||||
OperationName::List => Operation::List { assigned, state },
|
OperationName::List => Operation::List { assigned, state },
|
||||||
OperationName::Cache => Operation::Cache { id },
|
OperationName::Cache => Operation::Cache {
|
||||||
|
id,
|
||||||
|
storage: cache_storage,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
|
|
@ -591,9 +601,19 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
let id = id.resolve(&repo.backend)?;
|
let id = id.resolve(&repo.backend)?;
|
||||||
issues.remove(&id, &signer)?;
|
issues.remove(&id, &signer)?;
|
||||||
}
|
}
|
||||||
Operation::Cache { id } => {
|
Operation::Cache { id, storage } => {
|
||||||
let id = id.map(|id| id.resolve(&repo.backend)).transpose()?;
|
let mode = if storage {
|
||||||
cache::run(id, &repo, &profile)?;
|
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::issue::IssueId;
|
||||||
use radicle::storage::git::Repository;
|
use radicle::storage::git::Repository;
|
||||||
|
use radicle::storage::ReadStorage as _;
|
||||||
use radicle::Profile;
|
use radicle::Profile;
|
||||||
|
|
||||||
use crate::terminal as term;
|
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)?;
|
let mut issues = profile.issues_mut(repository)?;
|
||||||
|
|
||||||
match id {
|
match id {
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ Usage
|
||||||
rad patch edit <patch-id> [<option>...]
|
rad patch edit <patch-id> [<option>...]
|
||||||
rad patch set <patch-id> [<option>...]
|
rad patch set <patch-id> [<option>...]
|
||||||
rad patch comment <patch-id | revision-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
|
Show options
|
||||||
|
|
||||||
|
|
@ -279,6 +279,7 @@ pub enum Operation {
|
||||||
},
|
},
|
||||||
Cache {
|
Cache {
|
||||||
patch_id: Option<Rev>,
|
patch_id: Option<Rev>,
|
||||||
|
storage: bool,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -345,6 +346,7 @@ impl Args for Options {
|
||||||
let mut review_op = review::Operation::default();
|
let mut review_op = review::Operation::default();
|
||||||
let mut base_id = None;
|
let mut base_id = None;
|
||||||
let mut repo = None;
|
let mut repo = None;
|
||||||
|
let mut cache_storage = false;
|
||||||
|
|
||||||
while let Some(arg) = parser.next()? {
|
while let Some(arg) = parser.next()? {
|
||||||
match arg {
|
match arg {
|
||||||
|
|
@ -565,6 +567,11 @@ impl Args for Options {
|
||||||
authors.push(term::args::did(&parser.value()?)?);
|
authors.push(term::args::did(&parser.value()?)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cache options.
|
||||||
|
Long("storage") if op == Some(OperationName::Cache) => {
|
||||||
|
cache_storage = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Common.
|
// Common.
|
||||||
Long("verbose") | Short('v') => {
|
Long("verbose") | Short('v') => {
|
||||||
verbose = true;
|
verbose = true;
|
||||||
|
|
@ -711,7 +718,10 @@ impl Args for Options {
|
||||||
patch_id: patch_id.ok_or_else(|| anyhow!("a patch must be provided"))?,
|
patch_id: patch_id.ok_or_else(|| anyhow!("a patch must be provided"))?,
|
||||||
remote,
|
remote,
|
||||||
},
|
},
|
||||||
OperationName::Cache => Operation::Cache { patch_id },
|
OperationName::Cache => Operation::Cache {
|
||||||
|
patch_id,
|
||||||
|
storage: cache_storage,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
|
|
@ -934,11 +944,24 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
true,
|
true,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
Operation::Cache { patch_id } => {
|
Operation::Cache { patch_id, storage } => {
|
||||||
let patch_id = patch_id
|
let mode = if storage {
|
||||||
.map(|id| id.resolve(&repository.backend))
|
cache::CacheMode::Storage
|
||||||
.transpose()?;
|
} else {
|
||||||
cache::run(patch_id, &repository, &profile)?;
|
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::patch::PatchId;
|
||||||
use radicle::storage::git::Repository;
|
use radicle::storage::git::Repository;
|
||||||
|
use radicle::storage::ReadStorage as _;
|
||||||
use radicle::Profile;
|
use radicle::Profile;
|
||||||
|
|
||||||
use crate::terminal as term;
|
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)?;
|
let mut patches = profile.patches_mut(repository)?;
|
||||||
|
|
||||||
match id {
|
match id {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue