From 80198d68b6a31ae45ea013bf18446e056bb141e3 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Wed, 15 Oct 2025 01:03:58 +0200 Subject: [PATCH] cli: Share value parser for `Scope` --- crates/radicle-cli/src/commands/clone/args.rs | 33 ++++--------------- crates/radicle-cli/src/terminal/args.rs | 28 ++++++++++++++++ 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/crates/radicle-cli/src/commands/clone/args.rs b/crates/radicle-cli/src/commands/clone/args.rs index 364acb0e..0d92d7b4 100644 --- a/crates/radicle-cli/src/commands/clone/args.rs +++ b/crates/radicle-cli/src/commands/clone/args.rs @@ -9,6 +9,8 @@ use radicle::identity::IdError; use radicle::node::policy::Scope; use radicle::prelude::*; +use crate::terminal; + pub(crate) const ABOUT: &str = "Clone a Radicle repository"; const LONG_ABOUT: &str = r#" @@ -44,31 +46,6 @@ impl From for SyncSettings { } } -#[derive(Clone, Debug)] -struct ScopeParser; - -impl clap::builder::TypedValueParser for ScopeParser { - type Value = Scope; - - fn parse_ref( - &self, - cmd: &clap::Command, - arg: Option<&clap::Arg>, - value: &std::ffi::OsStr, - ) -> Result { - ::from_str.parse_ref(cmd, arg, value) - } - - fn possible_values( - &self, - ) -> Option + '_>> { - use clap::builder::PossibleValue; - Some(Box::new( - [PossibleValue::new("all"), PossibleValue::new("followed")].into_iter(), - )) - } -} - #[derive(Debug, Parser)] #[clap(about = ABOUT, long_about = LONG_ABOUT, disable_version_flag = true)] pub struct Args { @@ -83,7 +60,11 @@ pub struct Args { pub(super) directory: Option, /// Follow scope - #[arg(long, default_value_t = Scope::All, value_name = "SCOPE", value_parser = ScopeParser)] + #[arg( + long, + default_value_t = Scope::All, + value_parser = terminal::args::ScopeParser + )] pub(super) scope: Scope, #[clap(flatten)] diff --git a/crates/radicle-cli/src/terminal/args.rs b/crates/radicle-cli/src/terminal/args.rs index c3c511d1..33b2ee1f 100644 --- a/crates/radicle-cli/src/terminal/args.rs +++ b/crates/radicle-cli/src/terminal/args.rs @@ -5,9 +5,12 @@ use std::time; use anyhow::anyhow; +use clap::builder::TypedValueParser; + use radicle::cob::{self, issue, patch}; use radicle::crypto; use radicle::git::{fmt::RefString, Oid}; +use radicle::node::policy::Scope; use radicle::node::{Address, Alias}; use radicle::prelude::{Did, NodeId, RepoId}; @@ -203,3 +206,28 @@ pub fn cob(val: &OsString) -> anyhow::Result { let val = val.to_string_lossy(); cob::ObjectId::from_str(&val).map_err(|_| anyhow!("invalid Object ID '{}'", val)) } + +#[derive(Clone, Debug)] +pub(crate) struct ScopeParser; + +impl TypedValueParser for ScopeParser { + type Value = Scope; + + fn parse_ref( + &self, + cmd: &clap::Command, + arg: Option<&clap::Arg>, + value: &std::ffi::OsStr, + ) -> Result { + ::from_str.parse_ref(cmd, arg, value) + } + + fn possible_values( + &self, + ) -> Option + '_>> { + use clap::builder::PossibleValue; + Some(Box::new( + [PossibleValue::new("all"), PossibleValue::new("followed")].into_iter(), + )) + } +}