Skip to main content

radicle_cli/commands/publish/
args.rs

1use radicle::identity::RepoId;
2
3const ABOUT: &str = "Publish a repository to the network";
4
5const LONG_ABOUT: &str = r#"
6Publishing a private repository makes it public and discoverable
7on the network.
8
9By default, this command will publish the current repository.
10If an `<rid>` is specified, that repository will be published instead.
11
12Note that this command can only be run for repositories with a
13single delegate. The delegate must be the currently authenticated
14user. For repositories with more than one delegate, the `rad id`
15command must be used."#;
16
17#[derive(Debug, clap::Parser)]
18#[command(about = ABOUT, long_about = LONG_ABOUT, disable_version_flag = true)]
19pub struct Args {
20    /// The Repository ID of the repository to publish
21    ///
22    /// [example values: rad:z3Tr6bC7ctEg2EHmLvknUr29mEDLH, z3Tr6bC7ctEg2EHmLvknUr29mEDLH]
23    #[arg(value_name = "RID")]
24    pub(super) rid: Option<RepoId>,
25}
26
27#[cfg(test)]
28mod test {
29    use super::Args;
30    use clap::error::ErrorKind;
31    use clap::Parser;
32
33    #[test]
34    fn should_parse_rid_non_urn() {
35        let args = Args::try_parse_from(["publish", "z3Tr6bC7ctEg2EHmLvknUr29mEDLH"]);
36        assert!(args.is_ok())
37    }
38
39    #[test]
40    fn should_parse_rid_urn() {
41        let args = Args::try_parse_from(["publish", "rad:z3Tr6bC7ctEg2EHmLvknUr29mEDLH"]);
42        assert!(args.is_ok())
43    }
44
45    #[test]
46    fn should_not_parse_rid_url() {
47        let err =
48            Args::try_parse_from(["publish", "rad://z3Tr6bC7ctEg2EHmLvknUr29mEDLH"]).unwrap_err();
49        assert_eq!(err.kind(), ErrorKind::ValueValidation);
50    }
51}