cli: Add `patch archive` sub-command

This commit is contained in:
Alexis Sellier 2023-04-06 14:30:53 +02:00
parent 414477a316
commit 7d1e3d489b
No known key found for this signature in database
3 changed files with 36 additions and 0 deletions

View File

@ -1,3 +1,5 @@
#[path = "patch/archive.rs"]
mod archive;
#[path = "patch/checkout.rs"]
mod checkout;
#[path = "patch/common.rs"]
@ -38,6 +40,7 @@ Usage
rad patch list [--all|--merged|--open|--archived] [<option>...]
rad patch show <patch-id> [<option>...]
rad patch open [<option>...]
rad patch archive <patch-id> [<option>...]
rad patch update <patch-id> [<option>...]
rad patch checkout <patch-id> [<option>...]
rad patch delete <patch-id> [<option>...]
@ -67,6 +70,7 @@ pub enum OperationName {
Open,
Show,
Update,
Archive,
Delete,
Checkout,
#[default]
@ -85,6 +89,9 @@ pub enum Operation {
patch_id: Option<Rev>,
message: Message,
},
Archive {
patch_id: Rev,
},
Delete {
patch_id: Rev,
},
@ -180,6 +187,7 @@ impl Args for Options {
"u" | "update" => op = Some(OperationName::Update),
"d" | "delete" => op = Some(OperationName::Delete),
"c" | "checkout" => op = Some(OperationName::Checkout),
"a" | "archive" => op = Some(OperationName::Archive),
unknown => anyhow::bail!("unknown operation '{}'", unknown),
},
Value(val)
@ -202,6 +210,9 @@ impl Args for Options {
patch_id: patch_id.ok_or_else(|| anyhow!("a patch must be provided"))?,
},
OperationName::Update => Operation::Update { patch_id, message },
OperationName::Archive => Operation::Archive {
patch_id: patch_id.ok_or_else(|| anyhow!("a patch id must be provided"))?,
},
OperationName::Checkout => Operation::Checkout {
patch_id: patch_id.ok_or_else(|| anyhow!("a patch must be provided"))?,
},
@ -259,6 +270,10 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
&options,
)?;
}
Operation::Archive { ref patch_id } => {
let patch_id = patch_id.resolve::<PatchId>(&repository.backend)?;
archive::run(&repository, &profile, &patch_id)?;
}
Operation::Delete { patch_id } => {
let patch_id = patch_id.resolve(&repository.backend)?;
delete::run(&repository, &profile, &patch_id)?;

View File

@ -0,0 +1,16 @@
use super::*;
use radicle::cob::patch;
use radicle::prelude::*;
use radicle::storage::git::Repository;
pub fn run(repository: &Repository, profile: &Profile, patch_id: &PatchId) -> anyhow::Result<()> {
let signer = term::signer(profile)?;
let mut patches = patch::Patches::open(repository)?;
let Ok(mut patch) = patches.get_mut(patch_id) else {
anyhow::bail!("Patch `{patch_id}` not found");
};
patch.archive(&signer)?;
Ok(())
}

View File

@ -955,6 +955,11 @@ impl<'a, 'g> PatchMut<'a, 'g> {
self.transaction("Lifecycle", signer, |tx| tx.lifecycle(state))
}
/// Archive a patch.
pub fn archive<G: Signer>(&mut self, signer: &G) -> Result<EntryId, Error> {
self.lifecycle(State::Archived, signer)
}
/// Tag a patch.
pub fn tag<G: Signer>(
&mut self,