feat: Unix windows compatibility

This commit is contained in:
Ahmet Kaan GÜMÜŞ 2024-07-08 17:59:41 +03:00
parent 6d4e8062fb
commit ccc77a09e3
3 changed files with 26 additions and 22 deletions

View file

@ -68,8 +68,20 @@ async fn execute(payload: Payload, debug: bool) -> Option<Output> {
if debug {
println!("{:#?}", payload);
}
match Command::new(payload.command)
.args(payload.args)
let command = if cfg!(target_os = "windows") {
"cmd"
} else {
"sh"
};
let first_arg = if cfg!(target_os = "windows") {
"/C"
} else {
"-c"
};
match Command::new(command)
.arg(first_arg)
.arg(payload.args)
.output()
.await
{

View file

@ -26,8 +26,7 @@ pub struct Config {
pub struct Payload {
pub sudo: bool,
pub user: String,
pub command: String,
pub args: Vec<String>,
pub args: String,
}
#[derive(Debug, Serialize, Deserialize)]

View file

@ -91,26 +91,19 @@ async fn payload_from_input(debug: bool) -> Option<Payload> {
println!("Command");
match get_input(debug) {
Some(input) => {
let mut args: Vec<String> = input.split_ascii_whitespace().map(String::from).collect();
if args.is_empty() {
None
} else {
let mut sudo = false;
let mut command = args.remove(0);
if command == "sudo" {
if args.is_empty() {
return None;
}
let args = match input.split_once(" ") {
Some(input_splitted) => {
if input_splitted.0 == "sudo" {
sudo = true;
command = args.remove(0);
input_splitted.1.to_string()
} else {
input
}
Some(Payload {
sudo,
user,
command,
args,
})
}
None => input,
};
Some(Payload { sudo, user, args })
}
None => None,
}