Function worterbuch_cli::app

source ·
pub fn app<'help>(
    name: &'help str,
    about: &'help str,
    args: Vec<Arg<'help>>
) -> Result<(ArgMatches, String, String, u16, bool, bool)>
Examples found in repository?
examples/last-will-test.rs (lines 14-18)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
async fn main() -> Result<()> {
    dotenv::dotenv().ok();

    let (_matches, proto, host_addr, port, _json, debug) = app(
        "last-will-test",
        "Test Wörterbuch's last will funciton.",
        vec![],
    )?;

    let on_disconnect = async move {
        eprintln!("Connection to server lost.");
        process::exit(1);
    };

    if debug {
        eprintln!("Server: {proto}://{host_addr}:{port}");
    }

    let mut con = wb::connect(
        &proto,
        &host_addr,
        port,
        vec![("last_will/hello/world", "OFFLINE").into()],
        vec![],
        on_disconnect,
    )
    .await?;

    con.set("last_will/hello/world", "ONLINE")?;

    let mut lines = BufReader::new(tokio::io::stdin()).lines();
    while let Ok(Some(value)) = lines.next_line().await {
        con.set("last_will/hello/world", &value)?;
    }

    Ok(())
}