Drop ParsedDuration and use Duration directly
This commit is contained in:
parent
35b4871c52
commit
8d60cd71b4
1 changed files with 10 additions and 20 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{net::SocketAddr, path::PathBuf, str::FromStr, sync::Arc, time::Duration};
|
use std::{net::SocketAddr, path::PathBuf, sync::Arc, time::Duration};
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use clap::{Parser, ValueEnum};
|
use clap::{Parser, ValueEnum};
|
||||||
|
|
@ -24,16 +24,6 @@ enum LogLevel {
|
||||||
Error,
|
Error,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
|
||||||
struct ParsedDuration(Duration);
|
|
||||||
impl FromStr for ParsedDuration {
|
|
||||||
type Err = parse_duration::parse::Error;
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
||||||
parse_duration::parse(s).map(ParsedDuration)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[clap(version, author, about)]
|
#[clap(version, author, about)]
|
||||||
struct Opts {
|
struct Opts {
|
||||||
|
|
@ -44,8 +34,8 @@ struct Opts {
|
||||||
/// The interval to poll trackers, e.g. 30s.
|
/// The interval to poll trackers, e.g. 30s.
|
||||||
/// Trackers send the refresh interval when we connect to them. Often this is
|
/// Trackers send the refresh interval when we connect to them. Often this is
|
||||||
/// pretty big, e.g. 30 minutes. This can force a certain value.
|
/// pretty big, e.g. 30 minutes. This can force a certain value.
|
||||||
#[clap(short = 'i', long = "tracker-refresh-interval")]
|
#[clap(short = 'i', long = "tracker-refresh-interval", value_parser = parse_duration::parse)]
|
||||||
force_tracker_interval: Option<ParsedDuration>,
|
force_tracker_interval: Option<Duration>,
|
||||||
|
|
||||||
/// The listen address for HTTP API
|
/// The listen address for HTTP API
|
||||||
#[clap(long = "http-api-listen-addr", default_value = "127.0.0.1:3030")]
|
#[clap(long = "http-api-listen-addr", default_value = "127.0.0.1:3030")]
|
||||||
|
|
@ -67,12 +57,12 @@ struct Opts {
|
||||||
disable_dht_persistence: bool,
|
disable_dht_persistence: bool,
|
||||||
|
|
||||||
/// The connect timeout, e.g. 1s, 1.5s, 100ms etc.
|
/// The connect timeout, e.g. 1s, 1.5s, 100ms etc.
|
||||||
#[clap(long = "peer-connect-timeout")]
|
#[clap(long = "peer-connect-timeout", value_parser = parse_duration::parse)]
|
||||||
peer_connect_timeout: Option<ParsedDuration>,
|
peer_connect_timeout: Option<Duration>,
|
||||||
|
|
||||||
/// The connect timeout, e.g. 1s, 1.5s, 100ms etc.
|
/// The connect timeout, e.g. 1s, 1.5s, 100ms etc.
|
||||||
#[clap(long = "peer-read-write-timeout")]
|
#[clap(long = "peer-read-write-timeout" , value_parser = parse_duration::parse)]
|
||||||
peer_read_write_timeout: Option<ParsedDuration>,
|
peer_read_write_timeout: Option<Duration>,
|
||||||
|
|
||||||
/// How many threads to spawn for the executor.
|
/// How many threads to spawn for the executor.
|
||||||
#[clap(short = 't', long)]
|
#[clap(short = 't', long)]
|
||||||
|
|
@ -207,8 +197,8 @@ async fn async_main(opts: Opts, spawner: BlockingSpawner) -> anyhow::Result<()>
|
||||||
dht_config: None,
|
dht_config: None,
|
||||||
peer_id: None,
|
peer_id: None,
|
||||||
peer_opts: Some(PeerConnectionOptions {
|
peer_opts: Some(PeerConnectionOptions {
|
||||||
connect_timeout: opts.peer_connect_timeout.map(|d| d.0),
|
connect_timeout: opts.peer_connect_timeout,
|
||||||
read_write_timeout: opts.peer_read_write_timeout.map(|d| d.0),
|
read_write_timeout: opts.peer_read_write_timeout,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
@ -286,7 +276,7 @@ async fn async_main(opts: Opts, spawner: BlockingSpawner) -> anyhow::Result<()>
|
||||||
only_files_regex: download_opts.only_files_matching_regex.clone(),
|
only_files_regex: download_opts.only_files_matching_regex.clone(),
|
||||||
overwrite: download_opts.overwrite,
|
overwrite: download_opts.overwrite,
|
||||||
list_only: download_opts.list,
|
list_only: download_opts.list,
|
||||||
force_tracker_interval: opts.force_tracker_interval.map(|d| d.0),
|
force_tracker_interval: opts.force_tracker_interval,
|
||||||
output_folder: download_opts.output_folder.clone(),
|
output_folder: download_opts.output_folder.clone(),
|
||||||
sub_folder: download_opts.sub_folder.clone(),
|
sub_folder: download_opts.sub_folder.clone(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue