extern crate hglib; use hglib::cmdserver::CommandServer; use hglib::Chunk; fn run_command(cmdserver: &mut CommandServer, command: Vec<&[u8]>) -> (i32, Vec, Vec) { let (mut result, mut output, mut error) = (-1i32, vec![], vec![]); let run = cmdserver.connection .raw_command(command) .ok().expect("failed to send 'log' command"); for chunk in run { match chunk { Ok(Chunk::Output(s)) => output.extend(s), Ok(Chunk::Error(s)) => error.extend(s), Ok(Chunk::Result(r)) => { result = r }, Ok(_) => unimplemented!(), Err(e) => panic!("failed to read command results: {}", e), } } (result, output, error) } fn main() { let mut cmdserver = CommandServer::new().ok().expect("failed to start command server"); println!("capabilities: {:?}", cmdserver.capabilities); println!("encoding: {:?}", cmdserver.encoding); let (result, output, error) = run_command(&mut cmdserver, vec![b"log", b"-l", b"5"]); cmdserver.connection.close().ok().expect("command server did not stop cleanly"); println!("output: {}", String::from_utf8(output).unwrap().trim_right_matches('\n')); println!("error: {}", String::from_utf8(error).unwrap().trim_right_matches('\n')); println!("result: {:?}", result); }