mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-19 09:53:08 +02:00
update to clap-4.x
This commit is contained in:
parent
898ccd8797
commit
9e6be07e24
3 changed files with 21 additions and 25 deletions
|
@ -15,7 +15,7 @@ thiserror = "1.0"
|
|||
futures = "^0.3.24"
|
||||
serde = "^1.0.145"
|
||||
serde_json = "^1.0"
|
||||
clap = "^4.0.4"
|
||||
clap = { version = "^4.0.4", features = ["string"] }
|
||||
log = "^0.4.17"
|
||||
env_logger = "^0.9.1"
|
||||
rusqlite = { version = "0.28", features = ["bundled"] }
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#![deny(clippy::all)]
|
||||
|
||||
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::{Server, ServerConfig};
|
||||
|
||||
|
@ -17,30 +18,30 @@ async fn main() -> anyhow::Result<()> {
|
|||
.arg(
|
||||
arg!(-p --port <PORT> "Port on which to serve")
|
||||
.help("Port on which to serve")
|
||||
.default_value("8080")
|
||||
.required(true),
|
||||
.value_parser(value_parser!(usize))
|
||||
.default_value("8080"),
|
||||
)
|
||||
.arg(
|
||||
arg!(-d --data-dir <DIR> "Directory in which to store data")
|
||||
.default_value("/var/lib/taskchampion-sync-server")
|
||||
.allow_invalid_utf8(true)
|
||||
.required(true),
|
||||
arg!(-d --"data-dir" <DIR> "Directory in which to store data")
|
||||
.value_parser(ValueParser::os_string())
|
||||
.default_value("/var/lib/taskchampion-sync-server"),
|
||||
)
|
||||
.arg(
|
||||
arg!(--snapshot-versions [NUM] "Target number of versions between snapshots")
|
||||
.default_value(&default_snapshot_versions),
|
||||
arg!(--"snapshot-versions" <NUM> "Target number of versions between snapshots")
|
||||
.value_parser(value_parser!(u32))
|
||||
.default_value(default_snapshot_versions),
|
||||
)
|
||||
.arg(
|
||||
arg!(--snapshot-days [NUM] "Target number of days between snapshots")
|
||||
.default_value(&default_snapshot_days)
|
||||
.required(false),
|
||||
arg!(--"snapshot-days" <NUM> "Target number of days between snapshots")
|
||||
.value_parser(value_parser!(i64))
|
||||
.default_value(default_snapshot_days),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let data_dir = matches.value_of("data-dir").unwrap();
|
||||
let port = matches.value_of("port").unwrap();
|
||||
let snapshot_versions = matches.value_of("snapshot-versions").unwrap();
|
||||
let snapshot_days = matches.value_of("snapshot-versions").unwrap();
|
||||
let data_dir: &OsString = matches.get_one("data-dir").unwrap();
|
||||
let port: usize = *matches.get_one("port").unwrap();
|
||||
let snapshot_versions: u32 = *matches.get_one("snapshot-versions").unwrap();
|
||||
let snapshot_days: i64 = *matches.get_one("snapshot-days").unwrap();
|
||||
|
||||
let config = ServerConfig::from_args(snapshot_days, snapshot_versions)?;
|
||||
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
|
||||
//! are in [`crate::api`]. See the protocol documentation for details.
|
||||
use crate::storage::{Client, Snapshot, StorageTxn};
|
||||
use anyhow::Context;
|
||||
use chrono::Utc;
|
||||
use uuid::Uuid;
|
||||
|
||||
|
@ -37,14 +36,10 @@ impl Default for 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 {
|
||||
snapshot_days: snapshot_days
|
||||
.parse()
|
||||
.context("--snapshot-days must be a number")?,
|
||||
snapshot_versions: snapshot_versions
|
||||
.parse()
|
||||
.context("--snapshot-days must be a number")?,
|
||||
snapshot_days: snapshot_days,
|
||||
snapshot_versions: snapshot_versions,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue