Parse `os/arch[/variant]` and reject malformed empty segments.
(platform: &str)
| 70 | |
| 71 | /// Parse `os/arch[/variant]` and reject malformed empty segments. |
| 72 | fn parse_platform(platform: &str) -> Result<(&str, &str, &str)> { |
| 73 | let mut parts = platform.split('/'); |
| 74 | let os = parts |
| 75 | .next() |
| 76 | .filter(|v| !v.is_empty()) |
| 77 | .ok_or_else(|| miette::miette!("platform is missing an operating system"))?; |
| 78 | let arch = parts |
| 79 | .next() |
| 80 | .filter(|v| !v.is_empty()) |
| 81 | .ok_or_else(|| miette::miette!("platform is missing an architecture"))?; |
| 82 | // A trailing slash creates a malformed empty variant segment. |
| 83 | let variant = match parts.next() { |
| 84 | Some("") => { |
| 85 | return Err(miette::miette!( |
| 86 | "platform variant must not be empty (trailing slash?): '{platform}'" |
| 87 | )); |
| 88 | } |
| 89 | Some(v) => v, |
| 90 | None => "", |
| 91 | }; |
| 92 | if parts.next().is_some() { |
| 93 | return Err(miette::miette!( |
| 94 | "platform must be os/arch[/variant], got '{platform}'" |
| 95 | )); |
| 96 | } |
| 97 | Ok((os, arch, variant)) |
| 98 | } |
| 99 | |
| 100 | /// Seed Docker's implicit `BuildKit` platform args without replacing caller values. |
| 101 | /// |
no test coverage detected