Merge pull request #305 from djmitche/issue23-client-apply

Client initialization from snapshots
This commit is contained in:
Dustin J. Mitchell 2021-10-20 22:22:51 -04:00 committed by GitHub
commit 2f7c11bcc3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 122 additions and 24 deletions

View file

@ -1,5 +1,5 @@
use crate::settings::Settings;
use taskchampion::{server::Server, Replica};
use taskchampion::{server::Server, Error as TCError, Replica};
use termcolor::WriteColor;
pub(crate) fn execute<W: WriteColor>(
@ -8,9 +8,32 @@ pub(crate) fn execute<W: WriteColor>(
settings: &Settings,
server: &mut Box<dyn Server>,
) -> Result<(), crate::Error> {
replica.sync(server, settings.avoid_snapshots)?;
writeln!(w, "sync complete.")?;
Ok(())
match replica.sync(server, settings.avoid_snapshots) {
Ok(()) => {
writeln!(w, "sync complete.")?;
Ok(())
}
Err(e) => match e.downcast() {
Ok(TCError::OutOfSync) => {
writeln!(w, "This replica cannot be synchronized with the server.")?;
writeln!(
w,
"It may be too old, or some other failure may have occurred."
)?;
writeln!(
w,
"To start fresh, remove the local task database and run `ta sync` again."
)?;
writeln!(
w,
"Note that doing so will lose any un-synchronized local changes."
)?;
Ok(())
}
Ok(e) => Err(e.into()),
Err(e) => Err(e.into()),
},
}
}
#[cfg(test)]