pub struct CommandArg { /* private fields */ }Expand description
A validated command argument with sanitization
This newtype ensures that command arguments do not contain shell metacharacters that could lead to command injection attacks.
Implementations§
Source§impl CommandArg
impl CommandArg
Sourcepub fn new<S: AsRef<str>>(arg: S) -> Result<Self>
pub fn new<S: AsRef<str>>(arg: S) -> Result<Self>
Create a new CommandArg from a string
§Validation Rules
- Argument cannot contain shell metacharacters (;|&><$`\n\r)
- Argument can be empty (for flags like –release)
§Examples
use ggen_utils::safe_command::CommandArg;
// Valid arguments
assert!(CommandArg::new("build").is_ok());
assert!(CommandArg::new("--release").is_ok());
assert!(CommandArg::new("").is_ok());
// Invalid arguments (shell metacharacters)
assert!(CommandArg::new("build; rm -rf /").is_err());
assert!(CommandArg::new("build | tee").is_err());
assert!(CommandArg::new("$(whoami)").is_err());Sourcepub fn from_path(path: &SafePath) -> Self
pub fn from_path(path: &SafePath) -> Self
Create a CommandArg from a SafePath
This ensures that path arguments are validated through SafePath.
§Examples
use ggen_utils::safe_command::CommandArg;
use ggen_utils::safe_path::SafePath;
let path = SafePath::new("src/generated").unwrap();
let arg = CommandArg::from_path(&path);
assert_eq!(arg.as_str(), "src/generated");Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Convert into the inner String
Trait Implementations§
Source§impl Clone for CommandArg
impl Clone for CommandArg
Source§fn clone(&self) -> CommandArg
fn clone(&self) -> CommandArg
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CommandArg
impl Debug for CommandArg
Source§impl Display for CommandArg
impl Display for CommandArg
impl Eq for CommandArg
Source§impl Hash for CommandArg
impl Hash for CommandArg
Source§impl PartialEq for CommandArg
impl PartialEq for CommandArg
impl StructuralPartialEq for CommandArg
Source§impl TryFrom<&str> for CommandArg
impl TryFrom<&str> for CommandArg
Auto Trait Implementations§
impl Freeze for CommandArg
impl RefUnwindSafe for CommandArg
impl Send for CommandArg
impl Sync for CommandArg
impl Unpin for CommandArg
impl UnsafeUnpin for CommandArg
impl UnwindSafe for CommandArg
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.