update to clap-4.x
This commit is contained in:
@@ -15,7 +15,7 @@ thiserror = "1.0"
|
|||||||
futures = "^0.3.24"
|
futures = "^0.3.24"
|
||||||
serde = "^1.0.145"
|
serde = "^1.0.145"
|
||||||
serde_json = "^1.0"
|
serde_json = "^1.0"
|
||||||
clap = "^4.0.4"
|
clap = { version = "^4.0.4", features = ["string"] }
|
||||||
log = "^0.4.17"
|
log = "^0.4.17"
|
||||||
env_logger = "^0.9.1"
|
env_logger = "^0.9.1"
|
||||||
rusqlite = { version = "0.28", features = ["bundled"] }
|
rusqlite = { version = "0.28", features = ["bundled"] }
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#![deny(clippy::all)]
|
#![deny(clippy::all)]
|
||||||
|
|
||||||
use actix_web::{middleware::Logger, App, HttpServer};
|
use actix_web::{middleware::Logger, App, HttpServer};
|
||||||
use clap::{arg, Command};
|
use clap::{arg, builder::ValueParser, value_parser, Command};
|
||||||
|
use std::ffi::OsString;
|
||||||
use taskchampion_sync_server::storage::SqliteStorage;
|
use taskchampion_sync_server::storage::SqliteStorage;
|
||||||
use taskchampion_sync_server::{Server, ServerConfig};
|
use taskchampion_sync_server::{Server, ServerConfig};
|
||||||
|
|
||||||
@@ -17,30 +18,30 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
.arg(
|
.arg(
|
||||||
arg!(-p --port <PORT> "Port on which to serve")
|
arg!(-p --port <PORT> "Port on which to serve")
|
||||||
.help("Port on which to serve")
|
.help("Port on which to serve")
|
||||||
.default_value("8080")
|
.value_parser(value_parser!(usize))
|
||||||
.required(true),
|
.default_value("8080"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
arg!(-d --data-dir <DIR> "Directory in which to store data")
|
arg!(-d --"data-dir" <DIR> "Directory in which to store data")
|
||||||
.default_value("/var/lib/taskchampion-sync-server")
|
.value_parser(ValueParser::os_string())
|
||||||
.allow_invalid_utf8(true)
|
.default_value("/var/lib/taskchampion-sync-server"),
|
||||||
.required(true),
|
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
arg!(--snapshot-versions [NUM] "Target number of versions between snapshots")
|
arg!(--"snapshot-versions" <NUM> "Target number of versions between snapshots")
|
||||||
.default_value(&default_snapshot_versions),
|
.value_parser(value_parser!(u32))
|
||||||
|
.default_value(default_snapshot_versions),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
arg!(--snapshot-days [NUM] "Target number of days between snapshots")
|
arg!(--"snapshot-days" <NUM> "Target number of days between snapshots")
|
||||||
.default_value(&default_snapshot_days)
|
.value_parser(value_parser!(i64))
|
||||||
.required(false),
|
.default_value(default_snapshot_days),
|
||||||
)
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
let data_dir = matches.value_of("data-dir").unwrap();
|
let data_dir: &OsString = matches.get_one("data-dir").unwrap();
|
||||||
let port = matches.value_of("port").unwrap();
|
let port: usize = *matches.get_one("port").unwrap();
|
||||||
let snapshot_versions = matches.value_of("snapshot-versions").unwrap();
|
let snapshot_versions: u32 = *matches.get_one("snapshot-versions").unwrap();
|
||||||
let snapshot_days = matches.value_of("snapshot-versions").unwrap();
|
let snapshot_days: i64 = *matches.get_one("snapshot-days").unwrap();
|
||||||
|
|
||||||
let config = ServerConfig::from_args(snapshot_days, snapshot_versions)?;
|
let config = ServerConfig::from_args(snapshot_days, snapshot_versions)?;
|
||||||
let server = Server::new(config, Box::new(SqliteStorage::new(data_dir)?));
|
let server = Server::new(config, Box::new(SqliteStorage::new(data_dir)?));
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
//! invariants, and so on. This does not implement the HTTP-specific portions; those
|
//! invariants, and so on. This does not implement the HTTP-specific portions; those
|
||||||
//! are in [`crate::api`]. See the protocol documentation for details.
|
//! are in [`crate::api`]. See the protocol documentation for details.
|
||||||
use crate::storage::{Client, Snapshot, StorageTxn};
|
use crate::storage::{Client, Snapshot, StorageTxn};
|
||||||
use anyhow::Context;
|
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
@@ -37,14 +36,10 @@ impl Default for ServerConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ServerConfig {
|
impl ServerConfig {
|
||||||
pub fn from_args(snapshot_days: &str, snapshot_versions: &str) -> anyhow::Result<ServerConfig> {
|
pub fn from_args(snapshot_days: i64, snapshot_versions: u32) -> anyhow::Result<ServerConfig> {
|
||||||
Ok(ServerConfig {
|
Ok(ServerConfig {
|
||||||
snapshot_days: snapshot_days
|
snapshot_days: snapshot_days,
|
||||||
.parse()
|
snapshot_versions: snapshot_versions,
|
||||||
.context("--snapshot-days must be a number")?,
|
|
||||||
snapshot_versions: snapshot_versions
|
|
||||||
.parse()
|
|
||||||
.context("--snapshot-days must be a number")?,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user