From 5250aa0549c3a6230f4754c7b92d3193c0af0aab Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Sun, 29 Oct 2023 00:08:58 +0000 Subject: [PATCH] feat: move extra args to NIX_ARGS env --- --- /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) +} -- gitstuff