From 472a1e65455131c942171b8706efc1add981ccfa Mon Sep 17 00:00:00 2001 From: cloudhead Date: Fri, 8 Dec 2023 15:40:01 +0100 Subject: [PATCH] cli: Add `watch` command Allows watching and waiting for refs to change. This is especially useful for tests. For now, we don't show it in the output of `rad`. --- radicle-cli/examples/rad-watch.md | 20 ++++ radicle-cli/src/commands.rs | 2 + radicle-cli/src/commands/watch.rs | 146 ++++++++++++++++++++++++++++++ radicle-cli/src/main.rs | 5 + radicle-cli/src/terminal/args.rs | 8 ++ radicle-cli/tests/commands.rs | 31 +++++++ 6 files changed, 212 insertions(+) create mode 100644 radicle-cli/examples/rad-watch.md create mode 100644 radicle-cli/src/commands/watch.rs diff --git a/radicle-cli/examples/rad-watch.md b/radicle-cli/examples/rad-watch.md new file mode 100644 index 00000000..39e3fc84 --- /dev/null +++ b/radicle-cli/examples/rad-watch.md @@ -0,0 +1,20 @@ +The `rad watch` command allows you to watch a reference and return when it +reaches a target commit. + +``` ~bob +$ git rev-parse refs/remotes/alice@z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi/master +f2de534b5e81d7c6e2dcaf58c3dd91573c0a0354 +``` + +``` ~alice +$ git rev-parse master +f2de534b5e81d7c6e2dcaf58c3dd91573c0a0354 +$ git commit --allow-empty -m "Minor update" -q +$ git rev-parse master +e09c4dc1b54443ceea715ea648afecdcfd1dd7d0 +$ git push rad master +``` + +``` ~bob +$ rad watch --repo rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji --node z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi --ref 'refs/heads/master' --target e09c4dc1b54443ceea715ea648afecdcfd1dd7d0 --interval 500 +``` diff --git a/radicle-cli/src/commands.rs b/radicle-cli/src/commands.rs index 2ab1455a..22a78700 100644 --- a/radicle-cli/src/commands.rs +++ b/radicle-cli/src/commands.rs @@ -46,3 +46,5 @@ pub mod rad_self; pub mod rad_sync; #[path = "commands/unfollow.rs"] pub mod rad_unfollow; +#[path = "commands/watch.rs"] +pub mod rad_watch; diff --git a/radicle-cli/src/commands/watch.rs b/radicle-cli/src/commands/watch.rs new file mode 100644 index 00000000..15c66095 --- /dev/null +++ b/radicle-cli/src/commands/watch.rs @@ -0,0 +1,146 @@ +use std::ffi::OsString; +use std::{thread, time}; + +use anyhow::{anyhow, Context as _}; + +use radicle::git; +use radicle::prelude::{Id, NodeId}; +use radicle::storage::{ReadRepository, ReadStorage}; + +use crate::terminal as term; +use crate::terminal::args::{Args, Error, Help}; + +pub const HELP: Help = Help { + name: "wait", + description: "Wait for some state to be updated", + version: env!("CARGO_PKG_VERSION"), + usage: r#" +Usage + + rad watch -r [-t ] [--repo ] [