commit bf297bd726fc9762cc49789bba2d931588b143de
parent 86ce932a204486be1d8c1188394091fe5ac0a0ac
Author: Alex Balgavy <alex@balgavy.eu>
Date: Fri, 30 Sep 2022 21:47:49 +0200
Formatting
Diffstat:
2 files changed, 27 insertions(+), 25 deletions(-)
diff --git a/src/main.rs b/src/main.rs
@@ -1,6 +1,6 @@
mod smmry;
-use ureq::{self,Error};
-use clap::{ArgGroup,Parser};
+use clap::{ArgGroup, Parser};
+use ureq::{self, Error};
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
@@ -23,28 +23,25 @@ struct Cli {
html: bool,
}
-
fn main() {
let cli = Cli::parse();
- let outfmt =
- if cli.markdown {
- smmry::OutputFmt::Markdown
- } else if cli.text {
- smmry::OutputFmt::Text
- } else if cli.html {
- smmry::OutputFmt::Html
- } else {
- unreachable!("Output format not set");
- };
+ let outfmt = if cli.markdown {
+ smmry::OutputFmt::Markdown
+ } else if cli.text {
+ smmry::OutputFmt::Text
+ } else if cli.html {
+ smmry::OutputFmt::Html
+ } else {
+ unreachable!("Output format not set");
+ };
let data = smmry::summarize(&cli.url);
match data {
Ok(resp) => smmry::show_summary(resp, outfmt),
Err(Error::Status(code, response)) => {
println!("{} {}", code, response.status_text())
- },
+ }
Err(e) => {
println!("Error: {:?}", e)
}
};
-
}
diff --git a/src/smmry.rs b/src/smmry.rs
@@ -1,18 +1,20 @@
use indoc::printdoc;
-use serde::{Deserialize};
-use std::{env,process};
+use serde::Deserialize;
+use std::{env, process};
#[derive(Deserialize)]
pub struct SmmryResponse {
sm_api_title: String,
sm_api_content: String,
- sm_api_limitation: String
+ sm_api_limitation: String,
}
-pub fn summarize(url: &str) -> Result<SmmryResponse, ureq::Error>{
+pub fn summarize(url: &str) -> Result<SmmryResponse, ureq::Error> {
let api_key: String = match env::var("SMMRY_API_KEY") {
Ok(key) => key,
_ => {
- eprintln!("Please set the environment variable SMMRY_API_KEY to your API key for smmry.com.");
+ eprintln!(
+ "Please set the environment variable SMMRY_API_KEY to your API key for smmry.com."
+ );
process::exit(1);
}
};
@@ -26,7 +28,11 @@ pub fn summarize(url: &str) -> Result<SmmryResponse, ureq::Error>{
Ok(data)
}
-pub enum OutputFmt { Text, Html, Markdown }
+pub enum OutputFmt {
+ Text,
+ Html,
+ Markdown,
+}
pub fn show_summary(summary: SmmryResponse, fmt: OutputFmt) {
match fmt {
@@ -39,7 +45,7 @@ pub fn show_summary(summary: SmmryResponse, fmt: OutputFmt) {
Smmry: {}
", summary.sm_api_title, summary.sm_api_content, summary.sm_api_limitation
};
- },
+ }
OutputFmt::Markdown => {
printdoc! {"
# {}
@@ -49,7 +55,7 @@ pub fn show_summary(summary: SmmryResponse, fmt: OutputFmt) {
_Smmry: {}_
", summary.sm_api_title, summary.sm_api_content, summary.sm_api_limitation
};
- },
+ }
OutputFmt::Html => {
printdoc! {"
<!DOCTYPE html>
@@ -63,7 +69,6 @@ pub fn show_summary(summary: SmmryResponse, fmt: OutputFmt) {
</html>
", summary.sm_api_title, summary.sm_api_title, summary.sm_api_content, summary.sm_api_limitation
};
- },
+ }
};
}
-