Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
REVIEW: Handle default subcommand like `rad issue`
✗ CI failure Lorenz Leutgeb committed 6 months ago
commit 9f37f1f1bf16a6df147933977b2d22971997f866
parent 329b11b6682fdf4cf30d2d2cf1989e4787af7a6f
1 failed 1 pending (2 total) View logs
2 files changed +33 -24
modified crates/radicle-cli/src/commands/remote.rs
@@ -21,7 +21,9 @@ pub fn run(args: Args, ctx: impl Context) -> anyhow::Result<()> {
    let (working, rid) = radicle::rad::cwd()
        .map_err(|_| anyhow!("this command must be run in the context of a repository"))?;
    let profile = ctx.profile()?;
-
    let command = args.command.unwrap_or_default();
+
    let command = args
+
        .command
+
        .unwrap_or_else(|| Command::List(args.empty.into()));
    match command {
        Command::Add {
            nid,
@@ -43,7 +45,7 @@ pub fn run(args: Args, ctx: impl Context) -> anyhow::Result<()> {
            )?
        }
        Command::Rm { ref name } => self::rm::run(name, &working)?,
-
        Command::List { args } => match ListOption::from(args) {
+
        Command::List(args) => match ListOption::from(args) {
            ListOption::All => {
                let tracked = list::tracked(&working)?;
                let untracked = list::untracked(rid, &profile, tracked.iter())?;
modified crates/radicle-cli/src/commands/remote/args.rs
@@ -13,6 +13,11 @@ pub(crate) const ABOUT: &str = "Manage a repository's remotes";
pub struct Args {
    #[command(subcommand)]
    pub(super) command: Option<Command>,
+

+
    /// Arguments for the empty subcommand.
+
    /// Will fall back to [`Command::List`].
+
    #[clap(flatten)]
+
    pub(super) empty: EmptyArgs,
}

#[derive(Subcommand, Debug)]
@@ -47,18 +52,7 @@ pub(super) enum Command {
    ///
    /// Filter the listed remotes using the provided options
    #[clap(alias = "l")]
-
    List {
-
        #[clap(flatten)]
-
        args: ListArgs,
-
    },
-
}
-

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

#[derive(Parser, Debug)]
@@ -113,16 +107,6 @@ pub struct ListArgs {
    untracked: bool,
}

-
impl Default for ListArgs {
-
    fn default() -> Self {
-
        Self {
-
            all: false,
-
            tracked: true,
-
            untracked: false,
-
        }
-
    }
-
}
-

impl From<ListArgs> for ListOption {
    fn from(
        ListArgs {
@@ -149,6 +133,29 @@ pub(super) enum ListOption {
    Untracked,
}

+
#[derive(Parser, Clone, Copy, Debug)]
+
#[group(multiple = false)]
+
pub(super) struct EmptyArgs {
+
    #[arg(long, hide = true)]
+
    all: bool,
+

+
    #[arg(long, hide = true)]
+
    tracked: bool,
+

+
    #[arg(long, hide = true)]
+
    untracked: bool,
+
}
+

+
impl From<EmptyArgs> for ListArgs {
+
    fn from(args: EmptyArgs) -> Self {
+
        Self {
+
            all: args.all,
+
            tracked: args.tracked,
+
            untracked: args.untracked,
+
        }
+
    }
+
}
+

fn parse_refstr(refstr: &str) -> Result<RefString, git::fmt::Error> {
    RefString::try_from(refstr)
}