Add binary to fetch fen from game

It can be used to show the game in external programs.
This commit is contained in:
Artlef 2020-12-06 22:46:02 +01:00
parent 4748d61bca
commit 8377717cc3

View File

@ -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);
}