diff --git a/src/bin/fetch_game_info.rs b/src/bin/fetch_game_info.rs new file mode 100644 index 0000000..68d8906 --- /dev/null +++ b/src/bin/fetch_game_info.rs @@ -0,0 +1,20 @@ +use clichess::ClientRequest; +use std::os::unix::net::UnixStream; + + +fn main() { + let version = env!("CARGO_PKG_VERSION"); + eprintln!("Running clichess fetch_game_info version {}", version); + let mut stream = match UnixStream::connect("/tmp/clichess.socket") { + Ok(sock) => sock, + Err(_) => { + eprintln!("clichess daemon is not running."); + return; + } + }; + clichess::write_to_stream(&mut stream, serde_json::to_string(&ClientRequest::GetGameInfo).unwrap()).unwrap(); + let response = clichess::read_line_from_stream(&stream).expect("Error message from server"); + clichess::write_to_stream(&mut stream, serde_json::to_string(&ClientRequest::Exit).unwrap()).unwrap(); + clichess::read_line_from_stream(&stream).expect("Error message from server"); + println!("{}", response); +}