added verboses output

master
Mathias Rothenhaeusler 2026-02-05 15:44:13 +01:00
parent 6907656cf2
commit 5151932cda
5 changed files with 14 additions and 2 deletions

2
Cargo.lock generated
View File

@ -152,7 +152,7 @@ checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b"
[[package]] [[package]]
name = "deepl" name = "deepl"
version = "1.0.4" version = "1.0.5"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap", "clap",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "deepl" name = "deepl"
version = "1.0.4" version = "1.0.5"
edition = "2024" edition = "2024"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
authors = ["Mathias Rothenhäusler <safemind@posteo.net"] authors = ["Mathias Rothenhäusler <safemind@posteo.net"]

View File

@ -13,6 +13,7 @@ Required keys URI (eg. https://api-free.deepl.com/v2/translate) and KEY (eg. XY
### OPTIONS: ### OPTIONS:
-s, --source <source_lang> The language you want to translate. Default is autodectect. -s, --source <source_lang> The language you want to translate. Default is autodectect.
-t, --target <target_lang> The language your text should be tranlated to. Default is DE. -t, --target <target_lang> The language your text should be tranlated to. Default is DE.
-v, --verbos <verbose> Verbose output
### ARGS: ### ARGS:
<INPUT> Text to translate <INPUT> Text to translate

View File

@ -20,6 +20,10 @@ pub struct Cli {
#[arg(short, long, default_value = "DE")] #[arg(short, long, default_value = "DE")]
pub target: String, pub target: String,
/// verbose output
#[arg(short, long)]
pub verbose: bool,
/// Text to translate /// Text to translate
pub input: String, pub input: String,
} }
@ -30,6 +34,7 @@ pub struct Params {
pub key: String, pub key: String,
pub uri: String, pub uri: String,
pub input: String, pub input: String,
pub verbose: bool,
} }
impl Params { impl Params {
@ -50,6 +55,7 @@ impl Params {
input: cli.input, input: cli.input,
key: env::var("KEY").context("KEY env var missing")?, key: env::var("KEY").context("KEY env var missing")?,
uri: env::var("URI").context("URI env var missing")?, uri: env::var("URI").context("URI env var missing")?,
verbose: cli.verbose
}) })
} }

View File

@ -23,6 +23,11 @@ async fn main() -> Result<()> {
let res = client.request(request).await?; let res = client.request(request).await?;
let body_bytes = body::to_bytes(res.into_body()).await?; let body_bytes = body::to_bytes(res.into_body()).await?;
let body = String::from_utf8(body_bytes.to_vec())?; let body = String::from_utf8(body_bytes.to_vec())?;
if params.verbose {
println!("{}", &body);
}
let v: DeeplResponse = let v: DeeplResponse =
serde_json::from_str(&body).context(format!("Could not parse body: {}", body))?; serde_json::from_str(&body).context(format!("Could not parse body: {}", body))?;
println!("{}", v.get_text(&params)?); println!("{}", v.get_text(&params)?);