From 3c8952500303c4626050873cfa8f28a18995f42f Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Tue, 21 Oct 2025 12:18:12 +0100 Subject: [PATCH] cli/sync: migrate to clap Due to the idiosyncracies of this command there are a few things to note about this migration. The `rad sync` command acts as a default subcommand in itself, in that it has options that do not apply to its subcommand, `rad sync status`. This means that the options will print with `rad sync --help`, but they will not print with `rad sync status`. The `--inventory` flag is not compatible with any of the other flags and options, thus they are all marked with `conflicts_with`. This cannot be done for a positional argument, so `clap` will "helpfully" print out the usage, for example, as: error: the argument '--inventory' cannot be used with '--fetch' Usage: rad sync --inventory [RID] For more information, try '--help'. Which is incorrect, since `RID` is ignored. This is explained in the `--help` documentation for `--inventory`. Co-authored-by: Lorenz Leutgeb --- crates/radicle-cli/src/commands/help.rs | 5 +- crates/radicle-cli/src/commands/sync.rs | 343 +++---------------- crates/radicle-cli/src/commands/sync/args.rs | 253 ++++++++++++++ crates/radicle-cli/src/main.rs | 5 +- crates/radicle/src/node/sync.rs | 4 +- 5 files changed, 313 insertions(+), 297 deletions(-) create mode 100644 crates/radicle-cli/src/commands/sync/args.rs diff --git a/crates/radicle-cli/src/commands/help.rs b/crates/radicle-cli/src/commands/help.rs index 6b3cc0db..db6ca2e3 100644 --- a/crates/radicle-cli/src/commands/help.rs +++ b/crates/radicle-cli/src/commands/help.rs @@ -142,7 +142,10 @@ const COMMANDS: &[CommandItem] = &[ name: "stats", about: crate::commands::stats::ABOUT, }, - CommandItem::Lexopt(crate::commands::sync::HELP), + CommandItem::Clap { + name: "sync", + about: crate::commands::sync::ABOUT, + }, CommandItem::Clap { name: "watch", about: crate::commands::watch::ABOUT, diff --git a/crates/radicle-cli/src/commands/sync.rs b/crates/radicle-cli/src/commands/sync.rs index 93297659..14a6eab1 100644 --- a/crates/radicle-cli/src/commands/sync.rs +++ b/crates/radicle-cli/src/commands/sync.rs @@ -1,9 +1,8 @@ +mod args; + use std::cmp::Ordering; use std::collections::BTreeMap; -use std::collections::BTreeSet; use std::collections::HashSet; -use std::ffi::OsString; -use std::str::FromStr; use std::time; use anyhow::{anyhow, Context as _}; @@ -23,266 +22,14 @@ use radicle_term::Element; use crate::node::SyncReporting; use crate::node::SyncSettings; use crate::terminal as term; -use crate::terminal::args::{Args, Error, Help}; use crate::terminal::format::Author; use crate::terminal::{Table, TableOptions}; -pub const HELP: Help = Help { - name: "sync", - description: "Sync repositories to the network", - version: env!("RADICLE_VERSION"), - usage: r#" -Usage +pub use args::Args; +pub(crate) use args::ABOUT; +use args::{Command, SortBy, SyncDirection, SyncMode}; - rad sync [--fetch | --announce] [] [