mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Add download/request speed limiter (#250)
This commit is contained in:
parent
f9e431e181
commit
be3248a4f9
9 changed files with 230 additions and 76 deletions
|
|
@ -9,3 +9,20 @@ pub fn clap_parse_resolution(s: &str) -> Result<Resolution, String> {
|
|||
pub fn clap_parse_proxy(s: &str) -> Result<Proxy, String> {
|
||||
Proxy::all(s).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
pub fn clap_parse_speed_limit(s: &str) -> Result<u32, String> {
|
||||
let quota = s.to_lowercase();
|
||||
|
||||
let bytes = if let Ok(b) = quota.parse() {
|
||||
b
|
||||
} else if let Ok(b) = quota.trim_end_matches('b').parse::<u32>() {
|
||||
b
|
||||
} else if let Ok(kb) = quota.trim_end_matches("kb").parse::<u32>() {
|
||||
kb * 1024
|
||||
} else if let Ok(mb) = quota.trim_end_matches("mb").parse::<u32>() {
|
||||
mb * 1024 * 1024
|
||||
} else {
|
||||
return Err("Invalid speed limit".to_string());
|
||||
};
|
||||
Ok(bytes)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue