cli: Add `--draft` to `patch list` command

This commit is contained in:
Alexis Sellier 2023-04-27 10:54:19 +02:00
parent 12a91bd0ae
commit 0ecd8fb074
No known key found for this signature in database
2 changed files with 14 additions and 5 deletions

View File

@ -40,7 +40,7 @@ pub const HELP: Help = Help {
Usage Usage
rad patch [<option>...] rad patch [<option>...]
rad patch list [--all|--merged|--open|--archived] [<option>...] rad patch list [--all|--merged|--open|--archived|--draft] [<option>...]
rad patch show <patch-id> [<option>...] rad patch show <patch-id> [<option>...]
rad patch open [--draft] [<option>...] rad patch open [--draft] [<option>...]
rad patch archive <patch-id> [<option>...] rad patch archive <patch-id> [<option>...]
@ -68,6 +68,7 @@ List options
--archived Show only archived patches --archived Show only archived patches
--merged Show only merged patches --merged Show only merged patches
--open Show only open patches (default) --open Show only open patches (default)
--draft Show only draft patches
Ready options Ready options
@ -209,6 +210,9 @@ impl Args for Options {
Long("all") => { Long("all") => {
filter = None; filter = None;
} }
Long("draft") => {
filter = Some(patch::State::Draft);
}
Long("archived") => { Long("archived") => {
filter = Some(patch::State::Archived); filter = Some(patch::State::Archived);
} }

View File

@ -276,12 +276,17 @@ impl Patch {
/// Check if the patch is open. /// Check if the patch is open.
pub fn is_open(&self) -> bool { pub fn is_open(&self) -> bool {
matches!(self.state.get().get(), State::Open) matches!(self.state(), State::Open)
} }
/// Check if the patch is archived. /// Check if the patch is archived.
pub fn is_archived(&self) -> bool { pub fn is_archived(&self) -> bool {
matches!(self.state.get().get(), &State::Archived) matches!(self.state(), State::Archived)
}
/// Check if the patch is a draft.
pub fn is_draft(&self) -> bool {
matches!(self.state(), State::Draft)
} }
} }
@ -982,7 +987,7 @@ impl<'a, 'g> PatchMut<'a, 'g> {
/// Mark a patch as ready to be reviewed. Returns `false` if the patch was not a draft. /// Mark a patch as ready to be reviewed. Returns `false` if the patch was not a draft.
pub fn ready<G: Signer>(&mut self, signer: &G) -> Result<bool, Error> { pub fn ready<G: Signer>(&mut self, signer: &G) -> Result<bool, Error> {
if self.state() != State::Draft { if !self.is_draft() {
return Ok(false); return Ok(false);
} }
self.lifecycle(State::Open, signer)?; self.lifecycle(State::Open, signer)?;
@ -992,7 +997,7 @@ impl<'a, 'g> PatchMut<'a, 'g> {
/// Mark an open patch as a draft. Returns `false` if the patch was not open. /// Mark an open patch as a draft. Returns `false` if the patch was not open.
pub fn unready<G: Signer>(&mut self, signer: &G) -> Result<bool, Error> { pub fn unready<G: Signer>(&mut self, signer: &G) -> Result<bool, Error> {
if self.state() != State::Open { if !self.is_open() {
return Ok(false); return Ok(false);
} }
self.lifecycle(State::Draft, signer)?; self.lifecycle(State::Draft, signer)?;