Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
REVIEW: handle empty arguments
Fintan Halpenny committed 6 months ago
commit c3f320dd9d73b32d2898f0cfaf0168e8a5bd959b
parent 1a42b505671c6eb64fbf0e5bdc52491ec0777fc1
2 files changed +61 -37
modified crates/radicle-cli/src/commands/inbox.rs
@@ -24,34 +24,31 @@ use radicle::{cob, git, Storage};
use term::Element as _;

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

pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
    let profile = ctx.profile()?;
    let storage = &profile.storage;
    let mut cache = profile.notifications_mut()?;
-
    let command = args.command.unwrap_or_default();
+
    let command = args
+
        .command
+
        .unwrap_or_else(|| Command::List(args.empty.into()));

    match command {
-
        Command::List {
+
        Command::List(ListArgs {
            sort_by,
            reverse,
            show_unknown,
-
        } => {
-
            let reverse = reverse.unwrap_or(false);
-
            let show_unknown = show_unknown.unwrap_or(false);
-

-
            list(
-
                &cache.read_only(),
-
                args.all,
-
                args.repo,
-
                sort_by,
-
                reverse,
-
                show_unknown,
-
                storage,
-
                &profile,
-
            )
-
        }
+
        }) => list(
+
            &cache.read_only(),
+
            args.all,
+
            args.repo,
+
            sort_by,
+
            reverse,
+
            show_unknown,
+
            storage,
+
            &profile,
+
        ),
        Command::Clear { ids } => clear(&mut cache, args.all, args.repo, ids),
        Command::Show { id } => show(&mut cache, id, storage, &profile),
    }
modified crates/radicle-cli/src/commands/inbox/args.rs
@@ -34,24 +34,15 @@ pub struct Args {
    #[arg(short, long, conflicts_with = "repo")]
    #[clap(global = true)]
    pub(crate) all: bool,
+

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

#[derive(Subcommand, Debug)]
pub(crate) enum Command {
    /// List all items in your inbox
-
    List {
-
        /// Sort by column
-
        #[arg(long, value_enum, default_value_t)]
-
        sort_by: SortBy,
-

-
        /// Reverse the list
-
        #[arg(short, long)]
-
        reverse: Option<bool>,
-

-
        /// Show any updates that were not recognized
-
        #[arg(long)]
-
        show_unknown: Option<bool>,
-
    },
+
    List(ListArgs),
    /// Show a notification
    Show {
        /// The notification to display
@@ -66,12 +57,48 @@ pub(crate) enum Command {
    },
}

-
impl Default for Command {
-
    fn default() -> Self {
-
        Command::List {
-
            sort_by: SortBy::default(),
-
            reverse: None,
-
            show_unknown: None,
+
#[derive(Parser, Debug)]
+
pub struct EmptyArgs {
+
    /// Sort by column
+
    #[arg(long, value_enum, default_value_t, hide = true)]
+
    sort_by: SortBy,
+

+
    /// Reverse the list
+
    #[arg(short, long, hide = true)]
+
    reverse: bool,
+

+
    /// Show any updates that were not recognized
+
    #[arg(long, hide = true)]
+
    show_unknown: bool,
+
}
+

+
#[derive(Parser, Debug)]
+
pub struct ListArgs {
+
    /// Sort by column
+
    #[arg(long, value_enum, default_value_t)]
+
    pub(super) sort_by: SortBy,
+

+
    /// Reverse the list
+
    #[arg(short, long)]
+
    pub(super) reverse: bool,
+

+
    /// Show any updates that were not recognized
+
    #[arg(long)]
+
    pub(super) show_unknown: bool,
+
}
+

+
impl From<EmptyArgs> for ListArgs {
+
    fn from(
+
        EmptyArgs {
+
            sort_by,
+
            reverse,
+
            show_unknown,
+
        }: EmptyArgs,
+
    ) -> Self {
+
        Self {
+
            sort_by,
+
            reverse,
+
            show_unknown,
        }
    }
}