mirror of
https://github.com/lune-org/lune.git
synced 2025-05-04 10:43:57 +01:00
Remove legacy stdin option in favor of full stdio options on process exec + adjust tests accordingly
This commit is contained in:
parent
551120fba1
commit
1119f0d46b
4 changed files with 49 additions and 34 deletions
|
@ -118,21 +118,11 @@ impl FromLua for ProcessSpawnOptions {
|
|||
}
|
||||
|
||||
/*
|
||||
If we got options for stdio handling, parse those as well - note that
|
||||
we accept a separate "stdin" value here for compatibility with older
|
||||
scripts, but the user should preferrably pass it in the stdio table
|
||||
If we got options for stdio handling, parse those as well
|
||||
|
||||
This may optionally contain configuration for any or all of: stdin, stdout, stderr
|
||||
*/
|
||||
this.stdio = value.get("stdio")?;
|
||||
match value.get("stdin")? {
|
||||
LuaValue::Nil => {}
|
||||
LuaValue::String(s) => this.stdio.stdin = Some(s.as_bytes().to_vec()),
|
||||
value => {
|
||||
return Err(LuaError::RuntimeError(format!(
|
||||
"Invalid type for option 'stdin' - expected 'string', got '{}'",
|
||||
value.type_name()
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
Ok(this)
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use bstr::BString;
|
||||
use mlua::prelude::*;
|
||||
|
||||
use super::kind::ProcessSpawnOptionsStdioKind;
|
||||
|
@ -29,8 +30,8 @@ impl FromLua for ProcessSpawnOptionsStdio {
|
|||
LuaValue::Table(t) => {
|
||||
let mut this = Self::default();
|
||||
|
||||
if let Some(stdin) = t.get("stdin")? {
|
||||
this.stdin = stdin;
|
||||
if let Some(stdin) = t.get::<Option<BString>>("stdin")? {
|
||||
this.stdin = Some(stdin.to_vec());
|
||||
}
|
||||
|
||||
if let Some(stdout) = t.get("stdout")? {
|
||||
|
|
|
@ -2,27 +2,35 @@ export type OS = "linux" | "macos" | "windows"
|
|||
export type Arch = "x86_64" | "aarch64"
|
||||
export type Endianness = "big" | "little"
|
||||
|
||||
export type StdioKind = "default" | "inherit" | "forward" | "none"
|
||||
export type StdioOptions = {
|
||||
stdin: StdioKind?,
|
||||
stdout: StdioKind?,
|
||||
stderr: StdioKind?,
|
||||
}
|
||||
|
||||
--[=[
|
||||
@interface CreateOptions
|
||||
@interface ExecStdioKind
|
||||
@within Process
|
||||
|
||||
A dictionary of options for `process.create`, with the following available values:
|
||||
Enum determining how to treat a standard input/output stream for `process.exec`.
|
||||
|
||||
* `cwd` - The current working directory for the process
|
||||
* `env` - Extra environment variables to give to the process
|
||||
* `shell` - Whether to run in a shell or not - set to `true` to run using the default shell, or a string to run using a specific shell
|
||||
Can be one of the following values:
|
||||
|
||||
* `default` - The default behavior, writing to the final result table only
|
||||
* `inherit` - Inherit the stream from the parent process, writing to both the result table and the respective stream for the parent process
|
||||
* `forward` - Forward the stream to the parent process, without writing to the result table, only respective stream for the parent process
|
||||
* `none` - Do not create any input/output stream
|
||||
]=]
|
||||
export type CreateOptions = {
|
||||
cwd: string?,
|
||||
env: { [string]: string }?,
|
||||
shell: (boolean | string)?,
|
||||
export type ExecStdioKind = "default" | "inherit" | "forward" | "none"
|
||||
|
||||
--[=[
|
||||
@interface ExecStdioOptions
|
||||
@within Process
|
||||
|
||||
A dictionary of stdio-specific options for `process.exec`, with the following available values:
|
||||
|
||||
* `stdin` - A buffer or string to write to the stdin of the process
|
||||
* `stdout` - How to treat the stdout stream from the child process - see `ExecStdioKind` for more info
|
||||
* `stderr` - How to treat the stderr stream from the child process - see `ExecStdioKind` for more info
|
||||
]=]
|
||||
export type ExecStdioOptions = {
|
||||
stdin: (buffer | string)?,
|
||||
stdout: ExecStdioKind?,
|
||||
stderr: ExecStdioKind?,
|
||||
}
|
||||
|
||||
--[=[
|
||||
|
@ -40,7 +48,23 @@ export type ExecOptions = {
|
|||
cwd: string?,
|
||||
env: { [string]: string }?,
|
||||
shell: (boolean | string)?,
|
||||
stdio: (StdioKind | StdioOptions)?,
|
||||
stdio: (ExecStdioKind | ExecStdioOptions)?,
|
||||
}
|
||||
|
||||
--[=[
|
||||
@interface CreateOptions
|
||||
@within Process
|
||||
|
||||
A dictionary of options for `process.create`, with the following available values:
|
||||
|
||||
* `cwd` - The current working directory for the process
|
||||
* `env` - Extra environment variables to give to the process
|
||||
* `shell` - Whether to run in a shell or not - set to `true` to run using the default shell, or a string to run using a specific shell
|
||||
]=]
|
||||
export type CreateOptions = {
|
||||
cwd: string?,
|
||||
env: { [string]: string }?,
|
||||
shell: (boolean | string)?,
|
||||
}
|
||||
|
||||
--[=[
|
||||
|
|
|
@ -10,8 +10,8 @@ local echoMessage = "Hello from child process!"
|
|||
-- When passing stdin to powershell on windows we must "accept" using the double newline
|
||||
|
||||
local result = if IS_WINDOWS
|
||||
then process.exec("powershell", { "echo" }, { stdin = echoMessage .. "\n\n" })
|
||||
else process.exec("xargs", { "echo" }, { stdin = echoMessage })
|
||||
then process.exec("powershell", { "echo" }, { stdio = { stdin = echoMessage .. "\n\n" } })
|
||||
else process.exec("xargs", { "echo" }, { stdio = { stdin = echoMessage } })
|
||||
|
||||
local resultStdout = if IS_WINDOWS
|
||||
then string.sub(result.stdout, #result.stdout - #echoMessage - 1)
|
||||
|
|
Loading…
Add table
Reference in a new issue