MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / parse_platform

Function parse_platform

crates/openshell-bootstrap/src/build.rs:72–98  ·  view source on GitHub ↗

Parse `os/arch[/variant]` and reject malformed empty segments.

(platform: &str)

Source from the content-addressed store, hash-verified

70
71/// Parse `os/arch[/variant]` and reject malformed empty segments.
72fn 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///

Callers 1

Calls 2

nextMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected