From e95d9f86d2d9f2e689393f1e486b6250b2b075db Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 2 May 2020 13:58:09 +0200 Subject: zotcli: take item body as a file rather than string. --- examples/zot/item.rs | 8 +++++++- examples/zotcli.rs | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/zot/item.rs b/examples/zot/item.rs index 2e07561..9869492 100644 --- a/examples/zot/item.rs +++ b/examples/zot/item.rs @@ -20,7 +20,13 @@ use zotapi; pub fn post(client: &zotapi::Client, args: &ArgMatches) { let mut msg = zotapi::item(); - msg.body(args.value_of("BODY").unwrap()); + let body: String; + + if let Some(file) = dbg!(args.value_of("FILE")) { + let buf = std::fs::read(file).expect("Invalid file name"); + body = String::from_utf8(buf).expect("File contained invalid char data."); + msg.body(&body); + } if let Some(title) = dbg!(args.value_of("TITLE")) { msg.title(title); diff --git a/examples/zotcli.rs b/examples/zotcli.rs index 02f51e6..0be566f 100644 --- a/examples/zotcli.rs +++ b/examples/zotcli.rs @@ -66,7 +66,7 @@ fn main() { ) (@subcommand post => (about: "Post a new message") - (@arg BODY: +required "Body of the message") + (@arg FILE: "A text file containing the body of the message") (@arg TITLE: --title +takes_value "Set a title for the message") (@arg ATTACH: --attach [FILE] "Attach a file or image to the post") (@arg GROUP: --group [groups] "Limit distribution to the specified group(s) separated by comma") -- cgit v1.2.3