--- /dev/null +++ b/cmds/fleet/src/extra_args.rs @@ -0,0 +1,18 @@ +use anyhow::anyhow; +use anyhow::Result; +use std::ffi::{OsStr, OsString}; + +pub fn parse_os(os: &OsStr) -> Result> { + Ok(shlex::bytes::split(os.as_encoded_bytes()) + .ok_or_else(|| anyhow!("invalid arguments"))? + .into_iter() + .map(|a| { + // Unpaired surrogates are not touched + unsafe { OsString::from_encoded_bytes_unchecked(a) } + }) + .collect()) +} +pub fn parse(s: &str) -> Result> { + let osstr = OsString::try_from(s)?; + parse_os(&osstr) +}