Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
REVIEW: un-global-ify repo and all
✗ CI failure Fintan Halpenny committed 6 months ago
commit 0dffc26dcf2ac437684ca5b7a049f7bbc72ea76f
parent 13ac93fed99a45683fde9c0fc6c1392f05be01da
1 failed (1 total) View logs
2 files changed +98 -59
modified crates/radicle-cli/src/commands/inbox.rs
@@ -24,7 +24,7 @@ use radicle::{cob, git, Storage};
use term::Element as _;

use crate::terminal as term;
-
use args::{ClearMode, Command, ListArgs, ListMode, SortBy};
+
use args::{ClearMode, Command, ListMode, SortBy};

pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
    let profile = ctx.profile()?;
@@ -36,20 +36,22 @@ pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
        .unwrap_or_else(|| Command::List(args.empty.into()));

    match command {
-
        Command::List(ListArgs {
-
            sort_by,
-
            reverse,
-
            show_unknown,
-
        }) => list(
-
            &notifs.read_only(),
-
            args.list_mode(),
-
            sort_by,
-
            reverse,
-
            show_unknown,
-
            storage,
-
            &profile,
-
        ),
-
        Command::Clear { ids } => clear(&mut notifs, args.clear_mode(ids)),
+
        Command::List(args) => {
+
            let show_unknown = args.show_unknown;
+
            let sort_by = args.sort_by;
+
            let reverse = args.reverse;
+

+
            list(
+
                &notifs.read_only(),
+
                args.into(),
+
                sort_by,
+
                reverse,
+
                show_unknown,
+
                storage,
+
                &profile,
+
            )
+
        }
+
        Command::Clear(args) => clear(&mut notifs, args.into()),
        Command::Show { id } => show(&mut notifs, id, storage, &profile),
    }
}
modified crates/radicle-cli/src/commands/inbox/args.rs
@@ -22,57 +22,25 @@ or all notifications if no ids were passed.
#[command(about = ABOUT, long_about = LONG_ABOUT, disable_version_flag = true)]
pub struct Args {
    #[command(subcommand)]
-
    pub(crate) command: Option<Command>,
+
    pub(super) command: Option<Command>,

    /// Operate on a given repository [default: cwd]
    #[arg(value_name = "RID")]
    #[arg(long)]
    #[clap(global = true)]
-
    pub(crate) repo: Option<RepoId>,
+
    pub(super) repo: Option<RepoId>,

    /// Operate on all repositories
    #[arg(short, long, conflicts_with = "repo")]
    #[clap(global = true)]
-
    pub(crate) all: bool,
+
    pub(super) all: bool,

    #[clap(flatten)]
-
    pub(crate) empty: EmptyArgs,
-
}
-

-
impl Args {
-
    pub(super) fn list_mode(&self) -> ListMode {
-
        if self.all {
-
            assert!(self.repo.is_none());
-
            return ListMode::All;
-
        }
-

-
        if let Some(repo) = self.repo {
-
            return ListMode::ByRepo(repo);
-
        }
-

-
        ListMode::Contextual
-
    }
-

-
    pub(super) fn clear_mode(&self, ids: Option<Vec<NotificationId>>) -> ClearMode {
-
        if let Some(ids) = ids {
-
            return ClearMode::ByNotifications(ids);
-
        }
-

-
        if self.all {
-
            assert!(self.repo.is_none());
-
            return ClearMode::All;
-
        }
-

-
        if let Some(repo) = self.repo {
-
            return ClearMode::ByRepo(repo);
-
        }
-

-
        ClearMode::Contextual
-
    }
+
    pub(super) empty: EmptyArgs,
}

