#[cfg(test)]
pub mod badge_check;
pub mod blender;
pub mod bootstrap;
pub mod git;
pub mod gitattributes;
pub mod gitignore;
pub mod modules;
pub mod notify;
pub mod quality;
pub mod rojo;
pub mod studio_plugin;
pub mod testez;
pub mod toolchain;
pub mod update_check;
pub mod vscode;
pub mod wally;
use std::path::Path;
use std::process::Command;
use anyhow::{bail, Context, Result};
use crate::ui;
pub fn run(program: &str, args: &[&str]) -> Result<()> {
run_in(program, args, None)
}
pub fn run_in(program: &str, args: &[&str], dir: Option<&Path>) -> Result<()> {
let output = capture(program, args, dir)?;
if !output.success || ui::is_verbose() {
ui::passthrough(&output.stdout, &output.stderr);
}
if !output.success {
bail!("`{program} {}` failed", args.join(" "));
}
Ok(())
}
#[derive(Debug)]
pub struct Captured {
pub stdout: String,
pub stderr: String,
pub success: bool,
}
impl Captured {
pub fn combined(&self) -> String {
format!("{}{}", self.stdout, self.stderr)
}
}
pub fn capture(program: &str, args: &[&str], dir: Option<&Path>) -> Result<Captured> {
ui::command(program, args);
let mut cmd = Command::new(program);
cmd.args(args);
if let Some(dir) = dir {
cmd.current_dir(dir);
}
let output = cmd.output().with_context(|| format!("failed to spawn `{program}`"))?;
Ok(Captured {
stdout: String::from_utf8_lossy(&output.stdout).into_owned(),
stderr: String::from_utf8_lossy(&output.stderr).into_owned(),
success: output.status.success(),
})
}
pub fn probe(program: &str, args: &[&str]) -> bool {
Command::new(program)
.args(args)
.output()
.map(|o| o.status.success())
.unwrap_or(false)
}
pub fn github_get_text(url: &str) -> Result<String> {
match ureq::get(url).header("User-Agent", "rproj").call() {
Ok(mut response) => response.body_mut().read_to_string().context("failed to read response body"),
Err(ureq::Error::StatusCode(403)) => bail!(
"GitHub's unauthenticated API rate limit (60 requests/hour per IP) was hit while \
calling {url}. Wait for it to reset (up to an hour) and try again."
),
Err(err) => Err(err).with_context(|| format!("failed to call {url}")),
}
}