Files
taskchampion-sync-server/server/src/bin/taskchampion-sync-server.rs
Dustin J. Mitchell c445ac475a Add a binary that uses a Postgres backend
Building of this binary is controlled with features, allowing downstream
users to build just the SQLite version and not be concerned with the
tokio-postgres dependency tree (which includes links to OpenSSL and
other details). The Postgres version is disabled by default.

This does not change the binary name for the SQLite build, just to avoid
confusion for people upgrading to the new version.
2025-07-25 22:01:14 -04:00

61 lines
1.8 KiB
Rust

#![deny(clippy::all)]
use clap::{arg, builder::ValueParser, ArgMatches, Command};
use std::ffi::OsString;
use taskchampion_sync_server::{args, web};
use taskchampion_sync_server_storage_sqlite::SqliteStorage;
fn command() -> Command {
args::command().arg(
arg!(-d --"data-dir" <DIR> "Directory in which to store data")
.value_parser(ValueParser::os_string())
.env("DATA_DIR")
.default_value("/var/lib/taskchampion-sync-server"),
)
}
fn data_dir_from_matches(matches: &ArgMatches) -> OsString {
matches.get_one::<OsString>("data-dir").unwrap().clone()
}
#[actix_web::main]
async fn main() -> anyhow::Result<()> {
env_logger::init();
let matches = command().get_matches();
let server_config = args::server_config_from_matches(&matches);
let web_config = args::web_config_from_matches(&matches);
let data_dir = data_dir_from_matches(&matches);
let storage = SqliteStorage::new(data_dir)?;
let server = web::WebServer::new(server_config, web_config, storage);
server.run().await
}
#[cfg(test)]
mod test {
use super::*;
use temp_env::{with_var, with_var_unset};
#[test]
fn command_data_dir() {
with_var_unset("DATA_DIR", || {
let matches = command().get_matches_from([
"tss",
"--data-dir",
"/foo/bar",
"--listen",
"localhost:8080",
]);
assert_eq!(data_dir_from_matches(&matches), "/foo/bar");
});
}
#[test]
fn command_data_dir_env() {
with_var("DATA_DIR", Some("/foo/bar"), || {
let matches = command().get_matches_from(["tss", "--listen", "localhost:8080"]);
assert_eq!(data_dir_from_matches(&matches), "/foo/bar");
});
}
}