#[derive(Subcommand, Clone, Debug)]
-
pub(crate) enum Command {
+
pub(super) enum Command {
    /// List all items in your inbox
    List(ListArgs),
    /// Show a notification
@@ -90,15 +58,11 @@ pub(crate) enum Command {
    /// This will clear all the specified notifications
    ///
    /// If no notifications are specified then all notifications are cleared
-
    Clear {
-
        /// A list of notifications to clear
-
        #[arg(value_name = "NOTIFICATION_ID")]
-
        ids: Option<Vec<NotificationId>>,
-
    },
+
    Clear(ClearArgs),
}

#[derive(Parser, Clone, Copy, Debug)]
-
pub struct EmptyArgs {
+
pub(super) struct EmptyArgs {
    /// Sort by column
    #[arg(long, value_enum, default_value_t, hide = true)]
    sort_by: SortBy,
@@ -110,10 +74,19 @@ pub struct EmptyArgs {
    /// Show any updates that were not recognized
    #[arg(long, hide = true)]
    show_unknown: bool,
+

+
    /// Operate on a given repository [default: cwd]
+
    #[arg(value_name = "RID")]
+
    #[arg(long, hide = true)]
+
    repo: Option<RepoId>,
+

+
    /// Operate on all repositories
+
    #[arg(short, long, conflicts_with = "repo", hide = true)]
+
    all: bool,
}

#[derive(Parser, Clone, Copy, Debug)]
-
pub struct ListArgs {
+
pub(super) struct ListArgs {
    /// Sort by column
    #[arg(long, value_enum, default_value_t)]
    pub(super) sort_by: SortBy,
@@ -125,6 +98,29 @@ pub struct ListArgs {
    /// Show any updates that were not recognized
    #[arg(long)]
    pub(super) show_unknown: bool,
+

+
    /// Operate on a given repository [default: cwd]
+
    #[arg(long, value_name = "RID")]
+
    pub(super) repo: Option<RepoId>,
+

+
    /// Operate on all repositories
+
    #[arg(short, long, conflicts_with = "repo")]
+
    pub(super) all: bool,
+
}
+

+
impl From<ListArgs> for ListMode {
+
    fn from(args: ListArgs) -> Self {
+
        if args.all {
+
            assert!(args.repo.is_none());
+
            return Self::All;
+
        }
+

+
        if let Some(repo) = args.repo {
+
            return Self::ByRepo(repo);
+
        }
+

+
        Self::Contextual
+
    }
}

impl From<EmptyArgs> for ListArgs {
@@ -133,16 +129,57 @@ impl From<EmptyArgs> for ListArgs {
            sort_by,
            reverse,
            show_unknown,
+
            repo,
+
            all,
        }: EmptyArgs,
    ) -> Self {
        Self {
            sort_by,
            reverse,
            show_unknown,
+
            repo,
+
            all,
        }
    }
}

+
#[derive(Parser, Clone, Debug)]
+
pub(super) struct ClearArgs {
+
    /// Operate on a given repository [default: cwd]
+
    #[arg(long, value_name = "RID")]
+
    repo: Option<RepoId>,
+

+
    /// Operate on all repositories
+
    #[arg(short, long, conflicts_with = "repo")]
+
    all: bool,
+

+
    /// A list of notifications to clear
+
    ///
+
    /// The --repo or --all options are ignored when the notification ID's are
+
    /// specified
+
    #[arg(value_name = "NOTIFICATION_ID")]
+
    ids: Option<Vec<NotificationId>>,
+
}
+

+
impl From<ClearArgs> for ClearMode {
+
    fn from(ClearArgs { repo, all, ids }: ClearArgs) -> Self {
+
        if let Some(ids) = ids {
+
            return Self::ByNotifications(ids);
+
        }
+

+
        if all {
+
            assert!(repo.is_none());
+
            return Self::All;
+
        }
+

+
        if let Some(repo) = repo {
+
            return Self::ByRepo(repo);
+
        }
+

+
        Self::Contextual
+
    }
+
}
+

#[derive(ValueEnum, Clone, Copy, Default, Debug)]
pub enum SortBy {
    Id,