Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
fixup! cli/issue: Parse arguments with clap
Matthias Beyer committed 9 months ago
commit db7041d8e3740858bc319596d20bcb36c2009853
parent d6489b199b6b9bc45c917876990e884dd85ef45d
2 files changed +25 -25
modified crates/radicle-cli/src/commands/issue.rs
@@ -23,7 +23,7 @@ use radicle::Profile;
use radicle::{cob, Node};

pub use args::Args;
-
use args::{Assigned, Commands, StateArg};
+
use args::{Assigned, Command, StateArg};

use crate::git::Rev;
use crate::node;
@@ -95,20 +95,20 @@ pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
    let announce = !args.no_announce
        && matches!(
            &command,
-
            Commands::Open { .. }
-
                | Commands::React { .. }
-
                | Commands::State { .. }
-
                | Commands::Delete { .. }
-
                | Commands::Assign { .. }
-
                | Commands::Label { .. }
-
                | Commands::Edit { .. }
-
                | Commands::Comment { .. }
+
            Command::Open { .. }
+
                | Command::React { .. }
+
                | Command::State { .. }
+
                | Command::Delete { .. }
+
                | Command::Assign { .. }
+
                | Command::Label { .. }
+
                | Command::Edit { .. }
+
                | Command::Comment { .. }
        );

    let mut issues = term::cob::issues_mut(&profile, &repo)?;

    match command {
-
        Commands::Edit {
+
        Command::Edit {
            id,
            title,
            description,
@@ -119,7 +119,7 @@ pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
                term::issue::show(&issue, issue.id(), Format::Header, args.verbose, &profile)?;
            }
        }
-
        Commands::Open {
+
        Command::Open {
            ref title,
            ref description,
            ref labels,
@@ -138,7 +138,7 @@ pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
                &profile,
            )?;
        }
-
        Commands::Comment {
+
        Command::Comment {
            id,
            message,
            reply_to,
@@ -163,7 +163,7 @@ pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
                term::comment::widget(&comment_id, comment, &profile).print();
            }
        }
-
        Commands::Comment {
+
        Command::Comment {
            id,
            message,
            reply_to: None,
@@ -195,10 +195,10 @@ pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
                term::comment::widget(&comment_id, comment, &profile).print();
            }
        }
-
        Commands::Comment { .. } => {
+
        Command::Comment { .. } => {
            todo!("We should use argument groups <https://docs.rs/clap/latest/clap/_derive/_tutorial/index.html#argument-relations> to ensure that comments can either be edited or composed (including a reply), but not both concurrently.")
        }
-
        Commands::Show { id } => {
+
        Command::Show { id } => {
            let format = if args.header {
                term::issue::Format::Header
            } else {
@@ -215,7 +215,7 @@ pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
                .context("No issue with the given ID exists")?;
            term::issue::show(&issue, &id, format, args.verbose, &profile)?;
        }
-
        Commands::State(state_args) => {
+
        Command::State(state_args) => {
            let id = state_args.id.clone();
            let to: StateArg = state_args.try_into()?;
            let id = id.resolve(&repo.backend)?;
@@ -236,7 +236,7 @@ pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
                };
            }
        }
-
        Commands::React {
+
        Command::React {
            id,
            reaction,
            comment_id,
@@ -256,7 +256,7 @@ pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
                issue.react(comment_id, reaction, true, &signer)?;
            }
        }
-
        Commands::Assign { id, add, delete } => {
+
        Command::Assign { id, add, delete } => {
            let signer = term::signer(&profile)?;
            let id = id.resolve(&repo.backend)?;
            let Ok(mut issue) = issues.get_mut(&id) else {
@@ -270,7 +270,7 @@ pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
                .collect::<Vec<_>>();
            issue.assign(assignees, &signer)?;
        }
-
        Commands::Label { id, add, delete } => {
+
        Command::Label { id, add, delete } => {
            let id = id.resolve(&repo.backend)?;
            let Ok(mut issue) = issues.get_mut(&id) else {
                anyhow::bail!("Issue `{id}` not found");
@@ -284,16 +284,16 @@ pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> {
            let signer = term::signer(&profile)?;
            issue.label(labels, &signer)?;
        }
-
        Commands::List(list_args) => {
+
        Command::List(list_args) => {
            let assigned = list_args.assigned.clone();
            list(issues, &assigned, &list_args.into(), &profile, args.verbose)?;
        }
-
        Commands::Delete { id } => {
+
        Command::Delete { id } => {
            let id = id.resolve(&repo.backend)?;
            let signer = term::signer(&profile)?;
            issues.remove(&id, &signer)?;
        }
-
        Commands::Cache { id, storage } => {
+
        Command::Cache { id, storage } => {
            let mode = if storage {
                cache::CacheMode::Storage
            } else {
modified crates/radicle-cli/src/commands/issue/args.rs
@@ -32,7 +32,7 @@ pub(crate) enum Assigned {
pub struct Args {
    /// Subcommand for `radicle issue`
    #[command(subcommand)]
-
    pub(crate) command: Option<Commands>,
+
    pub(crate) command: Option<Command>,

    /// Don't print anything
    #[arg(short, long)]
@@ -64,7 +64,7 @@ pub struct Args {

/// Commands to create, view, and edit Radicle issues
#[derive(Subcommand, Debug)]
-
pub(crate) enum Commands {
+
pub(crate) enum Command {
    /// Delete an issue
    Delete {
        /// The issue to delete
@@ -210,7 +210,7 @@ pub(crate) enum Commands {
    State(StateArgs),
}

-
impl Default for Commands {
+
impl Default for Command {
    fn default() -> Self {
        Self::List(ListArgs::default())
    }