Commit Graph

47 Commits

Author SHA1 Message Date
Adrian Duke caee776c38 log: New crate for logger implementations
Move logging-related module `radicle::logging` into its own crate.

While at it, remove the "logger" feature flag from `radicle`.

Co-authored-by: Lorenz Leutgeb <lorenz.leutgeb@radicle.dev>
2026-05-11 16:44:37 +01:00
Daniel Norman 6b460c4429 logger: Respect config file log level
- Fixes a bug where the log level set in the config file was
  ignored: `Logger` and `StderrLogger` captured the level in a
  `self.level` field at construction time and checked it in
  `Log::enabled`. After config was loaded, the global
  `log::set_max_level` was updated but `self.level` was not,
  so verbose messages were dropped by the per-instance filter
  even when the global filter allowed them.
- Make `log::set_max_level` the single source of truth: remove
  the `level` field and have `Log::enabled` defer to
  `log::max_level()` so the two filters can no longer drift.
- Update call sites to construct loggers without a level.
- Disable the structured logger's internal filter (set to "trace") so
  that it also falls back to `log::set_max_level`.
2026-05-07 16:23:28 +01:00
Fintan Halpenny 1a31a9f541 cli: Handle broken pipe (SIGPIPE) gracefully
Prevent `rad` from panicking when its stdout is a closed pipe, e.g.
when running `rad config | head`.

The broken pipes are handled at the output boundaries using three
layers of defence:

1. Inner: Route all stdout output through `term::print()` and
   `term::print_inline()`, which use explicit `writeln!`/`write!` to
   a locked stdout and silently ignore write errors. All `println!`
   calls in `radicle-cli` and `radicle-term` are converted.
2. Middle: Catch `BrokenPipe` errors that propagate up via `anyhow`
   from subcommands in `main::run()`, and exit cleanly with code 0.
3. Outer: Install a panic hook that intercepts `println!` panics
   containing "Broken pipe" (from dependencies like clap) and exits
   cleanly, chained in front of human_panic's hook.

To prevent regressions, `#![deny(clippy::print_stdout)]` is added to
`radicle-cli`, requiring all future stdout output to go through the
safe `term::` functions.

Note: `eprintln!` calls (stderr) are not handled, as broken stderr
pipes are extremely rare in practice.
2026-04-29 10:57:24 +02:00
Lorenz Leutgeb aa177b0400
treewide: radicle.{xyz → dev,network}
We have moved to radicle.dev, so adjust the domain name in various
places.

Not changed:
 - COB type names
 - systemd secret identifiers
2026-04-27 18:34:30 +02:00
Lorenz Leutgeb 8bac24d6ab
rust/edition/fmt: 2021 → 2024
Reformat code with `rustfmt`, now that the edition changed from
Rust 2021 to Rust 2024.
2026-03-30 16:57:51 +02:00
Lorenz Leutgeb 0494227e75
rust/edition: 2021 → 2024
Switch from Rust 2021 to Rust 2024.

See <https://doc.rust-lang.org/edition-guide/rust-2024/>.

Regarding the added bound `use<>`, see
<https://blog.rust-lang.org/2024/09/05/impl-trait-capture-rules/>.
2026-03-30 16:56:58 +02:00
Lorenz Leutgeb e63c30976e cli/fork: Deprecate
This command is confusing in name and function. Rather than creating
a hard fork of a repository, with a new identity, it pushes the
default branch to the local user's namespace.

Deprecate it and add some help text.
2026-01-23 15:04:16 +00:00
Fintan Halpenny 93d2ed8c61 cli/completion: Static shell completion for `rad`
Introduce the use of `clap_completion` for generating static completion.
The shells that are supported are the ones that are included in `clap_complete`:
- `bash`,
- `elvish`,
- `zsh`,
- `fish`, and
- `powershell`.

