commit 528dd364551f41d4c557e5ddfaea3326cdcc07cb Author: Tait Hoyem Date: Thu Mar 3 13:18:35 2022 -0700 Initial commit diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..f16355e --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "odilia-control" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/README.md b/README.md new file mode 100644 index 0000000..1350477 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# odilia-control + +Test for JSON-RPC based communication. + +Here are some examples on how to use it once odilia-recv (other test program_ is running. + +Try the following: + +``` +odilia-control '{"jsonrpc": "2.0", "method": "test", "id": "123"}' +odilia-control '{"jsonrpc": "2.0", "method": "next", "params": [{"tag": "code", "role": "link"}], "id": "123"}' +``` + +This program doesn't fascilitate a return yet, because it's just a proof of concept. +More ronbustness to come. diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..8c9b8a6 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,24 @@ +use std::{ + os::unix::net::UnixStream, + process::exit, + io::Write, + env, +}; + +fn sock_send(command: &str) -> std::io::Result<()> { + let mut stream = UnixStream::connect("/tmp/odilia-ctrl.sock")?; + stream.write_all(command.as_bytes())?; + Ok(()) +} + +fn main() { + let mut args_vec: Vec = env::args().collect(); + args_vec.remove(0); + let args = args_vec.join(" "); + if args.len() == 0 { + println!("You cannot send an empty command"); + exit(1); + } else { + let _ = sock_send(&args); + } +}