Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Rework `rad sync` command
Alexis Sellier committed 3 years ago
commit 8202495e24b9dd00b4d2f422bd02b0dc83927ccc
parent fc951b82c65c58a126e5220c37fc103be540ed53
3 files changed +29 -11
modified radicle-cli/examples/git/git-push.md
@@ -56,6 +56,6 @@ f2de534b5e81d7c6e2dcaf58c3dd91573c0a0354 refs/heads/master
```

```
-
$ rad sync
+
$ rad sync --announce
✓ Synced with 1 node(s)
```
modified radicle-cli/examples/rad-sync.md
@@ -11,7 +11,7 @@ Now let's run `rad sync`. This will announce the issue refs to the network and
wait for nodes to announce that they have fetched those refs.

```
-
$ rad sync
+
$ rad sync --announce
✓ Synced with 2 node(s)
```

@@ -19,7 +19,7 @@ If we try to sync again after the nodes have synced, we will get a timeout
after one second, since the nodes will not emit any message:

``` (fail)
-
$ rad sync --timeout 1
+
$ rad sync --announce --timeout 1
✗ Syncing with 2 node(s)..
! Seed z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk timed out..
! Seed z6Mkux1aUQD2voWWukVb5nNUR7thrHveQG4pDQua8nVhib7Z timed out..
modified radicle-cli/src/commands/sync.rs
@@ -21,16 +21,24 @@ Usage

    rad sync [<rid>] [<option>...]
    rad sync [<rid>] [--fetch] [--seed <nid>] [<option>...]
+
    rad sync [<rid>] [--announce] [<option>...]

-
    By default, the current repository is synced.
+
    By default, the current repository is synchronized both ways.

-
    When `--fetch` is specified, this command will fetch from
-
    all connected seeds. To instead specify a seed, use the
-
    `--seed <nid>` option in combination with `--fetch`.
+
    The process begins by fetching changes from connected seeds,
+
    followed by announcing local refs to peers, thereby prompting
+
    them to fetch from us.
+

+
    When `--fetch` is specified, a seed may be given with the `--seed`
+
    option.
+

+
    When either `--fetch` or `--announce` are specified, this command
+
    will only fetch or announce.

Options

-
    --fetch, -f         Fetch from seeds instead of having seeds fetch from us
+
    --fetch, -f         Fetch from seeds
+
    --announce, -a      Announce refs to seeds
    --seed <nid>        Seed to fetch from (use with `--fetch`)
    --timeout <secs>    How many seconds to wait while syncing
    --verbose, -v       Verbose output
@@ -39,11 +47,12 @@ Options
"#,
};

-
#[derive(Default, Debug)]
+
#[derive(Default, Debug, PartialEq, Eq)]
pub enum SyncMode {
    Fetch,
-
    #[default]
    Announce,
+
    #[default]
+
    Both,
}

#[derive(Default, Debug)]
@@ -76,9 +85,12 @@ impl Args for Options {
                    let val = term::args::nid(&val)?;
                    seed = Some(val);
                }
-
                Long("fetch") | Short('f') => {
+
                Long("fetch") | Short('f') if mode == SyncMode::Both => {
                    mode = SyncMode::Fetch;
                }
+
                Long("announce") | Short('a') if mode == SyncMode::Both => {
+
                    mode = SyncMode::Announce;
+
                }
                Long("timeout") | Short('t') => {
                    let value = parser.value()?;
                    let secs = term::args::parse_value("timeout", value)?;
@@ -127,6 +139,12 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
    match options.mode {
        SyncMode::Announce => announce(rid, node, options.timeout),
        SyncMode::Fetch => fetch(rid, profile, &mut node, options.seed),
+
        SyncMode::Both => {
+
            fetch(rid, profile, &mut node, options.seed)?;
+
            announce(rid, node, options.timeout)?;
+

+
            Ok(())
+
        }
    }
}