node: Remove `SyncWriter` in favor of `PaintTarget`
This commit is contained in:
parent
11a109ef41
commit
153a8f9fbe
|
|
@ -1,6 +1,5 @@
|
||||||
use core::time;
|
use core::time;
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
use std::io;
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
use radicle::node::sync;
|
use radicle::node::sync;
|
||||||
|
|
@ -93,51 +92,12 @@ impl SyncError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Writes sync output.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum SyncWriter {
|
|
||||||
/// Write to standard out.
|
|
||||||
Stdout(io::Stdout),
|
|
||||||
/// Write to standard error.
|
|
||||||
Stderr(io::Stderr),
|
|
||||||
/// Discard output, like [`std::io::sink`].
|
|
||||||
Sink,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Clone for SyncWriter {
|
|
||||||
fn clone(&self) -> Self {
|
|
||||||
match self {
|
|
||||||
Self::Stdout(_) => Self::Stdout(io::stdout()),
|
|
||||||
Self::Stderr(_) => Self::Stderr(io::stderr()),
|
|
||||||
Self::Sink => Self::Sink,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl io::Write for SyncWriter {
|
|
||||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
|
||||||
match self {
|
|
||||||
Self::Stdout(stdout) => stdout.write(buf),
|
|
||||||
Self::Stderr(stderr) => stderr.write(buf),
|
|
||||||
Self::Sink => Ok(buf.len()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn flush(&mut self) -> io::Result<()> {
|
|
||||||
match self {
|
|
||||||
Self::Stdout(stdout) => stdout.flush(),
|
|
||||||
Self::Stderr(stderr) => stderr.flush(),
|
|
||||||
Self::Sink => Ok(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Configures how sync progress is reported.
|
/// Configures how sync progress is reported.
|
||||||
pub struct SyncReporting {
|
pub struct SyncReporting {
|
||||||
/// Progress messages or animations.
|
/// Progress messages or animations.
|
||||||
pub progress: SyncWriter,
|
pub progress: term::PaintTarget,
|
||||||
/// Completion messages.
|
/// Completion messages.
|
||||||
pub completion: SyncWriter,
|
pub completion: term::PaintTarget,
|
||||||
/// Debug output.
|
/// Debug output.
|
||||||
pub debug: bool,
|
pub debug: bool,
|
||||||
}
|
}
|
||||||
|
|
@ -145,8 +105,8 @@ pub struct SyncReporting {
|
||||||
impl Default for SyncReporting {
|
impl Default for SyncReporting {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
progress: SyncWriter::Stderr(io::stderr()),
|
progress: term::PaintTarget::Stderr,
|
||||||
completion: SyncWriter::Stdout(io::stdout()),
|
completion: term::PaintTarget::Stdout,
|
||||||
debug: false,
|
debug: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -173,7 +133,7 @@ pub fn announce<R: ReadRepository>(
|
||||||
fn announce_<R>(
|
fn announce_<R>(
|
||||||
repo: &R,
|
repo: &R,
|
||||||
settings: SyncSettings,
|
settings: SyncSettings,
|
||||||
mut reporting: SyncReporting,
|
reporting: SyncReporting,
|
||||||
node: &mut Node,
|
node: &mut Node,
|
||||||
profile: &Profile,
|
profile: &Profile,
|
||||||
) -> Result<Option<sync::AnnouncerResult>, SyncError>
|
) -> Result<Option<sync::AnnouncerResult>, SyncError>
|
||||||
|
|
@ -214,7 +174,7 @@ where
|
||||||
Err(err) => match err {
|
Err(err) => match err {
|
||||||
sync::AnnouncerError::AlreadySynced(result) => {
|
sync::AnnouncerError::AlreadySynced(result) => {
|
||||||
term::success!(
|
term::success!(
|
||||||
&mut reporting.completion;
|
&mut reporting.completion.writer();
|
||||||
"Nothing to announce, already in sync with {} seed(s) (see `rad sync status`)",
|
"Nothing to announce, already in sync with {} seed(s) (see `rad sync status`)",
|
||||||
term::format::positive(result.synced()),
|
term::format::positive(result.synced()),
|
||||||
);
|
);
|
||||||
|
|
@ -222,7 +182,7 @@ where
|
||||||
}
|
}
|
||||||
sync::AnnouncerError::NoSeeds => {
|
sync::AnnouncerError::NoSeeds => {
|
||||||
term::info!(
|
term::info!(
|
||||||
&mut reporting.completion;
|
&mut reporting.completion.writer();
|
||||||
"{}",
|
"{}",
|
||||||
term::format::yellow(format!("No seeds found for {rid}."))
|
term::format::yellow(format!("No seeds found for {rid}."))
|
||||||
);
|
);
|
||||||
|
|
@ -235,8 +195,8 @@ where
|
||||||
let min_replicas = target.replicas().lower_bound();
|
let min_replicas = target.replicas().lower_bound();
|
||||||
let mut spinner = term::spinner_to(
|
let mut spinner = term::spinner_to(
|
||||||
format!("Found {} seed(s)..", announcer.progress().unsynced()),
|
format!("Found {} seed(s)..", announcer.progress().unsynced()),
|
||||||
reporting.completion.clone(),
|
|
||||||
reporting.progress.clone(),
|
reporting.progress.clone(),
|
||||||
|
reporting.completion.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
match node.announce(rid, settings.timeout, announcer, |node, progress| {
|
match node.announce(rid, settings.timeout, announcer, |node, progress| {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue