From 257b950d6f45b8f99db8c0463aec339899441d20 Mon Sep 17 00:00:00 2001 From: cloudhead Date: Tue, 29 Aug 2023 12:03:44 +0200 Subject: [PATCH] cli: Add `--private` option to `rad init` Enables private repository initialization. --- radicle-cli/src/commands/init.rs | 10 ++++++++-- radicle/src/identity/doc.rs | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/radicle-cli/src/commands/init.rs b/radicle-cli/src/commands/init.rs index 8f0d0158..349a5392 100644 --- a/radicle-cli/src/commands/init.rs +++ b/radicle-cli/src/commands/init.rs @@ -34,6 +34,7 @@ Options --description Description of the project --default-branch The default branch of the project --scope Tracking scope (default: all) + --private Set repository visibility to *private* (default: public) -u, --set-upstream Setup the upstream of the default branch --setup-signing Setup the radicle key as a signing key for this repository --announce Announce the new project to the network @@ -50,6 +51,7 @@ pub struct Options { pub description: Option, pub branch: Option, pub interactive: Interactive, + pub visibility: Visibility, pub setup_signing: bool, pub scope: Scope, pub set_upstream: bool, @@ -75,6 +77,7 @@ impl Args for Options { let mut scope = Scope::All; let mut track = true; let mut verbose = false; + let mut visibility = Visibility::default(); while let Some(arg) = parser.next()? { match arg { @@ -130,6 +133,9 @@ impl Args for Options { Long("no-track") => { track = false; } + Long("private") => { + visibility = Visibility::private([]); + } Long("verbose") | Short('v') => { verbose = true; } @@ -155,6 +161,7 @@ impl Args for Options { setup_signing, announce, track, + visibility, verbose, }, vec![], @@ -173,7 +180,6 @@ pub fn init(options: Options, profile: &profile::Profile) -> anyhow::Result<()> let path = options.path.unwrap_or_else(|| cwd.clone()); let path = path.as_path().canonicalize()?; let interactive = options.interactive; - let visibility = Visibility::default(); term::headline(format!( "Initializing radicle 👾 project in {}", @@ -224,7 +230,7 @@ pub fn init(options: Options, profile: &profile::Profile) -> anyhow::Result<()> &name, &description, branch, - visibility, + options.visibility, &signer, &profile.storage, ) { diff --git a/radicle/src/identity/doc.rs b/radicle/src/identity/doc.rs index ac81b020..add86ee8 100644 --- a/radicle/src/identity/doc.rs +++ b/radicle/src/identity/doc.rs @@ -150,9 +150,17 @@ pub enum Visibility { } impl Visibility { + /// Check whether the visibility is public. pub fn is_public(&self) -> bool { matches!(self, Self::Public) } + + /// Private visibility with list of allowed DIDs beyond the repository delegates. + pub fn private(allow: impl Into>) -> Self { + Self::Private { + allow: allow.into(), + } + } } /// An identity document.