added some params

master
Mathias Rothenhaeusler 2021-09-17 16:22:50 +02:00
parent 0125dfe26c
commit 10079766f3
4 changed files with 135 additions and 1 deletions

70
Cargo.lock generated
View File

@ -2,6 +2,26 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "ansi_term"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
dependencies = [
"winapi",
]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
version = "1.0.1"
@ -32,6 +52,22 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "2.33.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
dependencies = [
"ansi_term",
"atty",
"bitflags",
"strsim",
"textwrap",
"unicode-width",
"vec_map",
"yaml-rust",
]
[[package]]
name = "core-foundation"
version = "0.9.1"
@ -52,6 +88,7 @@ checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b"
name = "deepl"
version = "0.1.0"
dependencies = [
"clap",
"hyper",
"hyper-tls",
"serde",
@ -627,6 +664,12 @@ dependencies = [
"winapi",
]
[[package]]
name = "strsim"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "syn"
version = "1.0.76"
@ -652,6 +695,15 @@ dependencies = [
"winapi",
]
[[package]]
name = "textwrap"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
dependencies = [
"unicode-width",
]
[[package]]
name = "tokio"
version = "1.11.0"
@ -739,6 +791,12 @@ version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
[[package]]
name = "unicode-width"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
[[package]]
name = "unicode-xid"
version = "0.2.2"
@ -751,6 +809,12 @@ version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "want"
version = "0.3.0"
@ -788,3 +852,9 @@ name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "yaml-rust"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e66366e18dc58b46801afbf2ca7661a9f59cc8c5962c29892b6039b4f86fa992"

View File

@ -2,6 +2,8 @@
name = "deepl"
version = "0.1.0"
edition = "2018"
license = "MIT OR Apache-2.0"
authors = ["Mathias Rothenhäusler <safemind@posteo.net"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -10,4 +12,5 @@ hyper-tls = "^0.5.0"
hyper = { version = "0.14", features = ["full"] }
tokio = { version = "1", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_json = "1.0"
clap = {version = "~2.33.0", features = ["yaml"]}

27
src/cli.yml 100644
View File

@ -0,0 +1,27 @@
name: deepl
version: "1.0"
author: Mathias Rothenhaeusler <safemind@posteo.net>
about: Cli API for deepl translations.
args:
- source:
short: s
long: source
value_name: source_lang
help: The language you want to translate.
takes_value: true
required: false
- target:
short: t
long: target
value_name: target_lang
help: The language your text should be tranlated to.
takes_value: true
required: false
- file:
short: f
long: file
desc: File you want to translate.
help: Csv delimiter character
required: false
takes_value: true

34
src/lib.rs 100644
View File

@ -0,0 +1,34 @@
pub mod deepl_helper {
use clap::ArgMatches;
pub struct Params {
source_lang: String,
destination_lang: String,
file: String,
}
impl Params {
pub fn new_from_matches(matches: ArgMatches) -> Self {
Self {
source_lang: matches.value_of("source_lang").unwrap_or("EN").to_string(),
destination_lang: matches
.value_of("destination_lang")
.unwrap_or("DE")
.to_string(),
file: matches.value_of("file").unwrap_or_default().to_string(),
}
}
pub fn source(&self) -> &String {
&self.source_lang
}
pub fn dest(&self) -> &String {
&self.destination_lang
}
pub fn file(&self) -> &String {
&self.file
}
}
}