Merge pull request #127 from djmitche/issue76

Default to a local server, so `task sync` works out of the box
This commit is contained in:
Dustin J. Mitchell 2020-12-26 10:45:15 -05:00 committed by GitHub
commit c472e04a09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 15 deletions

View file

@ -106,15 +106,25 @@ fn get_replica(settings: &Config) -> Fallible<Replica> {
/// Get the server for this invocation
fn get_server(settings: &Config) -> Fallible<Box<dyn server::Server>> {
let client_id = settings.get_str("server_client_id")?;
let client_id = Uuid::parse_str(&client_id)?;
let origin = settings.get_str("server_origin")?;
log::debug!("Using sync-server with origin {}", origin);
log::debug!("Sync client ID: {}", client_id);
Ok(server::from_config(ServerConfig::Remote {
origin,
client_id,
})?)
// if server_client_id and server_origin are both set, use
// the remote server
if let (Ok(client_id), Ok(origin)) = (
settings.get_str("server_client_id"),
settings.get_str("server_origin"),
) {
let client_id = Uuid::parse_str(&client_id)?;
log::debug!("Using sync-server with origin {}", origin);
log::debug!("Sync client ID: {}", client_id);
Ok(server::from_config(ServerConfig::Remote {
origin,
client_id,
})?)
} else {
let server_dir = settings.get_str("server_dir")?.into();
log::debug!("Using local sync-server at `{:?}`", server_dir);
Ok(server::from_config(ServerConfig::Local { server_dir })?)
}
}
/// Get a WriteColor implementation based on whether the output is a tty.

View file

@ -7,12 +7,21 @@ pub(crate) fn read_settings() -> Fallible<Config> {
let mut settings = Config::default();
// set up defaults
if let Some(mut dir) = dirs::data_local_dir() {
dir.push("taskchampion");
if let Some(dir) = dirs::data_local_dir() {
let mut tc_dir = dir.clone();
tc_dir.push("taskchampion");
settings.set_default(
"data_dir",
// the config crate does not support non-string paths
dir.to_str().expect("data_local_dir is not utf-8"),
tc_dir.to_str().expect("data_local_dir is not utf-8"),
)?;
let mut server_dir = dir;
server_dir.push("taskchampion-sync-server");
settings.set_default(
"server_dir",
// the config crate does not support non-string paths
server_dir.to_str().expect("data_local_dir is not utf-8"),
)?;
}