cli: Make some changes to issue listing
* Use an `--assigned` flag * Default to listing all issues Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
parent
b7d0479b5c
commit
e49226c500
|
|
@ -28,11 +28,11 @@ $ rad assign de81d97d7fe07a80bfb339200c6af862d4526b6a z6MknSLrJoTcukLrE435hVNQT4
|
||||||
It will now show in the list of issues assigned to us.
|
It will now show in the list of issues assigned to us.
|
||||||
|
|
||||||
```
|
```
|
||||||
$ rad issue
|
$ rad issue list --assigned
|
||||||
de81d97d7fe07a80bfb339200c6af862d4526b6a "flux capacitor underpowered" z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
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
|
$ rad unassign de81d97d7fe07a80bfb339200c6af862d4526b6a z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ Usage
|
||||||
rad issue state <id> [--closed | --open | --solved]
|
rad issue state <id> [--closed | --open | --solved]
|
||||||
rad issue delete <id>
|
rad issue delete <id>
|
||||||
rad issue react <id> [--emoji <char>]
|
rad issue react <id> [--emoji <char>]
|
||||||
rad issue list [<assignee>]
|
rad issue list [--assigned <key>]
|
||||||
|
|
||||||
Options
|
Options
|
||||||
|
|
||||||
|
|
@ -40,37 +40,25 @@ pub struct Metadata {
|
||||||
labels: Vec<Tag>,
|
labels: Vec<Tag>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Default, Debug, PartialEq, Eq)]
|
||||||
pub enum OperationName {
|
pub enum OperationName {
|
||||||
Create,
|
Create,
|
||||||
Delete,
|
Delete,
|
||||||
|
#[default]
|
||||||
List,
|
List,
|
||||||
None,
|
|
||||||
React,
|
React,
|
||||||
Show,
|
Show,
|
||||||
State,
|
State,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for OperationName {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Command line Peer argument.
|
/// Command line Peer argument.
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Default, Debug, PartialEq, Eq)]
|
||||||
pub enum OptPeer {
|
pub enum Assigned {
|
||||||
Any,
|
#[default]
|
||||||
CurrentUser,
|
Me,
|
||||||
Peer(cob::ActorId),
|
Peer(cob::ActorId),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for OptPeer {
|
|
||||||
fn default() -> Self {
|
|
||||||
OptPeer::Any
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum Operation {
|
pub enum Operation {
|
||||||
Create {
|
Create {
|
||||||
|
|
@ -92,7 +80,7 @@ pub enum Operation {
|
||||||
reaction: Reaction,
|
reaction: Reaction,
|
||||||
},
|
},
|
||||||
List {
|
List {
|
||||||
assignee: OptPeer,
|
assigned: Option<Assigned>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,7 +96,7 @@ impl Args for Options {
|
||||||
let mut parser = lexopt::Parser::from_args(args);
|
let mut parser = lexopt::Parser::from_args(args);
|
||||||
let mut op: Option<OperationName> = None;
|
let mut op: Option<OperationName> = None;
|
||||||
let mut id: Option<IssueId> = None;
|
let mut id: Option<IssueId> = None;
|
||||||
let mut assignee: OptPeer = OptPeer::default();
|
let mut assigned: Option<Assigned> = None;
|
||||||
let mut title: Option<String> = None;
|
let mut title: Option<String> = None;
|
||||||
let mut reaction: Option<Reaction> = None;
|
let mut reaction: Option<Reaction> = None;
|
||||||
let mut description: Option<String> = None;
|
let mut description: Option<String> = None;
|
||||||
|
|
@ -144,6 +132,17 @@ impl Args for Options {
|
||||||
Long("description") if op == Some(OperationName::Create) => {
|
Long("description") if op == Some(OperationName::Create) => {
|
||||||
description = Some(parser.value()?.to_string_lossy().into());
|
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() {
|
Value(val) if op.is_none() => match val.to_string_lossy().as_ref() {
|
||||||
"n" | "new" => op = Some(OperationName::Create),
|
"n" | "new" => op = Some(OperationName::Create),
|
||||||
"c" | "show" => op = Some(OperationName::Show),
|
"c" | "show" => op = Some(OperationName::Show),
|
||||||
|
|
@ -154,14 +153,6 @@ impl Args for Options {
|
||||||
|
|
||||||
unknown => anyhow::bail!("unknown operation '{}'", unknown),
|
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() => {
|
Value(val) if op.is_some() => {
|
||||||
let val = val
|
let val = val
|
||||||
.to_str()
|
.to_str()
|
||||||
|
|
@ -179,9 +170,6 @@ impl Args for Options {
|
||||||
}
|
}
|
||||||
|
|
||||||
let op = match op.unwrap_or_default() {
|
let op = match op.unwrap_or_default() {
|
||||||
OperationName::None => Operation::List {
|
|
||||||
assignee: OptPeer::CurrentUser,
|
|
||||||
},
|
|
||||||
OperationName::Create => Operation::Create { title, description },
|
OperationName::Create => Operation::Create { title, description },
|
||||||
OperationName::Show => Operation::Show {
|
OperationName::Show => Operation::Show {
|
||||||
id: id.ok_or_else(|| anyhow!("an issue id must be provided"))?,
|
id: id.ok_or_else(|| anyhow!("an issue id must be provided"))?,
|
||||||
|
|
@ -197,7 +185,7 @@ impl Args for Options {
|
||||||
OperationName::Delete => Operation::Delete {
|
OperationName::Delete => Operation::Delete {
|
||||||
id: id.ok_or_else(|| anyhow!("an issue id to remove must be provided"))?,
|
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![]))
|
Ok((Options { op }, vec![]))
|
||||||
|
|
@ -279,11 +267,11 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Operation::List { assignee } => {
|
Operation::List { assigned } => {
|
||||||
let assignee = match assignee {
|
let assignee = match assigned {
|
||||||
OptPeer::Any => None,
|
Some(Assigned::Me) => Some(*profile.id()),
|
||||||
OptPeer::CurrentUser => Some(*profile.id()),
|
Some(Assigned::Peer(id)) => Some(id),
|
||||||
OptPeer::Peer(id) => Some(id),
|
None => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut t = term::Table::new(term::table::TableOptions::default());
|
let mut t = term::Table::new(term::table::TableOptions::default());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue