Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Change rad init default to not announce
Adrian Duke committed 2 months ago
commit 4669ddf43f28b4dd622089255eeb5cb0baa6826b
parent b04f487b3ae2efcd23f52f8138abe32e73a718fd
12 files changed +41 -17
modified crates/radicle-cli/examples/rad-init-no-seed.md
@@ -1,6 +1,7 @@
If we initialize a public repository without seeding it, it won't be advertised:
+

```
-
$ rad init --name heartwood --description "radicle heartwood protocol & stack" --no-confirm --public --no-seed
+
$ rad init --name heartwood --description "radicle heartwood protocol & stack" --no-confirm --public --no-seed --announce

Initializing public radicle 👾 repository in [..]

@@ -13,16 +14,19 @@ Your repository will be announced to the network when you start your node.
You can start your node with `rad node start`.
To push changes, run `git push`.
```
+

```
$ rad node inventory
```

If we then seed it, it becomes advertised in our inventory:
+

```
$ rad seed rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK
✓ Inventory updated with rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK
✓ Seeding policy updated for rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK with scope 'followed'
```
+

```
$ rad node inventory
rad:zhbMU4DUXrzB8xT6qAJh6yZ7bFMK
modified crates/radicle-cli/examples/rad-init-private-no-seed.md
@@ -3,7 +3,7 @@ to be seeded. This means that the repo will be available locally, to us,
and even if other peers know about it, they won't be able to fetch it
from us.
```
-
$ rad init --name heartwood --description "radicle heartwood protocol & stack" --no-confirm --private --no-seed
+
$ rad init --name heartwood --description "radicle heartwood protocol & stack" --no-confirm --private --no-seed --announce

Initializing private radicle 👾 repository in [..]

modified crates/radicle-cli/examples/rad-init-private.md
@@ -1,7 +1,7 @@
Alice can initialize a *private* repo using the `--private` flag.

```
-
$ rad init --name heartwood --description "radicle heartwood protocol & stack" --no-confirm --private
+
$ rad init --name heartwood --description "radicle heartwood protocol & stack" --no-confirm --private --announce

Initializing private radicle 👾 repository in [..]

modified crates/radicle-cli/examples/rad-init-sync-not-connected.md
@@ -1,7 +1,7 @@
When initializing a repository without any peer connections, we get this output:

```
-
$ rad init --name heartwood --description "Radicle Heartwood Protocol & Stack" --no-confirm --public --scope followed
+
$ rad init --name heartwood --description "Radicle Heartwood Protocol & Stack" --no-confirm --public --scope followed --announce

Initializing public radicle 👾 repository in [..]

modified crates/radicle-cli/examples/rad-init-sync-preferred.md
@@ -1,7 +1,7 @@
Let's try initializing a new repository with a preferred seed configured.

```
-
$ rad init --name heartwood --description "Radicle Heartwood Protocol & Stack" --no-confirm --public --scope followed
+
$ rad init --name heartwood --description "Radicle Heartwood Protocol & Stack" --no-confirm --public --scope followed --announce

Initializing public radicle 👾 repository in [..]

modified crates/radicle-cli/examples/rad-init-sync-timeout.md
@@ -2,7 +2,7 @@ Sometimes, `init` will fail to sync with the network. This is not a big deal,
as the node will keep attempting to sync in the background.

```
-
$ rad init --name heartwood --description "Radicle Heartwood Protocol & Stack" --no-confirm --public --scope followed
+
$ rad init --name heartwood --description "Radicle Heartwood Protocol & Stack" --no-confirm --public --scope followed --announce

Initializing public radicle 👾 repository in [..]

modified crates/radicle-cli/examples/rad-init-sync.md
@@ -3,7 +3,7 @@ To create your first radicle repository, navigate to a git repository, and run
the `init` command:

