mirror of
https://github.com/DioxusLabs/dioxus
synced 2025-02-16 05:38:26 +00:00
feat: commit code
This commit is contained in:
parent
da53c67841
commit
99b300d8d3
1 changed files with 56 additions and 21 deletions
|
@ -1,11 +1,47 @@
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
use mlua::UserData;
|
use mlua::{FromLua, UserData};
|
||||||
|
|
||||||
|
enum StdioFromString {
|
||||||
|
Inhert,
|
||||||
|
Piped,
|
||||||
|
Null,
|
||||||
|
}
|
||||||
|
impl<'lua> FromLua<'lua> for StdioFromString {
|
||||||
|
fn from_lua(lua_value: mlua::Value<'lua>, _lua: &'lua mlua::Lua) -> mlua::Result<Self> {
|
||||||
|
if let mlua::Value::String(v) = lua_value {
|
||||||
|
let v = v.to_str().unwrap();
|
||||||
|
return Ok(match v.to_lowercase().as_str() {
|
||||||
|
"inhert" => Self::Inhert,
|
||||||
|
"piped" => Self::Piped,
|
||||||
|
"null" => Self::Null,
|
||||||
|
_ => Self::Inhert,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Ok(Self::Inhert)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl StdioFromString {
|
||||||
|
pub fn to_stdio(self) -> Stdio {
|
||||||
|
match self {
|
||||||
|
StdioFromString::Inhert => Stdio::inherit(),
|
||||||
|
StdioFromString::Piped => Stdio::piped(),
|
||||||
|
StdioFromString::Null => Stdio::null(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct PluginCommander;
|
pub struct PluginCommander;
|
||||||
impl UserData for PluginCommander {
|
impl UserData for PluginCommander {
|
||||||
fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) {
|
fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) {
|
||||||
methods.add_function("exec", |_, cmd: Vec<String>| {
|
methods.add_function(
|
||||||
|
"exec",
|
||||||
|
|_, args: (Vec<String>, StdioFromString, StdioFromString)| {
|
||||||
|
|
||||||
|
let cmd = args.0;
|
||||||
|
let stdout = args.1;
|
||||||
|
let stderr = args.2;
|
||||||
|
|
||||||
if cmd.len() == 0 {
|
if cmd.len() == 0 {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -18,10 +54,11 @@ impl UserData for PluginCommander {
|
||||||
.map(|v| v.1.clone())
|
.map(|v| v.1.clone())
|
||||||
.collect::<Vec<String>>();
|
.collect::<Vec<String>>();
|
||||||
command.args(t);
|
command.args(t);
|
||||||
command.stdout(Stdio::inherit());
|
command.stdout(stdout.to_stdio()).stderr(stderr.to_stdio());
|
||||||
command.output()?;
|
command.output()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
},
|
||||||
|
);
|
||||||
methods.add_function("execQuiet", |_, cmd: Vec<String>| {
|
methods.add_function("execQuiet", |_, cmd: Vec<String>| {
|
||||||
if cmd.len() == 0 {
|
if cmd.len() == 0 {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
@ -45,7 +82,5 @@ impl UserData for PluginCommander {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_fields<'lua, F: mlua::UserDataFields<'lua, Self>>(_fields: &mut F) {
|
fn add_fields<'lua, F: mlua::UserDataFields<'lua, Self>>(_fields: &mut F) {}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue