Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
squash! Add --author and --authored flags to "rad issue (list)"
Fintan Halpenny committed 1 month ago
commit eb7f54a411b77a85fdc142938746aaca61b5b630
parent 9e8074690f35e40a1cb9fe36785b2bcb28ceb50b
2 files changed +41 -39
modified crates/radicle-cli/src/commands/issue.rs
@@ -198,19 +198,11 @@ pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
            issue.label(labels, &signer)?;
        }
        Command::List(list_args) => {
-
            let mut authors: BTreeSet<Did> = list_args.authors.iter().cloned().collect();
-
            if list_args.authored {
-
                authors.insert(profile.did());
-
            }
+
            let state = (&list_args.state).into();
+
            let assigned = list_args.assigned;
+
            let authors = list_args.authors(&profile);

-
            list(
-
                issues,
-
                authors,
-
                &list_args.assigned,
-
                &((&list_args.state).into()),
-
                &profile,
-
                args.verbose,
-
            )?;
+
            list(issues, authors, &assigned, &state, &profile, args.verbose)?;
        }
        Command::Delete { id } => {
            let id = id.resolve(&repo.backend)?;
modified crates/radicle-cli/src/commands/issue/args.rs
@@ -1,4 +1,4 @@
-
use std::str::FromStr;
+
use std::{collections::BTreeSet, str::FromStr};

use clap::{Parser, Subcommand};

@@ -10,7 +10,7 @@ use radicle::{

use crate::{git::Rev, terminal::patch::Message};

-
#[derive(Default, Debug, Clone, PartialEq, Eq)]
+
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq)]
pub enum Assigned {
    #[default]
    Me,
@@ -203,16 +203,7 @@ impl Command {

/// Arguments for the empty subcommand.
#[derive(Parser, Debug, Default)]
-
pub(crate) struct EmptyArgs {
-
    #[arg(long, name = "DID")]
-
    #[arg(default_missing_value = "me")]
-
    #[arg(num_args = 0..=1)]
-
    #[arg(hide = true)]
-
    pub(crate) assigned: Option<Assigned>,
-

-
    #[clap(flatten)]
-
    pub(crate) state: EmptyStateArgs,
-

+
pub(crate) struct AuthorArgs {
    /// Show only issues where the given user is an author (may be specified
    /// multiple times)
    #[arg(
@@ -221,11 +212,36 @@ pub(crate) struct EmptyArgs {
        num_args = 1..,
        action = clap::ArgAction::Append,
    )]
-
    pub(super) authors: Vec<Did>,
+
    authors: Vec<Did>,

    /// Show only issues that you have authored
    #[arg(long)]
-
    pub(super) authored: bool,
+
    authored: bool,
+
}
+

+
impl AuthorArgs {
+
    pub(super) fn authors(self, profile: &radicle::profile::Profile) -> BTreeSet<Did> {
+
        self.authors
+
            .into_iter()
+
            .chain(self.authored.then(|| profile.did()))
+
            .collect()
+
    }
+
}
+

+
/// Arguments for the empty subcommand.
+
#[derive(Parser, Debug, Default)]
+
pub(crate) struct EmptyArgs {
+
    #[arg(long, name = "DID")]
+
    #[arg(default_missing_value = "me")]
+
    #[arg(num_args = 0..=1)]
+
    #[arg(hide = true)]
+
    pub(crate) assigned: Option<Assigned>,
+

+
    #[clap(flatten)]
+
    pub(crate) state: EmptyStateArgs,
+

+
    #[clap(flatten)]
+
    authors: AuthorArgs,
}

/// Counterpart to [`ListStateArgs`] for the empty subcommand.
@@ -257,19 +273,14 @@ pub(crate) struct ListArgs {
    #[clap(flatten)]
    pub(crate) state: ListStateArgs,

-
    /// Show only issues where the given user is an author (may be specified
-
    /// multiple times)
-
    #[arg(
-
        long = "author",
-
        value_name = "DID",
-
        num_args = 1..,
-
        action = clap::ArgAction::Append,
-
    )]
-
    pub(super) authors: Vec<Did>,
+
    #[clap(flatten)]
+
    authors: AuthorArgs,
+
}

-
    /// Show only issues that you have authored
-
    #[arg(long)]
-
    pub(super) authored: bool,
+
impl ListArgs {
+
    pub(super) fn authors(self, profile: &radicle::profile::Profile) -> BTreeSet<Did> {
+
        self.authors.authors(profile)
+
    }
}

#[derive(Parser, Debug, Default)]
@@ -325,7 +336,6 @@ impl From<EmptyArgs> for ListArgs {
            assigned: args.assigned,
            state: ListStateArgs::from(args.state),
            authors: args.authors,
-
            authored: args.authored,
        }
    }
}