Co-authored-by: Michael Uti <utimichael9@gmail.com>
Co-authored-by: Lorenz Leutgeb <lorenz.leutgeb@radicle.xyz>
2025-11-28 20:47:25 +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 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 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 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
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
Sebastian Martinez c1d9f04963 cli/self: Use clap 2025-10-17 16:45:20 +01:00
Erik Kundt 407abc6a2c cli/follow: Use clap 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 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 d9ae29deaa cli/seed: Use clap 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
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 8c1073b9c9 cli/publish: Use clap 2025-10-09 10:52:21 +02:00
Lorenz Leutgeb 7b8da0e72f cli/fork: Use clap 2025-10-08 23:31:50 +02:00
Lorenz Leutgeb 3992d519c3 cli/clone: Use clap 2025-10-08 15:52:16 +02:00
Lorenz Leutgeb 7c89045ea0 cli/debug: Use clap 2025-10-08 15:30:18 +02:00
Lorenz Leutgeb 6d698bb794 cli/block: Use clap 2025-10-07 14:20:13 +02:00
Lorenz Leutgeb ee49e28766 cli/unfollow: Use clap 2025-10-01 14:36:39 +02:00
Lorenz Leutgeb 6fb1ebec45 cli/clean: Use clap 2025-10-01 14:12:22 +02:00
Lorenz Leutgeb 753b7aef93 cli/path: Use clap 2025-10-01 13:04:28 +02:00
Lorenz Leutgeb 01f9f3fcd4 cli/unseed: Use clap 2025-09-30 15:13:09 +02:00
Lorenz Leutgeb 80bc95269b
cli/stats: Use clap 2025-09-29 16:44:18 +02:00
Lorenz Leutgeb f1c7c98607
cli/issue: Move definition of "about" to args 2025-09-28 19:47:50 +02:00
Christopher Fredén c7bff28452 cli/issue: Use clap
A rewrite of the argument parsing portions of the `rad issue` subcommand
using `clap` instead of `lexopt`.

From a user's perspective, the look-and-feel of `rad issue` does not
change much. Although, the most prominent change is to rely on
`clap`'a default error template which looks a bit different from what we
use usually (`error: ...` vs. `✗ Error: ...`).

Leaving the above restriction aside, subcommand mis-usage is
reported more verbosely.

Also configure `clap` to use colored output for errors and help pages.
In help output, headers are colored with `Magenta` to match the overall
CLI styling.

Specify a type that captures the different actions that can be take
when using the `comment` command: `Comment`, `Reply`, and `Edit`.
Move the functions that run the corresponding actions into a `comment`
module.

To preserve the "default command" behaviour being `rad issue list`,
e.g., `rad issue --solved` behaving like `rad issue list --solved`,
introduce a new type `EmptyArgs`to also parse arguments without a
subcommand. In case no subcommand was parsed, construct `Command::List`
with from `EmptyArgs`.

Co-authored-by: Matthias Beyer <mail@beyermatthias.de>
Co-authored-by: Lorenz Leutgeb <lorenz.leutgeb@radicle.xyz>
Co-authored-by: Erik Kundt <erik@zirkular.io>
Co-authored-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2025-09-28 18:02:55 +02:00
Matthias Beyer ff021d5889 cli: Rewrite `#[path="…"]` module declarations
Rewrite module declarations that use the `#[path="…"]` annotation
to the more idomatic `pub mod …` + `pub use …` forms.

For the "self" module, that is not possible because `self` is an
identifier in Rust, and also `r#self` is not admissable as a raw
identifier, so stick to `rad_self`.

Files in submodules were patched as appropriate.
2025-09-10 21:09:29 +02:00
Matthias Beyer 6a1b13bb66 cli: Use human-panic
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2025-08-17 20:53:53 +02:00
Matthias Beyer 1e66c57643 refactor: Replace return Err(anyhow!()) with anyhow::bail!()
This is equivalent to before, but reduces cognitive load when browsing
the source.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2025-08-17 20:17:11 +02:00
Lorenz Leutgeb d7b48b9e29 radicle: Move logging setup calls to binaries 2025-08-07 08:30:59 +01:00
Lorenz Leutgeb 5bc2dc677b repo: Move workspace crates into `crates` subdirectory
This keeps the top level of the repo cleaner, e.g.
<https://github.com/radicle-dev/heartwood> scrolls less and
<https://app.radicle.xyz/nodes/rosa.radicle.xyz/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5/>
might show more files at the top level.

This way we also don't have to explicitly name all crates in
`Cargo.toml`.
2025-06-09 15:09:21 +02:00
Renamed from radicle-cli/src/main.rs (Browse further)