Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
cli: Deprecation and Obsoletion Warnings
Merged lorenz opened 7 months ago

The following deprecations/obsoletions were discussed in Zulip or are already in master. The aim here is to unify and fix.

rad self --nid

Deprecated in favor of rad node status --only nid.

This command was deprecated before, but in a way that broke its output on standard output. It now prints to standard error.

rad diff

Deprecated in favor of git diff.

rad patch review

Obsolete. See issue/9a047d07ee00d0733adedb4a279fbd158342a586.

8 files changed +66 -8 7b00bf2e 7b00bf2e
modified CHANGELOG.md
@@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Deprecations

+
- The option `rad self --nid` was deprecated in favor of `rad status --only nid`
+
- `rad diff` was deprecated in favor of using `git diff`
+
- `rad patch review --patch` and `rad patch review --delete` are made obsolete.
+
  This functionality never worked as intended, and may be removed before the
+
  next major release.
+

## New Features

- `rad clone` now supports the flag `--bare` which works analoguously to
@@ -22,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `rad init --setup-signing` now works on bare repositories.
- `git-remote-rad` now correctly reports the default branch to Git by listing
  the symbolic reference `HEAD`.
+
- `rad status` learned a new option `--only nid` for printing the Node ID.

## Fixed Bugs

modified crates/radicle-cli/examples/rad-diff.md
@@ -1,3 +1,8 @@
+
``` (stderr)
+
$ rad diff
+
! Deprecated: The command/option `rad diff` is deprecated and will be removed. Please use `git diff` instead.
+
```
+

Exploring `rad diff`.

``` ./main.c
modified crates/radicle-cli/examples/rad-self.md
@@ -26,10 +26,14 @@ did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi

```
$ rad self --nid
-
! Warning: The option `--nid` is deprecated, please use `rad node status` instead.
z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
```

+
``` (stderr)
+
$ rad self --nid
+
! Deprecated: The command/option `rad self --nid` is deprecated and will be removed. Please use `rad node status --only nid` instead.
+
```
+

```
$ rad self --ssh-key
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHahWSBEpuT1ESZbynOmBNkLBSnR32Ar4woZqSV2YNH1
modified crates/radicle-cli/src/commands/diff.rs
@@ -82,6 +82,8 @@ impl Args for Options {
}

pub fn run(options: Options, _ctx: impl term::Context) -> anyhow::Result<()> {
+
    crate::warning::deprecated("rad diff", "git diff");
+

    let repo = rad::repo()?;
    let oids = options
        .commits
modified crates/radicle-cli/src/commands/node.rs
@@ -1,7 +1,7 @@
use std::ffi::OsString;
use std::path::PathBuf;
use std::str::FromStr;
-
use std::time;
+
use std::{process, time};

use anyhow::anyhow;

@@ -64,6 +64,11 @@ Events options
    --timeout <secs>     How long to wait to receive an event before giving up
    --count, -n <count>  Exit after <count> events

+
Status options
+

+
    --only nid           If node is running, only print the Node ID and exit,
+
                         otherwise exit with a non-zero exit status.
+

General options

    --help               Print help
@@ -127,7 +132,9 @@ pub enum Operation {
    Logs {
        lines: usize,
    },
-
    Status,
+
    Status {
+
        only_nid: bool,
+
    },
    Inventory {
        nid: Option<NodeId>,
    },
@@ -171,6 +178,7 @@ impl Args for Options {
        let mut addresses = false;
        let mut path = None;
        let mut verbose = false;
+
        let mut only_nid = false;

        while let Some(arg) = parser.next()? {
            match arg {
@@ -207,6 +215,13 @@ impl Args for Options {
                    let val = parser.value()?;
                    nid = term::args::nid(&val).ok();
                }
+
                Long("only") if matches!(op, Some(OperationName::Status)) => {
+
                    if &parser.value()? == "nid" {
+
                        only_nid = true;
+
                    } else {
+
                        anyhow::bail!("unknown argument to --only");
+
                    }
+
                }
                Long("json") if matches!(op, Some(OperationName::Routing)) => json = true,
                Long("timeout")
                    if op == Some(OperationName::Events) || op == Some(OperationName::Connect) =>
@@ -263,7 +278,7 @@ impl Args for Options {
                path: path.unwrap_or(PathBuf::from("radicle-node")),
            },
            OperationName::Inventory => Operation::Inventory { nid },
-
            OperationName::Status => Operation::Status,
+
            OperationName::Status => Operation::Status { only_nid },
            OperationName::Debug => Operation::Debug,
            OperationName::Sessions => Operation::Sessions,
            OperationName::Stop => Operation::Stop,
@@ -333,9 +348,16 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
                println!("{}", term::format::tertiary(rid));
            }
        }
-
        Operation::Status => {
+
        Operation::Status { only_nid: false } => {
            control::status(&node, &profile)?;
        }
+
        Operation::Status { only_nid: true } => {
+
            if node.is_running() {
+
                term::print(term::format::node_id_human(&node.nid()?));
+
            } else {
+
                process::exit(2);
+
            }
+
        }
        Operation::Stop => {
            control::stop(node, &profile);
        }
modified crates/radicle-cli/src/commands/patch/review.rs
@@ -83,6 +83,7 @@ pub fn run(
            unified,
            hunk,
        } if by_hunk => {
+
            crate::warning::obsolete("rad patch review --patch");
            let mut opts = git::raw::DiffOptions::new();
            opts.patience(true)
                .minimal(true)
@@ -124,6 +125,7 @@ pub fn run(
            }
        }
        Operation::Delete => {
+
            crate::warning::obsolete("rad patch review --delete");
            let name = git::refs::storage::draft::review(profile.id(), &patch_id);

            match repository.backend.find_reference(&name) {
modified crates/radicle-cli/src/commands/self.rs
@@ -100,9 +100,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
            term::print(profile.config.alias());
        }
        Show::NodeId => {
-
            term::warning(
-
                "The option `--nid` is deprecated, please use `rad node status` instead.",
-
            );
+
            crate::warning::deprecated("rad self --nid", "rad node status --only nid");
            term::print(
                Node::new(profile.socket())
                    .nid()
modified crates/radicle-cli/src/warning.rs
@@ -44,3 +44,21 @@ pub(crate) fn nodes_renamed(config: &Config) -> Vec<String> {
    ));
    warnings
}
+

+
/// Prints a deprecation warning to standard error.
+
pub(crate) fn deprecated(old: impl std::fmt::Display, new: impl std::fmt::Display) {
+
    eprintln!(
+
        "{} {} The command/option `{old}` is deprecated and will be removed. Please use `{new}` instead.",
+
        radicle_term::PREFIX_WARNING,
+
        radicle_term::Paint::yellow("Deprecated:").bold(),
+
    );
+
}
+

+
/// Prints an obsoletion warning to standard error.
+
pub(crate) fn obsolete(command: impl std::fmt::Display) {
+
    eprintln!(
+
        "{} {} The command `{command}` is obsolete and will be removed. Please stop using it.",
+
        radicle_term::PREFIX_WARNING,
+
        radicle_term::Paint::yellow("Obsolete:").bold(),
+
    );
+
}