aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/zot/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/zot/main.rs')
-rw-r--r--src/bin/zot/main.rs56
1 files changed, 16 insertions, 40 deletions
diff --git a/src/bin/zot/main.rs b/src/bin/zot/main.rs
index a919e35..8508c13 100644
--- a/src/bin/zot/main.rs
+++ b/src/bin/zot/main.rs
@@ -15,12 +15,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-use zotapi::Stream;
-
use clap::{clap_app, crate_authors, crate_version};
use dotenv::dotenv;
use std::env;
+mod command;
+
#[tokio::main]
async fn main() -> Result<(), Box<(dyn std::error::Error + 'static)>> {
dotenv().ok();
@@ -104,52 +104,28 @@ async fn main() -> Result<(), Box<(dyn std::error::Error + 'static)>> {
Ok(match matches.subcommand() {
("verify", Some(_)) => {
- let channel = z.verify().await;
- println!("{:?}", channel);
+ let cmd = command::verify::VerifyCmd{};
+ cmd.run(z).await?;
}
("version", Some(_)) => {
- println!("{}", z.version().await?);
+ let cmd = command::version::VersionCmd{};
+ cmd.run(z).await?;
}
("channel", Some(m)) => {
match m.subcommand() {
("list", Some(_)) => {
- for ch in z.channel_list().await? {
- println!("{}", ch);
- }
+ let cmd = command::channel::list::ChannelListCmd{};
+ cmd.run(z).await?;
}
("stream", Some(_)) => {
- let json = z.channel_stream().await?;
-
- std::fs::write("channel_stream.json", &json)
- .expect("Unable to write channel_stream.json file");
-
- let s = Stream::from_json(&json)?;
- for item in s.items {
- if item.is_post() {
- let mut summary = item.title;
-
- if summary.len() == 0 {
- if item.summary.len() > 0 {
- summary = item.summary;
- } else {
- summary = item.body;
- }
- }
-
- summary.truncate(64);
-
- println!("{} | {:24} | {}",
- item.created.to_string(),
- item.author.name,
- summary);
- }
- }
- //println!("{}", z.channel_stream().await?);
+ let cmd = command::channel::stream::ChannelStreamCmd{};
+ cmd.run(z).await?;
}
("export", Some(_)) => {
- println!("{}", z.channel_export().await?);
+ let cmd = command::channel::export::ChannelExportCmd{};
+ cmd.run(z).await?;
}
_ => {
println!("Not a known subcommand for `channel`, or it's not implemented yet.");
@@ -157,14 +133,14 @@ async fn main() -> Result<(), Box<(dyn std::error::Error + 'static)>> {
}
}
}
- ("abook", Some(m)) => {
+ ("contact", Some(m)) => {
match m.subcommand() {
("list", Some(_)) => {
- let r = z.abook_list().await?;
- println!("{}", r);
+ let cmd = command::contact::list::ContactListCmd{};
+ cmd.run(z).await?;
}
_ => {
- println!("Not a known subcommand for `abook`, or it's not implemented yet.");
+ println!("Not a known subcommand for `contact`, or it's not implemented yet.");
println!("{}", m.usage());
}
}