summaryrefslogtreecommitdiffstats
path: root/ipc/examples/assuan-client.rs
blob: aa7f3ed8acfad665c85cd2dd4a3d00f27917d73e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use futures::StreamExt;
use sequoia_ipc as ipc;
use crate::ipc::assuan::Client;

fn main() {
    let matches = clap::App::new("assuan-client")
        .version(env!("CARGO_PKG_VERSION"))
        .about("Connects to and sends commands to assuan servers.")
        .arg(clap::Arg::with_name("server").value_name("PATH")
             .required(true)
             .help("Server to connect to"))
        .arg(clap::Arg::with_name("commands").value_name("COMMAND")
             .required(true)
             .multiple(true)
             .help("Commands to send to the server"))
        .get_matches();

    let rt = tokio::runtime::Runtime::new().unwrap();
    rt.block_on(async {
        let mut c = Client::connect(matches.value_of("server").unwrap()).await.unwrap();
        for command in matches.values_of("commands").unwrap() {
            eprintln!("> {}", command);
            c.send(command).unwrap();
            while let Some(response) = c.next().await {
                eprintln!("< {:?}", response);
            }
        }
    });
}