Skip to content

Commit 079183b

Browse files
committed
fix: flags for interactive commands
1 parent 3b95eaf commit 079183b

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

src/runner.rs

+25-9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ pub fn run(package: &Package, binary: Option<String>, params: &Vec<String>) -> b
2424
let mut args = vec!["run".to_string(), "--rm".to_string()];
2525
if interactive {
2626
args.push("-i".to_string());
27+
} else {
28+
args.push("-it".to_string());
2729
}
2830

2931
add_volumes(package, &mut args);
@@ -85,39 +87,53 @@ fn add_binary_entrypoint(package: &Package, binary: &Option<String>, args: &mut
8587
}
8688
}
8789

88-
fn get_stdio(config: &crate::configs::user::Root) -> (Stdio, Stdio) {
90+
fn get_stdio(config: &crate::configs::user::Root, stdin_buffer: &Option<Vec<u8>>) -> (Stdio, Stdio, Stdio) {
91+
let stdin = if let Some(b) = stdin_buffer {
92+
if b.is_empty() {
93+
Stdio::inherit()
94+
} else {
95+
Stdio::piped()
96+
}
97+
} else {
98+
Stdio::inherit()
99+
};
100+
89101
let stdout = if config.experimental.capture_stdout {
90102
Stdio::piped()
91103
} else {
92104
Stdio::inherit()
93105
};
106+
94107
let stderr = if config.experimental.capture_stderr {
95108
Stdio::piped()
96109
} else {
97110
Stdio::inherit()
98111
};
99-
(stdout, stderr)
112+
113+
(stdin, stdout, stderr)
100114
}
101115

102116
fn run_command_with_args(command: &str, args: &[String], stdin_buffer: Option<Vec<u8>>) -> bool {
103-
debug!("Running command: {} {:?}", command, args);
117+
debug!("Running command: {} {}", command, args.join(" "));
104118

105119
let config = UserConfig::load().unwrap_or_default();
106-
let (stdout, stderr) = get_stdio(&config);
120+
let (stdin, stdout, stderr) = get_stdio(&config, &stdin_buffer);
107121

108122
let mut child = Command::new(command)
109123
.args(args)
110124
.stdout(stdout)
111125
.stderr(stderr)
112-
.stdin(Stdio::piped())
126+
.stdin(stdin)
113127
.spawn()
114128
.expect("Failed to spawn command");
115129

116130
if let Some(buffer) = stdin_buffer {
117-
let child_stdin = child.stdin.as_mut().expect("Failed to open stdin");
118-
child_stdin
119-
.write_all(&buffer)
120-
.expect("Failed to write to stdin");
131+
if buffer.len() > 0 {
132+
let child_stdin = child.stdin.as_mut().expect("Failed to open stdin");
133+
child_stdin
134+
.write_all(&buffer)
135+
.expect("Failed to write to stdin");
136+
}
121137
}
122138

123139
let stdout_thread = spawn_log_thread(

0 commit comments

Comments
 (0)