Commit Graph

161 Commits

Author SHA1 Message Date
Fintan Halpenny bc1d9ed495 cli: remove lexopt dependency 2025-11-01 11:20:43 +01:00
Fintan Halpenny 83f26abaa0 cli/main: refactor external command
Refactors the external command logic into a struct.

This allows for methods to maitain the logic of an external command.
It also allows for a cleaner output for the executable name – avoiding the debug
output of OsString using `""`.
2025-11-01 11:20:43 +01:00
Fintan Halpenny f60922d125 cli/terminal: make args module private 2025-11-01 11:20:43 +01:00
Fintan Halpenny 961301f643 cli/terminal: clean up args::Error type
The other variants of `terminal::args::Error` were no longer used.
The only variant required is `Error::WithHint`.

The enum is also made private, since it is only used in this crate.
2025-11-01 11:20:43 +01:00
Fintan Halpenny a75db6a695 cli/terminal: remove argument helpers
These helper functions were for parsing arguments passed via lexopt.
Since `clap` is now the parser for these types, these functions are no longer
needed.
2025-11-01 11:20:43 +01:00
Fintan Halpenny fec8a27a36 cli/terminal: remove Help struct
The `Help` struct is no longer needed thanks to `clap`, so it is removed.
2025-11-01 11:20:43 +01:00
Fintan Halpenny e359435040 cli/main: move run_command_fn to main
This call was moved to the `main.rs` file, since that is where it is used.

It is renamed to `run` and its call site is cleaned up.
2025-11-01 11:20:43 +01:00
Fintan Halpenny 7533db62f9 cli/terminal: remove unused parameter 2025-11-01 11:20:43 +01:00
Fintan Halpenny 1f80eb61ed cli/terminal: remove unused trait 2025-11-01 11:20:43 +01:00
Fintan Halpenny d41ac59828 cli/help: remove the help module
The `help` module is no longer needed, since `clap` handles that.

This meant that the re-exports of each command's `ABOUT` could be removed and
the `const`s can now be private.
2025-11-01 11:20:43 +01:00
Fintan Halpenny 23332fa318 cli/main: migrate main to use clap
Now that all commands can be parsed by clap, remove any custom parsing and
directly use `CliArgs::parse`.

The `Diff` command was removed, since only one `external_command` can be
declared for a subcommand. The handling of `rad diff` is now done via the
`External` variant. If the subcommand name is `diff` then this is executed,
otherwise delegate to the possible `rad-{exe}` command.

Also of note, the `rad inspect` command has an alias `rad .`. This changes the
behaviour of `rad . --help`. Before, it would print the help of the `rad`
command. Now, it prints the help of `rad inspect`.

Co-authored-by: Lorenz Leutgeb <lorenz.leutgeb@radicle.xyz>
2025-11-01 11:20:43 +01:00
Fintan Halpenny 5053a1aa77 cli/unseed: rename options to args
Have consistent naming for args
2025-11-01 10:52:13 +01:00
Fintan Halpenny 6ca1292350 cli/unfollow: rename options to args
Have consistent naming for args
2025-11-01 10:52:13 +01:00
Fintan Halpenny 3c89525003 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 <lorenz.leutgeb@radicle.xyz>
2025-11-01 10:52:13 +01:00
Matthias Beyer d1e19a87b0 cli/patch: migrate patch CLI parsing to clap
Co-authored-by: Fintan Halpenny <fintan.halpenny@gmail.com>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2025-10-29 09:11:05 +00:00
Fintan Halpenny 3ea61f0f98 cli/patch: move comment actions
Moving the sub-comment actions to be beside the top level comment action. This
is mostly to provide a better diff for the next commit – that refactors due to
`clap` changes.
2025-10-29 09:11:05 +00:00
Sebastian Martinez 9bcdd353c9 cli/inbox: Use clap 2025-10-28 12:11:37 +00:00
Richard Levitte 990e22acff cli/inspect: use Clap
This includes a horrible - but hopefully short-lived - hack to make
`rad .` work.

