feat: ✨ Unix windows compatibility
This commit is contained in:
parent
6d4e8062fb
commit
ccc77a09e3
3 changed files with 26 additions and 22 deletions
|
@ -68,8 +68,20 @@ async fn execute(payload: Payload, debug: bool) -> Option<Output> {
|
||||||
if debug {
|
if debug {
|
||||||
println!("{:#?}", payload);
|
println!("{:#?}", payload);
|
||||||
}
|
}
|
||||||
match Command::new(payload.command)
|
let command = if cfg!(target_os = "windows") {
|
||||||
.args(payload.args)
|
"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()
|
.output()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,8 +26,7 @@ pub struct Config {
|
||||||
pub struct Payload {
|
pub struct Payload {
|
||||||
pub sudo: bool,
|
pub sudo: bool,
|
||||||
pub user: String,
|
pub user: String,
|
||||||
pub command: String,
|
pub args: String,
|
||||||
pub args: Vec<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
|
|
@ -91,26 +91,19 @@ async fn payload_from_input(debug: bool) -> Option<Payload> {
|
||||||
println!("Command");
|
println!("Command");
|
||||||
match get_input(debug) {
|
match get_input(debug) {
|
||||||
Some(input) => {
|
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 sudo = false;
|
||||||
let mut command = args.remove(0);
|
let args = match input.split_once(" ") {
|
||||||
if command == "sudo" {
|
Some(input_splitted) => {
|
||||||
if args.is_empty() {
|
if input_splitted.0 == "sudo" {
|
||||||
return None;
|
|
||||||
}
|
|
||||||
sudo = true;
|
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,
|
None => None,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue