libtun 0.1.0

a cross-platform(macosx, linux) tunnel library
Documentation
use crate::errors::*;
use std::ffi::OsStr;
use std::io;
use std::process::Command;

#[cfg(target_os = "macos")]
mod raw_darwin;
#[cfg(target_os = "macos")]
pub use raw_darwin::*;

#[cfg(target_os = "linux")]
mod raw_linux;
#[cfg(target_os = "linux")]
pub use raw_linux::*;

pub fn run_shell<S: AsRef<OsStr>>(cmd_ref: S) -> Result<()> {
  let cmd: String = cmd_ref.as_ref().to_str().unwrap().into();
  // println!("run shell: {}", cmd);
  let result: std::process::Output = Command::new("env")
    .arg("bash")
    .arg("-c")
    .arg(cmd_ref)
    .output()
    .context(RunShellError { cmd: cmd.to_owned() })?;
  if !result.status.success() {
    let stderr: String = String::from_utf8_lossy(result.stderr.as_ref()).into();
    return ShellResultError {
      result: stderr,
      cmd: cmd,
    }.fail();
  }
  let stdout = String::from_utf8_lossy(result.stdout.as_ref());
  print!("{}", stdout);
  Ok(())
}