From 051e884f55162498bae05e796b431e9122313c11 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sun, 9 Jun 2019 21:49:11 +0200 Subject: zotcli can now post messages with titles. --- examples/zot/item.rs | 11 +++++++++-- examples/zotcli.rs | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/zot/item.rs b/examples/zot/item.rs index ede1876..5c3bd40 100644 --- a/examples/zot/item.rs +++ b/examples/zot/item.rs @@ -15,10 +15,17 @@ * along with this program. If not, see . */ +use clap::ArgMatches; use zotapi; -pub fn post(client: &zotapi::Client, body: &str) { - match client.item().body(&body).create() { +pub fn post(client: &zotapi::Client, args: &ArgMatches) { + let mut msg = client.item(); + msg.body(args.value_of("BODY").unwrap()); + if let Some(title) = args.value_of("TITLE") { + msg.title(title); + } + + match msg.create() { Ok(payload) => { println!("Raw payload: {}", payload); }, diff --git a/examples/zotcli.rs b/examples/zotcli.rs index 565d3ff..986dc85 100644 --- a/examples/zotcli.rs +++ b/examples/zotcli.rs @@ -64,6 +64,7 @@ fn main() { (@subcommand post => (about: "Post a new message") (@arg BODY: +required "Body of the message") + (@arg TITLE: --title +takes_value "Set a title for the message") ) ) .get_matches(); @@ -101,8 +102,7 @@ fn main() { zot::xchan::fetch(&client, raw, t, m.value_of("ID").unwrap()); }, ("post", Some(m)) => { - let body = m.value_of("BODY").unwrap(); - zot::item::post(&client, body); + zot::item::post(&client, m); }, _ => { println!("{}", matches.usage()); -- cgit v1.2.3