Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Share value parser for `Scope`
Erik Kundt committed 6 months ago
commit 8be038b956dea2b66eddb4eebd3a237f5e78ad6f
parent 0b3424857ec1c5b57d6778f2bf6f379685e7f073
2 files changed +35 -26
modified 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<SyncArgs> 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<Self::Value, clap::Error> {
-
        <Scope as std::str::FromStr>::from_str.parse_ref(cmd, arg, value)
-
    }
-

-
    fn possible_values(
-
        &self,
-
    ) -> Option<Box<dyn Iterator<Item = clap::builder::PossibleValue> + '_>> {
-
        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<PathBuf>,

    /// 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)]
modified 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<cob::ObjectId> {
    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<Self::Value, clap::Error> {
+
        <Scope as std::str::FromStr>::from_str.parse_ref(cmd, arg, value)
+
    }
+

+
    fn possible_values(
+
        &self,
+
    ) -> Option<Box<dyn Iterator<Item = clap::builder::PossibleValue> + '_>> {
+
        use clap::builder::PossibleValue;
+
        Some(Box::new(
+
            [PossibleValue::new("all"), PossibleValue::new("followed")].into_iter(),
+
        ))
+
    }
+
}