cli: Support colors in git helper output
This commit is contained in:
parent
2020e8531e
commit
48843434c7
|
|
@ -9,10 +9,9 @@ Switched to a new branch 'feature/1'
|
|||
$ git commit -a -m "Add things" -q --allow-empty
|
||||
$ git push -o patch.message="Add things #1" -o patch.message="See commits for details." rad HEAD:refs/patches
|
||||
✓ Patch 82faae29b2a2f11bf45bbba4c4787d6b32a12447 opened
|
||||
hint: to update, run `git push`,
|
||||
or `git push rad -f HEAD:patches/82faae29b2a2f11bf45bbba4c4787d6b32a12447`
|
||||
hint: to update, run `git push` or `git push rad -f HEAD:patches/82faae29b2a2f11bf45bbba4c4787d6b32a12447`
|
||||
hint: offline push, your node is not running
|
||||
to sync with the network, run `rad node start`
|
||||
hint: to sync with the network, run `rad node start`
|
||||
To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
|
||||
* [new reference] HEAD -> refs/patches
|
||||
```
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ mod push;
|
|||
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use std::{env, io};
|
||||
use std::{env, fmt, io};
|
||||
|
||||
use radicle_cli::git::Rev;
|
||||
use thiserror::Error;
|
||||
|
|
@ -86,6 +86,10 @@ pub struct Options {
|
|||
|
||||
/// Run the radicle remote helper using the given profile.
|
||||
pub fn run(profile: radicle::Profile) -> Result<(), Error> {
|
||||
// Since we're going to be writing user output to `stderr`, make sure the paint
|
||||
// module is aware of that.
|
||||
cli::Paint::set_terminal(io::stderr());
|
||||
|
||||
let url: Url = {
|
||||
let args = env::args().skip(1).take(2).collect::<Vec<_>>();
|
||||
|
||||
|
|
@ -227,3 +231,8 @@ pub(crate) fn read_line<'a>(stdin: &io::Stdin, line: &'a mut String) -> io::Resu
|
|||
|
||||
Ok(tokens)
|
||||
}
|
||||
|
||||
/// Write a hint to the user.
|
||||
pub(crate) fn hint(s: impl fmt::Display) {
|
||||
eprintln!("{}", cli::format::hint(format!("hint: {s}")));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ use radicle::Profile;
|
|||
use radicle::{git, rad};
|
||||
use radicle_cli::terminal as cli;
|
||||
|
||||
use crate::{read_line, Options};
|
||||
use crate::{hint, read_line, Options};
|
||||
|
||||
/// Default timeout for syncing to the network after a push.
|
||||
const DEFAULT_SYNC_TIMEOUT: time::Duration = time::Duration::from_secs(9);
|
||||
|
|
@ -248,14 +248,14 @@ pub fn run(
|
|||
&& !rollback
|
||||
{
|
||||
if hints {
|
||||
eprintln!(
|
||||
"hint: you are attempting to push a commit that would \
|
||||
cause your upstream to diverge from the canonical head"
|
||||
hint(
|
||||
"you are attempting to push a commit that would cause \
|
||||
your upstream to diverge from the canonical head",
|
||||
);
|
||||
hint(
|
||||
"to integrate the remote changes, run `git pull --rebase` \
|
||||
and try again",
|
||||
);
|
||||
eprintln!(
|
||||
"hint: to integrate the remote changes, run `git pull --rebase` \
|
||||
and try again"
|
||||
);
|
||||
}
|
||||
return Err(Error::HeadsDiverge(head.into(), *canonical_oid));
|
||||
}
|
||||
|
|
@ -291,8 +291,8 @@ pub fn run(
|
|||
// Nb. allow this to fail. The push to local storage was still successful.
|
||||
sync(stored.id, node).ok();
|
||||
} else if hints {
|
||||
eprintln!("hint: offline push, your node is not running");
|
||||
eprintln!(" to sync with the network, run `rad node start`");
|
||||
hint("offline push, your node is not running");
|
||||
hint("to sync with the network, run `rad node start`");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -397,8 +397,9 @@ fn patch_open<G: Signer>(
|
|||
// Remove the remote portion of the name, i.e.
|
||||
// rad/patches/deadbeef -> patches/deadbeef
|
||||
let name = name.split('/').skip(1).collect::<Vec<_>>().join("/");
|
||||
eprintln!("hint: to update, run `git push`,");
|
||||
eprintln!(" or `git push rad -f HEAD:{name}`");
|
||||
hint(format!(
|
||||
"to update, run `git push` or `git push rad -f HEAD:{name}`"
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,10 @@ pub fn yellow<D: std::fmt::Display>(msg: D) -> Paint<D> {
|
|||
Paint::yellow(msg)
|
||||
}
|
||||
|
||||
pub fn hint<D: std::fmt::Display>(msg: D) -> Paint<D> {
|
||||
Paint::yellow(msg)
|
||||
}
|
||||
|
||||
pub fn faint<D: std::fmt::Display>(msg: D) -> Paint<D> {
|
||||
Paint::fixed(236, msg)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ pub fn error(error: impl fmt::Display) {
|
|||
}
|
||||
|
||||
pub fn hint(hint: impl fmt::Display) {
|
||||
println!("{ERROR_HINT_PREFIX} {}", Paint::yellow(hint));
|
||||
println!("{ERROR_HINT_PREFIX} {}", format::hint(hint));
|
||||
}
|
||||
|
||||
pub fn ask<D: fmt::Display>(prompt: D, default: bool) -> bool {
|
||||
|
|
|
|||
Loading…
Reference in New Issue