cli: Add `--private` option to `rad init`

Enables private repository initialization.
This commit is contained in:
cloudhead 2023-08-29 12:03:44 +02:00
parent 27f39514d4
commit 257b950d6f
No known key found for this signature in database
2 changed files with 16 additions and 2 deletions

View File

@ -34,6 +34,7 @@ Options
--description <string> Description of the project --description <string> Description of the project
--default-branch <name> The default branch of the project --default-branch <name> The default branch of the project
--scope <scope> Tracking scope (default: all) --scope <scope> Tracking scope (default: all)
--private Set repository visibility to *private* (default: public)
-u, --set-upstream Setup the upstream of the default branch -u, --set-upstream Setup the upstream of the default branch
--setup-signing Setup the radicle key as a signing key for this repository --setup-signing Setup the radicle key as a signing key for this repository
--announce Announce the new project to the network --announce Announce the new project to the network
@ -50,6 +51,7 @@ pub struct Options {
pub description: Option<String>, pub description: Option<String>,
pub branch: Option<String>, pub branch: Option<String>,
pub interactive: Interactive, pub interactive: Interactive,
pub visibility: Visibility,
pub setup_signing: bool, pub setup_signing: bool,
pub scope: Scope, pub scope: Scope,
pub set_upstream: bool, pub set_upstream: bool,
@ -75,6 +77,7 @@ impl Args for Options {
let mut scope = Scope::All; let mut scope = Scope::All;
let mut track = true; let mut track = true;
let mut verbose = false; let mut verbose = false;
let mut visibility = Visibility::default();
while let Some(arg) = parser.next()? { while let Some(arg) = parser.next()? {
match arg { match arg {
@ -130,6 +133,9 @@ impl Args for Options {
Long("no-track") => { Long("no-track") => {
track = false; track = false;
} }
Long("private") => {
visibility = Visibility::private([]);
}
Long("verbose") | Short('v') => { Long("verbose") | Short('v') => {
verbose = true; verbose = true;
} }
@ -155,6 +161,7 @@ impl Args for Options {
setup_signing, setup_signing,
announce, announce,
track, track,
visibility,
verbose, verbose,
}, },
vec![], 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 = options.path.unwrap_or_else(|| cwd.clone());
let path = path.as_path().canonicalize()?; let path = path.as_path().canonicalize()?;
let interactive = options.interactive; let interactive = options.interactive;
let visibility = Visibility::default();
term::headline(format!( term::headline(format!(
"Initializing radicle 👾 project in {}", "Initializing radicle 👾 project in {}",
@ -224,7 +230,7 @@ pub fn init(options: Options, profile: &profile::Profile) -> anyhow::Result<()>
&name, &name,
&description, &description,
branch, branch,
visibility, options.visibility,
&signer, &signer,
&profile.storage, &profile.storage,
) { ) {

View File

@ -150,9 +150,17 @@ pub enum Visibility {
} }
impl Visibility { impl Visibility {
/// Check whether the visibility is public.
pub fn is_public(&self) -> bool { pub fn is_public(&self) -> bool {
matches!(self, Self::Public) matches!(self, Self::Public)
} }
/// Private visibility with list of allowed DIDs beyond the repository delegates.
pub fn private(allow: impl Into<Vec<Did>>) -> Self {
Self::Private {
allow: allow.into(),
}
}
} }
/// An identity document. /// An identity document.