-
-
Notifications
You must be signed in to change notification settings - Fork 829
Expand file tree
/
Copy pathbase_tool.rs
More file actions
62 lines (54 loc) · 1.95 KB
/
Copy pathbase_tool.rs
File metadata and controls
62 lines (54 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use anyhow::{Context, Result};
pub fn resolve_bin() -> Option<PathBuf> {
if let Ok(value) = std::env::var("FLOW_BASE_BIN") {
let trimmed = value.trim();
if !trimmed.is_empty() {
return Some(PathBuf::from(trimmed));
}
}
// Prefer a more specific name, but fall back to the current base repo binary name.
for name in ["base", "db"] {
if let Ok(path) = which::which(name) {
return Some(path);
}
}
None
}
pub fn run_inherit_stdio(bin: &Path, args: &[String]) -> Result<()> {
let status = Command::new(bin)
.args(args)
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.status()
.with_context(|| format!("failed to run {} {}", bin.display(), args.join(" ")))?;
if !status.success() {
anyhow::bail!("{} exited with {}", bin.display(), status);
}
Ok(())
}
pub fn run_with_stdin(bin: &Path, args: &[String], stdin: &str) -> Result<()> {
let mut child = Command::new(bin)
.args(args)
.stdin(Stdio::piped())
.stdout(Stdio::null())
// This path is currently only used for best-effort "task run" ingestion.
// If the user has some other `base` binary on PATH (or an older one),
// it may print usage/errors like "unrecognized subcommand 'ingest'".
// We intentionally silence stderr to avoid confusing noise during normal runs.
.stderr(Stdio::null())
.spawn()
.with_context(|| format!("failed to spawn {} {}", bin.display(), args.join(" ")))?;
{
use std::io::Write;
let child_stdin = child.stdin.as_mut().context("failed to open stdin")?;
child_stdin.write_all(stdin.as_bytes())?;
}
let status = child.wait()?;
if !status.success() {
anyhow::bail!("{} exited with {}", bin.display(), status);
}
Ok(())
}