use std::{
ffi::OsStr,
io,
path::Path,
process::{Command, ExitStatus},
};
use thiserror::Error;
pub mod url;
#[cfg(feature = "download")]
pub mod download;
#[derive(Error, Debug)]
pub enum RunError {
#[error("could not run ngrok. status: {0}")]
CouldNotRun(ExitStatus),
#[error("could not find ngrok binary")]
CouldNotFindBinary,
#[error("io")]
IO(#[from] io::Error),
}
pub fn run<T: AsRef<OsStr>>(bin: &Path, auth_token: &str, args: &[T]) -> Result<(), RunError> {
let mut child = Command::new(bin)
.env("NGROK_AUTHTOKEN", auth_token)
.args(args)
.spawn()?;
let status = child.wait()?;
if !status.success() {
return Err(RunError::CouldNotRun(status));
}
Ok(())
}