From e49226c50023e012657c022009d58489054d6f99 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Tue, 3 Jan 2023 15:06:34 +0100 Subject: [PATCH] cli: Make some changes to issue listing * Use an `--assigned` flag * Default to listing all issues Signed-off-by: Alexis Sellier --- radicle-cli/examples/rad-issue.md | 4 +- radicle-cli/src/commands/issue.rs | 64 +++++++++++++------------------ 2 files changed, 28 insertions(+), 40 deletions(-) diff --git a/radicle-cli/examples/rad-issue.md b/radicle-cli/examples/rad-issue.md index 9c7317af..baf710be 100644 --- a/radicle-cli/examples/rad-issue.md +++ b/radicle-cli/examples/rad-issue.md @@ -28,11 +28,11 @@ $ rad assign de81d97d7fe07a80bfb339200c6af862d4526b6a z6MknSLrJoTcukLrE435hVNQT4 It will now show in the list of issues assigned to us. ``` -$ rad issue +$ rad issue list --assigned de81d97d7fe07a80bfb339200c6af862d4526b6a "flux capacitor underpowered" z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi ``` -Note: this can always be undone with the 'unassign' subcommand. +Note: this can always be undone with the `unassign` subcommand. ``` $ rad unassign de81d97d7fe07a80bfb339200c6af862d4526b6a z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi diff --git a/radicle-cli/src/commands/issue.rs b/radicle-cli/src/commands/issue.rs index bb6c597c..906030d2 100644 --- a/radicle-cli/src/commands/issue.rs +++ b/radicle-cli/src/commands/issue.rs @@ -26,7 +26,7 @@ Usage rad issue state [--closed | --open | --solved] rad issue delete rad issue react [--emoji ] - rad issue list [] + rad issue list [--assigned ] Options @@ -40,37 +40,25 @@ pub struct Metadata { labels: Vec, } -#[derive(Debug, PartialEq, Eq)] +#[derive(Default, Debug, PartialEq, Eq)] pub enum OperationName { Create, Delete, + #[default] List, - None, React, Show, State, } -impl Default for OperationName { - fn default() -> Self { - Self::None - } -} - /// Command line Peer argument. -#[derive(Debug, PartialEq, Eq)] -pub enum OptPeer { - Any, - CurrentUser, +#[derive(Default, Debug, PartialEq, Eq)] +pub enum Assigned { + #[default] + Me, Peer(cob::ActorId), } -impl Default for OptPeer { - fn default() -> Self { - OptPeer::Any - } -} - #[derive(Debug, PartialEq, Eq)] pub enum Operation { Create { @@ -92,7 +80,7 @@ pub enum Operation { reaction: Reaction, }, List { - assignee: OptPeer, + assigned: Option, }, } @@ -108,7 +96,7 @@ impl Args for Options { let mut parser = lexopt::Parser::from_args(args); let mut op: Option = None; let mut id: Option = None; - let mut assignee: OptPeer = OptPeer::default(); + let mut assigned: Option = None; let mut title: Option = None; let mut reaction: Option = None; let mut description: Option = None; @@ -144,6 +132,17 @@ impl Args for Options { Long("description") if op == Some(OperationName::Create) => { description = Some(parser.value()?.to_string_lossy().into()); } + Long("assigned") | Short('a') if assigned.is_none() => { + if let Ok(val) = parser.value() { + let val = val.to_string_lossy(); + let Ok(peer) = cob::ActorId::from_str(&val) else { + return Err(anyhow!("invalid peer ID '{}'", val)); + }; + assigned = Some(Assigned::Peer(peer)); + } else { + assigned = Some(Assigned::Me); + } + } Value(val) if op.is_none() => match val.to_string_lossy().as_ref() { "n" | "new" => op = Some(OperationName::Create), "c" | "show" => op = Some(OperationName::Show), @@ -154,14 +153,6 @@ impl Args for Options { unknown => anyhow::bail!("unknown operation '{}'", unknown), }, - Value(val) if op == Some(OperationName::List) && assignee == OptPeer::Any => { - let val = val.to_string_lossy(); - let Ok(val) = cob::ActorId::from_str(&val) else { - return Err(anyhow!("invalid peer ID '{}'", val)); - }; - - assignee = OptPeer::Peer(val) - } Value(val) if op.is_some() => { let val = val .to_str() @@ -179,9 +170,6 @@ impl Args for Options { } let op = match op.unwrap_or_default() { - OperationName::None => Operation::List { - assignee: OptPeer::CurrentUser, - }, OperationName::Create => Operation::Create { title, description }, OperationName::Show => Operation::Show { id: id.ok_or_else(|| anyhow!("an issue id must be provided"))?, @@ -197,7 +185,7 @@ impl Args for Options { OperationName::Delete => Operation::Delete { id: id.ok_or_else(|| anyhow!("an issue id to remove must be provided"))?, }, - OperationName::List => Operation::List { assignee }, + OperationName::List => Operation::List { assigned }, }; Ok((Options { op }, vec![])) @@ -279,11 +267,11 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { )?; } } - Operation::List { assignee } => { - let assignee = match assignee { - OptPeer::Any => None, - OptPeer::CurrentUser => Some(*profile.id()), - OptPeer::Peer(id) => Some(id), + Operation::List { assigned } => { + let assignee = match assigned { + Some(Assigned::Me) => Some(*profile.id()), + Some(Assigned::Peer(id)) => Some(id), + None => None, }; let mut t = term::Table::new(term::table::TableOptions::default());