pub fn wrap_sudo_command(command: &str, password: Option<&str>) -> StringExpand description
Wraps a command for execution with sudo privileges.
§Arguments
command- The command to wrap with sudopassword- Optional sudo password. If None, usessudo -n(passwordless). If Some, usesprintf | sudo -Sto pipe the password.
§Returns
A string containing the wrapped command ready for execution.
§Examples
use ssh_mcp::ssh::elevation::wrap_sudo_command;
// Passwordless sudo
let cmd = wrap_sudo_command("apt update", None);
assert_eq!(cmd, "sudo -n sh -c 'apt update'");
// Sudo with password
let cmd = wrap_sudo_command("apt update", Some("mypassword"));
assert_eq!(cmd, "printf '%s\\n' 'mypassword' | sudo -S -p '' sh -c 'apt update'");