Co-authored-by: Lorenz Leutgeb <lorenz.leutgeb@radicle.xyz>
2025-10-22 21:14:12 +02:00
Erik Kundt e8f9d21be3 cli/node: Use clap
Co-authored-by: Fintan Halpenny <fintan.halpenny@gmail.com>
Co-authored-by: Lorenz Leutgeb <lorenz.leutgeb@radicle.xyz>
2025-10-22 11:27:23 +01:00
Fintan Halpenny 6cfed884bf cli/remote: migrate to clap 2025-10-21 10:12:33 +01:00
Sebastian Martinez 8604d3bcc7 cli/config: Use clap 2025-10-20 12:04:31 +01:00
Erik Kundt 8d90699c30 cli/cob: Use clap 2025-10-20 11:21:58 +01:00
Fintan Halpenny 38ca038a0d cli: fix test regression in 27a85987c3
A test failure was caused in commit
27a85987c3, which expected `STRING`
instead of `ALIAS`.

This change fixes that discrepancy.
2025-10-17 16:57:29 +01:00
Sebastian Martinez c1d9f04963 cli/self: Use clap 2025-10-17 16:45:20 +01:00
Erik Kundt 27a85987c3 cli: Fix argument value names in `auth` and `init`
We decided to use the value names to indicate which type the value
is parsed into (instead of just saying that the value is a `STRING`).

This makes the value names consistent with other commands again.
2025-10-17 13:43:42 +01:00
Lorenz Leutgeb b0beef4391
workspace/rust/clippy: Fix all warnings
Fix clippy warnings following the upgrade of the Rust toolchain to
version 1.90. Almost all are "mismatched_lifetime_syntaxes".
2025-10-17 12:56:43 +02:00
Erik Kundt 407abc6a2c cli/follow: Use clap 2025-10-17 10:50:21 +01:00
Erik Kundt deaf77e5b4 cli/unfollow: Use common DID / NID argument parser 2025-10-17 10:50:21 +01:00
Erik Kundt e488ddb446 cli: Add common value parser for NID / DID 2025-10-17 10:50:21 +01:00
Richard Levitte 06e22434e1 cli/checkout: use Clap 2025-10-17 08:51:10 +02:00
Erik Kundt 28824a3127 cli/init: Fix argument value names 2025-10-17 08:20:30 +02:00
Erik Kundt 634866889f cli/id: Use clap
This implementation works around the fact that `clap` does currently
not support value parsers for a series of values, so representing
`--payload` as a `Vec<Payload>` does not work.

Instead, we parse eveything into a `Vec<String>` and do the validation
on the application side.

Using value parsers for a series of values will probably be supported in
`clap` v5, though.
2025-10-16 18:14:11 +02:00
Erik Kundt ec1d754308 cli/unblock: Use clap 2025-10-16 15:31:47 +01:00
Erik Kundt faf19af9de cli: Share common argument types used in `(un)block`
Since `rad block` and `rad unblock` share the same argument type,
`BlockTarget` is moved to the exising `terminal/args.rs` module.
2025-10-16 15:31:47 +01:00
Erik Kundt d9ae29deaa cli/seed: Use clap 2025-10-16 13:02:06 +02:00
Erik Kundt 80198d68b6 cli: Share value parser for `Scope` 2025-10-16 13:02:06 +02:00
Lorenz Leutgeb 72cf3d1919 cli/diff: Use clap
The implementation of the *deprecated* command is removed, it now
directly invokes `git diff`.
2025-10-15 10:30:34 +02:00
Richard Levitte 384c506489 cli/auth: use Clap 2025-10-14 12:55:33 +01:00
Erik Kundt dfd35480be cli/watch: Use clap 2025-10-14 12:49:16 +02:00
Lorenz Leutgeb b7cfcfff75
workspace: A Little Less `git2`
Make `git2` an *optional* dependency of `radicle-cob`, and refactor
`radicle` to depend on crates that in turn do not depend on `git2`
*non-optionally*

The main offending dependency of `radicle-cob` is `radicle-git-ext`
from the `radicle-git` workspace in repository
(rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt) which *non-optionally* depends on
`git2`.

So, to achieve removal of this dependency:

 1. The crate is refactored to depend on the new crates
    `radicle-git-ref-format` `radicle-git-metadata`, and
    `radicle-oid` introduced in the previous commits, instead of
    `radicle-git-ext`.
 2. Some code from the `radicle-git-ext` crate in the `radicle-git`
    workspace in repository (rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt) is
    copied. See `crates/radicle-cob/src/backend/git/commit.rs`.

This cascades to `radicle` and its dependents.

  Firstly, the there is an