```
-
$ rad init --name heartwood --description "Radicle Heartwood Protocol & Stack" --no-confirm --public --scope followed
+
$ rad init --name heartwood --description "Radicle Heartwood Protocol & Stack" --no-confirm --public --scope followed --announce

Initializing public radicle 👾 repository in [..]

modified crates/radicle-cli/examples/rad-init-with-existing-remote.md
@@ -20,7 +20,7 @@ $ git branch -vv
Then we initialize.

```
-
$ rad init --name heartwood --description "Heartwood Protocol & Stack" --no-confirm --public
+
$ rad init --name heartwood --description "Heartwood Protocol & Stack" --no-confirm --public --announce

Initializing public radicle 👾 repository in [..]

@@ -36,7 +36,7 @@ To push changes, run `git push rad master`.

Finally we run the suggested command.

-
``` (stderr)
+
```(stderr)
$ git push rad master
Everything up-to-date
```
modified crates/radicle-cli/examples/rad-init.md
@@ -3,7 +3,7 @@ To create your first radicle repository, navigate to a git repository, and run t
`init` command.  Make sure you have [authenticated](../rad-auth.md) beforehand.

```
-
$ rad init --name heartwood --description "Radicle Heartwood Protocol & Stack" --no-confirm --public -v
+
$ rad init --name heartwood --description "Radicle Heartwood Protocol & Stack" --no-confirm --public --announce -v

Initializing public radicle 👾 repository in [..]

modified crates/radicle-cli/examples/rad-patch-pull-update.md
@@ -3,7 +3,7 @@ Let's look at how patch updates work.
Alice creates a repository and Bob clones it.

``` ~alice
-
$ rad init --name heartwood --description "radicle heartwood protocol & stack" --no-confirm --public
+
$ rad init --name heartwood --description "radicle heartwood protocol & stack" --no-confirm --public --announce

Initializing public radicle 👾 repository in [..]

modified crates/radicle-cli/src/commands/init.rs
@@ -59,6 +59,7 @@ pub fn init(repo: git::Repository, args: Args, profile: &profile::Profile) -> an
    let interactive = args.interactive();
    let visibility = args.visibility();
    let seed = args.seed();
+
    let should_announce = args.should_announce();

    let default_branch = match find_default_branch(&repo) {
        Err(err @ DefaultBranchError::Head) => {
@@ -204,12 +205,17 @@ pub fn init(repo: git::Repository, args: Args, profile: &profile::Profile) -> an
            term::blank();

            // Announce inventory to network.
-
            if let Err(e) = announce(rid, doc, &mut node, &profile.config) {
-
                term::blank();
-
                term::warning(format!(
-
                    "There was an error announcing your repository to the network: {e}"
-
                ));
-
                term::warning("Try again with `rad sync --announce`, or check your logs with `rad node logs`.");
+
            if should_announce {
+
                if let Err(e) = announce(rid, doc, &mut node, &profile.config) {
+
                    term::blank();
+
                    term::warning(format!(
+
                        "There was an error announcing your repository to the network: {e}"
+
                    ));
+
                    term::warning("Try again with `rad sync --announce`, or check your logs with `rad node logs`.");
+
                    term::blank();
+
                }
+
            } else {
+
                term::info!("Your repository has not been announced to the network, run `rad sync --announce` when you're ready.");
                term::blank();
            }
            term::info!("To push changes, run {}.", term::format::command(push_cmd));
modified crates/radicle-cli/src/commands/init/args.rs
@@ -55,6 +55,12 @@ pub struct Args {
    /// Don't seed this repository after initializing it
    #[arg(long)]
    no_seed: bool,
+
    /// Announce changes made to the network
+
    #[arg(long, global = true, conflicts_with = "no_announce")]
+
    announce: bool,
+
    /// Do not announce changes made to the network
+
    #[arg(long, global = true, conflicts_with = "announce")]
+
    no_announce: bool,
    /// Verbose mode
    #[arg(short, long)]
    pub(super) verbose: bool,
@@ -83,6 +89,14 @@ impl Args {
    pub(super) fn seed(&self) -> bool {
        !self.no_seed
    }
+

+
    pub(super) fn should_announce(&self) -> bool {
+
        match (self.announce, self.no_announce) {
+
            (false, true) | (false, false) => false,
+
            (true, false) => true,
+
            (true, true) => false,
+
        }
+
    }
}

// TODO(finto): this is duplicated from `clone::args`. Consolidate these once