Parse a duration string like "5m", "1h", "30s" into milliseconds.
(s: &str)
| 6135 | |
| 6136 | /// Parse a duration string like "5m", "1h", "30s" into milliseconds. |
| 6137 | fn parse_duration_to_ms(s: &str) -> Result<i64> { |
| 6138 | let s = s.trim(); |
| 6139 | if s.is_empty() { |
| 6140 | return Err(miette::miette!("empty duration string")); |
| 6141 | } |
| 6142 | let (num_str, unit) = s.split_at(s.len() - 1); |
| 6143 | let num: i64 = num_str |
| 6144 | .parse() |
| 6145 | .map_err(|_| miette::miette!("invalid duration: {s} (expected e.g. 5m, 1h, 30s)"))?; |
| 6146 | let multiplier = match unit { |
| 6147 | "s" => 1_000, |
| 6148 | "m" => 60_000, |
| 6149 | "h" => 3_600_000, |
| 6150 | _ => { |
| 6151 | return Err(miette::miette!( |
| 6152 | "unknown duration unit: {unit} (use s, m, or h)" |
| 6153 | )); |
| 6154 | } |
| 6155 | }; |
| 6156 | Ok(num * multiplier) |
| 6157 | } |
| 6158 | |
| 6159 | fn confirm_global_setting_takeover(key: &str, yes: bool) -> Result<()> { |
| 6160 | if yes { |
no test coverage detected