`impl Deref<Target=git2::Oid> for radicle_git_ext::Oid`. This made
it very convenient to just deref to obtain the wrapped `git2::Oid`,
so there are many expressions of the shape `*oid` in `radicle` and
its dependents. However `radicle-oid` does not provide
`impl Deref<Target=git2::Oid> for radicle_oid::Oid`, as notably,
`Target` is an associated type, and not a type parameter, so an
implementation of `Deref` would tie the new `Oid` too tightly to a
particular implementation.
Instead, work with `impl From<radicle_oid::Oid> for git2::Oid`
(which can be enabled using the feature flag `radicle-oid/git2`).
This explains the changes from `*oid` to `oid.into()` at every
transition to "`git2` land".

  Secondly, `radicle` and its dependents are refactored to also depend
on `radicle-git-ref-format` and (much less prominently)
`radicle-git-metadata` instead of `radicle-git-ext`
This is to avoid pulling in `git2` via these dependencies.

  Thirdly, as the re-exports in `crates/radicle/src/git.rs` change,
they are at the same time also cleaned up. Notably, the types from
`radicle-git-ref-format` are re-exported under `fmt` only, not "twice".

While overall this obviously is very much a breaking change, these
changes should mostly amount to changing from `Deref` to `Into`, i.e.,
`*oid` → `oid.into()` and rewriting imports for `radicle::git::fmt`.
This is indicated by the mostly mechanical nature of the changes to
`crates/radicle-{cli,node,remote-helper}`.
2025-10-13 16:14:23 +02:00
Lorenz Leutgeb f232acda74 cli/diff: Print cross-platform line endings 2025-10-13 10:32:17 +01:00
Lorenz Leutgeb 013da67aa1 cli/test: Skip `rad_diff` on macOS
macOS's `sed` requires an argument for `-i`, which we don't provide
in the example. Providing it makes the test fail on Linux.
Since this command is deprecated anyway, we just skip macOS.
2025-10-13 10:27:02 +01:00
Lorenz Leutgeb f7af918190 cli/test: Fix `rad_patch_delete` for macOS
It looks like macOS does not like this command:

    ln: -f: No such file or directory

Since `LICENSE` and `MIT` are both just empty here, we don't need to
link anything.
2025-10-13 10:18:10 +01:00
Lorenz Leutgeb 7d6d2e51d8 cli/test: Clean up testing environment
This is a small cleanup to path generation during testing.
 1. Separate `rad_home` and `unix_home` to avoid confusion.
 2. Remove now unnecessary `trait HasHome`.
 3. Move setting `$USER` to the environment.
 4. Make paths shorter overall, to fix macOS tests.
2025-10-13 08:56:23 +01:00
Richard Levitte 191c287955 cli/ls: use Clap
This adds `conflicts_with` for `private` and `public` to simplify the logic that checks for the document visibility
(thank you Fintan)

Co-authored-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2025-10-10 17:08:08 +02:00
Richard Levitte 8ba3087cb9 cli/init: use Clap 2025-10-10 16:03:14 +02:00
Lorenz Leutgeb ea562215ea
radicle/git/raw: Introduce `trait ErrorExt`
This extension trait is more ergonomic than what `radicle-git-ext`
provides.
2025-10-10 11:29:24 +02:00
Lorenz Leutgeb 8c1073b9c9 cli/publish: Use clap 2025-10-09 10:52:21 +02:00
Lorenz Leutgeb 7effa7c64c
node: Report sync status for given namespaces
The "seeds" command does only take a repository ID, and
carries the implicit assumption that the namespace with the same public
key as the Node ID of the receiving `radicle-node` process should be
used as reference for determining whether other nodes are in sync,
but no other namespace.

In the spirit of separating user and node identity, relax this, so that
the command also carries the public keys relative to which the sync
status should be computed. This allows to inspect sync status for
arbitrary namespaces via command.

For now, this feature is not exposed to the CLI, but `rad sync status`
always passes the public key of the active profile.
2025-10-09 07:55:11 +02:00
Lorenz Leutgeb 9689de9af0
node: Allow announcing refs for given public keys
The "announce references" command does only take a repository ID, and
carries the implicit assumption that the namespace with the same public
key as the Node ID of the receiving `radicle-node` process should be
announced, but no other namespace.

In the spirit of separating user and node identity, relax this, so that
the command also carries the public keys for which the announcement
should be made. This allows to announce arbitrary namespaces out of
storage via command.

For now, this feature is not exposed to the CLI, but rather:
 - `rad sync` always announce for the public key of the active profile.
 - `git-remote-rad` ditto, as it calls the same codepath.
2025-10-09 07:55:10 +02:00