#![cfg(unix)] use async_trait::async_trait; use bytes::Bytes; use std::env; use std::process; use tokio::io; use tokio::io::AsyncWriteExt; use tokio_hglib::{UiHandler, UnixClient}; struct StdUiHandler { stdout: io::Stdout, stderr: io::Stderr, } #[async_trait] impl UiHandler for StdUiHandler { async fn read_data(&mut self, _len: usize) -> io::Result { Ok(Bytes::new()) // EOF } async fn read_line(&mut self, _len: usize) -> io::Result { Ok(Bytes::new()) // EOF } async fn write_output(&mut self, data: Bytes) -> io::Result<()> { self.stdout.write_all(&data).await } async fn write_error(&mut self, data: Bytes) -> io::Result<()> { self.stderr.write_all(&data).await } } #[tokio::main(flavor = "current_thread")] async fn run() -> io::Result { let sock_path = env::var_os("CHGSOCKNAME").expect("specify CHGSOCKNAME"); let mut handler = StdUiHandler { stdout: io::stdout(), stderr: io::stderr(), }; let mut client = UnixClient::connect(sock_path).await?; client .run_command_os(&mut handler, env::args_os().skip(1)) .await } fn main() -> io::Result<()> { let code = run()?; process::exit(code); }