From 327d900642d2dae6eb55aeb06f5fdd8cc8d2ea15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Mon, 8 Aug 2022 16:01:19 +0200 Subject: [PATCH 01/11] wip(lib/cli): Docker integration --- src/bin.rs | 8 ++++ src/lib/docker.rs | 117 ++++++++++++++++++++++++++++++++++++++++++++++ src/lib/error.rs | 5 ++ src/lib/lib.rs | 2 + 4 files changed, 132 insertions(+) create mode 100644 src/lib/docker.rs diff --git a/src/bin.rs b/src/bin.rs index 07b74bb..1ba61f9 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -44,6 +44,11 @@ async fn try_main() -> Result<()> { .author(clap::crate_authors!()) .about("Ping the LanguageTool server and return time elapsed in ms if success"), ) + .subcommand( + Docker::command() + .name("docker") + .author(clap::crate_authors!()), + ) .get_matches(); // TODO: prompt max_suggestion @@ -127,6 +132,9 @@ async fn try_main() -> Result<()> { Some(("ping", _sub_matches)) => { writeln!(&stdout, "PONG! Delay: {} ms", client.ping().await?)? } + Some(("docker", sub_matches)) => Docker::from_arg_matches(sub_matches)? + .run_action() + .map(|_| ())?, _ => unreachable!(), // Can't be None since subcommand is required } diff --git a/src/lib/docker.rs b/src/lib/docker.rs new file mode 100644 index 0000000..86a2210 --- /dev/null +++ b/src/lib/docker.rs @@ -0,0 +1,117 @@ +use crate::error::{Error, Result}; +use clap::Parser; +use std::process::{Command, Output, Stdio}; + +trait CommandOk { + fn command_ok(&mut self) -> Result; +} + +impl CommandOk for Command { + #[inline] + fn command_ok(&mut self) -> Result { + let output = self.output()?; + let status = output.status; + + if status.success() { + Ok(output) + } else { + match status.code() { + Some(code) => Err(Error::CommandFailed { + body: format!("Process terminated with exit code: {}", code), + }), + None => Err(Error::CommandFailed { + body: "Process terminated by signal".to_string(), + }), + } + } + } +} + +#[cfg_attr(feature = "cli", derive(Parser))] +/// Commands to pull, start and stop a LanguageTool using Docker. +pub struct Docker { + #[cfg_attr(feature = "cli", clap(default_value = "erikvl87/languagetool"))] + /// Image or repository from a registry. + name: String, + #[cfg_attr(feature = "cli", clap(short = 'b', long, default_value = "docker"))] + /// Path to Docker's binaries. + bin: String, + #[cfg_attr(feature = "cli", clap(long, default_value = "languagetool"))] + /// Name assigned to the container. + container_name: String, + #[cfg_attr(feature = "cli", clap(short = 'p', long, default_value = "8010:8010"))] + /// Publish a container's port(s) to the host. + port: String, + #[clap(subcommand)] + /// Docker action. + action: Action, +} + +#[derive(clap::Subcommand)] +enum Action { + /// Pull a docker docker image. + /// + /// Alias to `{docker.bin} pull {docker.name}`. + Pull, + /// Start a (detached) docker container. + /// + /// Alias to `{docker.bin} run --rm -d -p {docker.port} {docker.name}` + Start, + /// Stop a docker container. + /// + /// Alias to `{docker.bin} kill $({docker.bin} ps -l -f "name={docker.container_name}")`. + Stop, +} + +impl Docker { + pub fn pull(&self) -> Result { + Command::new(&self.bin) + .args(["pull", &self.name]) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .command_ok() + } + + pub fn start(&self) -> Result { + Command::new(&self.bin) + .args([ + "run", + "--rm", + "--name", + &self.container_name, + "-d", + "-p", + "8010:8010", + &self.name, + ]) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .command_ok() + } + + pub fn stop(&self) -> Result { + let output = Command::new(&self.bin) + .args(["ps", "-l", "-f", &format!("name={}", self.container_name), "-q"]) + .stderr(Stdio::inherit()) + .command_ok()?; + + let docker_id: String = String::from_utf8_lossy(&output.stdout) + .chars() + .filter(|c| c.is_alphanumeric()) // This avoids newlines + .collect(); + + Command::new(&self.bin) + .args(["kill", &docker_id]) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .command_ok() + } + + pub fn run_action(&self) -> Result { + match self.action { + Action::Pull => self.pull(), + Action::Start => self.start(), + Action::Stop => self.stop(), + } + } +} diff --git a/src/lib/error.rs b/src/lib/error.rs index 8fe2696..9f4f431 100644 --- a/src/lib/error.rs +++ b/src/lib/error.rs @@ -7,6 +7,11 @@ pub enum Error { #[error(transparent)] /// Error from the command line parsing (see [clap::Error]) Cli(#[from] clap::Error), + #[error("command failed: {body:?}")] + CommandFailed { + /// Error body + body: String, + }, #[error(transparent)] /// Error from parsing JSON (see [serde_json::Error]) JSON(#[from] serde_json::Error), diff --git a/src/lib/lib.rs b/src/lib/lib.rs index edc256a..85efc55 100644 --- a/src/lib/lib.rs +++ b/src/lib/lib.rs @@ -15,12 +15,14 @@ //! that cannot be controlled and (possible) breaking changes are to be expected. pub mod check; +pub mod docker; pub mod error; pub mod languages; pub mod server; pub mod words; pub use crate::check::{CheckRequest, CheckResponse}; +pub use crate::docker::Docker; pub use crate::languages::LanguagesResponse; pub use crate::server::ServerClient; pub use crate::words::{ From f6e8468cacff8352cc0c2964ba9ebf407fa8f292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Mon, 8 Aug 2022 16:01:19 +0200 Subject: [PATCH 02/11] wip(lib/cli): Docker integration --- src/bin.rs | 8 ++++ src/lib/docker.rs | 117 ++++++++++++++++++++++++++++++++++++++++++++++ src/lib/error.rs | 5 ++ src/lib/lib.rs | 2 + 4 files changed, 132 insertions(+) create mode 100644 src/lib/docker.rs diff --git a/src/bin.rs b/src/bin.rs index 07b74bb..1ba61f9 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -44,6 +44,11 @@ async fn try_main() -> Result<()> { .author(clap::crate_authors!()) .about("Ping the LanguageTool server and return time elapsed in ms if success"), ) + .subcommand( + Docker::command() + .name("docker") + .author(clap::crate_authors!()), + ) .get_matches(); // TODO: prompt max_suggestion @@ -127,6 +132,9 @@ async fn try_main() -> Result<()> { Some(("ping", _sub_matches)) => { writeln!(&stdout, "PONG! Delay: {} ms", client.ping().await?)? } + Some(("docker", sub_matches)) => Docker::from_arg_matches(sub_matches)? + .run_action() + .map(|_| ())?, _ => unreachable!(), // Can't be None since subcommand is required } diff --git a/src/lib/docker.rs b/src/lib/docker.rs new file mode 100644 index 0000000..86a2210 --- /dev/null +++ b/src/lib/docker.rs @@ -0,0 +1,117 @@ +use crate::error::{Error, Result}; +use clap::Parser; +use std::process::{Command, Output, Stdio}; + +trait CommandOk { + fn command_ok(&mut self) -> Result; +} + +impl CommandOk for Command { + #[inline] + fn command_ok(&mut self) -> Result { + let output = self.output()?; + let status = output.status; + + if status.success() { + Ok(output) + } else { + match status.code() { + Some(code) => Err(Error::CommandFailed { + body: format!("Process terminated with exit code: {}", code), + }), + None => Err(Error::CommandFailed { + body: "Process terminated by signal".to_string(), + }), + } + } + } +} + +#[cfg_attr(feature = "cli", derive(Parser))] +/// Commands to pull, start and stop a LanguageTool using Docker. +pub struct Docker { + #[cfg_attr(feature = "cli", clap(default_value = "erikvl87/languagetool"))] + /// Image or repository from a registry. + name: String, + #[cfg_attr(feature = "cli", clap(short = 'b', long, default_value = "docker"))] + /// Path to Docker's binaries. + bin: String, + #[cfg_attr(feature = "cli", clap(long, default_value = "languagetool"))] + /// Name assigned to the container. + container_name: String, + #[cfg_attr(feature = "cli", clap(short = 'p', long, default_value = "8010:8010"))] + /// Publish a container's port(s) to the host. + port: String, + #[clap(subcommand)] + /// Docker action. + action: Action, +} + +#[derive(clap::Subcommand)] +enum Action { + /// Pull a docker docker image. + /// + /// Alias to `{docker.bin} pull {docker.name}`. + Pull, + /// Start a (detached) docker container. + /// + /// Alias to `{docker.bin} run --rm -d -p {docker.port} {docker.name}` + Start, + /// Stop a docker container. + /// + /// Alias to `{docker.bin} kill $({docker.bin} ps -l -f "name={docker.container_name}")`. + Stop, +} + +impl Docker { + pub fn pull(&self) -> Result { + Command::new(&self.bin) + .args(["pull", &self.name]) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .command_ok() + } + + pub fn start(&self) -> Result { + Command::new(&self.bin) + .args([ + "run", + "--rm", + "--name", + &self.container_name, + "-d", + "-p", + "8010:8010", + &self.name, + ]) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .command_ok() + } + + pub fn stop(&self) -> Result { + let output = Command::new(&self.bin) + .args(["ps", "-l", "-f", &format!("name={}", self.container_name), "-q"]) + .stderr(Stdio::inherit()) + .command_ok()?; + + let docker_id: String = String::from_utf8_lossy(&output.stdout) + .chars() + .filter(|c| c.is_alphanumeric()) // This avoids newlines + .collect(); + + Command::new(&self.bin) + .args(["kill", &docker_id]) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .command_ok() + } + + pub fn run_action(&self) -> Result { + match self.action { + Action::Pull => self.pull(), + Action::Start => self.start(), + Action::Stop => self.stop(), + } + } +} diff --git a/src/lib/error.rs b/src/lib/error.rs index 8fe2696..9f4f431 100644 --- a/src/lib/error.rs +++ b/src/lib/error.rs @@ -7,6 +7,11 @@ pub enum Error { #[error(transparent)] /// Error from the command line parsing (see [clap::Error]) Cli(#[from] clap::Error), + #[error("command failed: {body:?}")] + CommandFailed { + /// Error body + body: String, + }, #[error(transparent)] /// Error from parsing JSON (see [serde_json::Error]) JSON(#[from] serde_json::Error), diff --git a/src/lib/lib.rs b/src/lib/lib.rs index edc256a..85efc55 100644 --- a/src/lib/lib.rs +++ b/src/lib/lib.rs @@ -15,12 +15,14 @@ //! that cannot be controlled and (possible) breaking changes are to be expected. pub mod check; +pub mod docker; pub mod error; pub mod languages; pub mod server; pub mod words; pub use crate::check::{CheckRequest, CheckResponse}; +pub use crate::docker::Docker; pub use crate::languages::LanguagesResponse; pub use crate::server::ServerClient; pub use crate::words::{ From 92f60fc1c51be528d557537fb147c542c4d1411c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Thu, 11 Aug 2022 10:11:16 +0200 Subject: [PATCH 03/11] wip(cli/bin): docker commands --- Cargo.lock | 2 +- Cargo.toml | 1 + src/lib/docker.rs | 26 ++++++++++++++++++++++++-- src/lib/error.rs | 19 ++++++++++++++++++- src/lib/lib.rs | 2 ++ 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ea1e3df..3637314 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -580,7 +580,7 @@ dependencies = [ [[package]] name = "languagetool-rust" -version = "1.1.0" +version = "1.1.1" dependencies = [ "annotate-snippets", "clap 3.2.12", diff --git a/Cargo.toml b/Cargo.toml index c34205d..0aa9e2b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ tokio = { version = "^1.0", features = ["macros"]} [features] annotate = ["annotate-snippets"] cli = ["clap", "tokio"] +docker = [] unstable = [] default = ["cli"] diff --git a/src/lib/docker.rs b/src/lib/docker.rs index 86a2210..e0b5abe 100644 --- a/src/lib/docker.rs +++ b/src/lib/docker.rs @@ -1,6 +1,22 @@ use crate::error::{Error, Result}; use clap::Parser; -use std::process::{Command, Output, Stdio}; +use std::process::{Command, ExitStatus, Output, Stdio}; + +impl From for Result<()> { + fn from(exit_status: ExitStatus) -> Self { + match exit_status.succes() { + true => Ok(()), + false => match exit_status.code() { + Some(code) => Err(Error::CommandFailed { + body: format!("Process terminated with exit code: {}", code), + }), + None => Err(Error::CommandFailed { + body: "Process terminated by signal".to_string(), + }), + }, + } + } +} trait CommandOk { fn command_ok(&mut self) -> Result; @@ -91,7 +107,13 @@ impl Docker { pub fn stop(&self) -> Result { let output = Command::new(&self.bin) - .args(["ps", "-l", "-f", &format!("name={}", self.container_name), "-q"]) + .args([ + "ps", + "-l", + "-f", + &format!("name={}", self.container_name), + "-q", + ]) .stderr(Stdio::inherit()) .command_ok()?; diff --git a/src/lib/error.rs b/src/lib/error.rs index 9f4f431..d499d16 100644 --- a/src/lib/error.rs +++ b/src/lib/error.rs @@ -1,4 +1,5 @@ //! Error and Result structure used all across this crate. +use std::process::ExitStatus; /// Enumeration of all possible error types. #[derive(Debug, thiserror::Error)] @@ -8,7 +9,7 @@ pub enum Error { /// Error from the command line parsing (see [clap::Error]) Cli(#[from] clap::Error), #[error("command failed: {body:?}")] - CommandFailed { + ExitStatusError { /// Error body body: String, }, @@ -53,6 +54,22 @@ pub enum Error { /// Result type alias with error type defined above (see [Error]). pub type Result = std::result::Result; +impl From for Result<(), Error::ExitStatusError> { + fn from(exit_status: ExitStatus) -> Self { + match exit_status.success() { + true => Ok(()), + false => match exit_status.code() { + Some(code) => Err(Error::ExitStatusError { + body: format!("Process terminated with exit code: {}", code), + }), + None => Err(Error::ExitStatusError { + body: "Process terminated by signal".to_string(), + }), + }, + } + } +} + #[cfg(test)] mod tests { diff --git a/src/lib/lib.rs b/src/lib/lib.rs index 85efc55..fe5906d 100644 --- a/src/lib/lib.rs +++ b/src/lib/lib.rs @@ -15,6 +15,7 @@ //! that cannot be controlled and (possible) breaking changes are to be expected. pub mod check; +#[cfg(feature = "docker")] pub mod docker; pub mod error; pub mod languages; @@ -22,6 +23,7 @@ pub mod server; pub mod words; pub use crate::check::{CheckRequest, CheckResponse}; +#[cfg(feature = "docker")] pub use crate::docker::Docker; pub use crate::languages::LanguagesResponse; pub use crate::server::ServerClient; From 1a82288abf3fc68369c1c9f6bee2ec45de7c9b93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Thu, 11 Aug 2022 15:53:52 +0200 Subject: [PATCH 04/11] fix(docker): fixing compilation issues and docs --- src/bin.rs | 20 ++++++----- src/lib/docker.rs | 85 ++++++++++++++++++----------------------------- src/lib/error.rs | 53 +++++++++++++++-------------- 3 files changed, 71 insertions(+), 87 deletions(-) diff --git a/src/bin.rs b/src/bin.rs index 1ba61f9..d5f8d1e 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -12,7 +12,7 @@ async fn main() { } async fn try_main() -> Result<()> { - let matches = ServerClient::command() + let command = ServerClient::command() .author(clap::crate_authors!()) .about(clap::crate_description!()) .name(clap::crate_name!()) @@ -43,13 +43,16 @@ async fn try_main() -> Result<()> { clap::Command::new("ping") .author(clap::crate_authors!()) .about("Ping the LanguageTool server and return time elapsed in ms if success"), - ) - .subcommand( - Docker::command() - .name("docker") - .author(clap::crate_authors!()), - ) - .get_matches(); + ); + + #[cfg(feature = "docker")] + let command = command.subcommand( + Docker::command() + .name("docker") + .author(clap::crate_authors!()), + ); + + let matches = command.get_matches(); // TODO: prompt max_suggestion let client = ServerClient::from_arg_matches(&matches)?.with_max_suggestions(5); @@ -132,6 +135,7 @@ async fn try_main() -> Result<()> { Some(("ping", _sub_matches)) => { writeln!(&stdout, "PONG! Delay: {} ms", client.ping().await?)? } + #[cfg(feature = "docker")] Some(("docker", sub_matches)) => Docker::from_arg_matches(sub_matches)? .run_action() .map(|_| ())?, diff --git a/src/lib/docker.rs b/src/lib/docker.rs index e0b5abe..bf3c38a 100644 --- a/src/lib/docker.rs +++ b/src/lib/docker.rs @@ -1,49 +1,12 @@ -use crate::error::{Error, Result}; -use clap::Parser; -use std::process::{Command, ExitStatus, Output, Stdio}; - -impl From for Result<()> { - fn from(exit_status: ExitStatus) -> Self { - match exit_status.succes() { - true => Ok(()), - false => match exit_status.code() { - Some(code) => Err(Error::CommandFailed { - body: format!("Process terminated with exit code: {}", code), - }), - None => Err(Error::CommandFailed { - body: "Process terminated by signal".to_string(), - }), - }, - } - } -} - -trait CommandOk { - fn command_ok(&mut self) -> Result; -} +//! Structures and methods to easily manipulate Docker images, especially for LanguageTool +//! applications. -impl CommandOk for Command { - #[inline] - fn command_ok(&mut self) -> Result { - let output = self.output()?; - let status = output.status; - - if status.success() { - Ok(output) - } else { - match status.code() { - Some(code) => Err(Error::CommandFailed { - body: format!("Process terminated with exit code: {}", code), - }), - None => Err(Error::CommandFailed { - body: "Process terminated by signal".to_string(), - }), - } - } - } -} +use crate::error::{exit_status_error, Result}; +use clap::Parser; +use std::process::{Command, Output, Stdio}; #[cfg_attr(feature = "cli", derive(Parser))] +#[derive(Debug, Clone)] /// Commands to pull, start and stop a LanguageTool using Docker. pub struct Docker { #[cfg_attr(feature = "cli", clap(default_value = "erikvl87/languagetool"))] @@ -63,7 +26,8 @@ pub struct Docker { action: Action, } -#[derive(clap::Subcommand)] +#[cfg_attr(feature = "cli", derive(clap::Subcommand))] +#[derive(Clone, Debug)] enum Action { /// Pull a docker docker image. /// @@ -80,16 +44,22 @@ enum Action { } impl Docker { + /// Pull a Docker image from the given repository/file/... pub fn pull(&self) -> Result { - Command::new(&self.bin) + let output = Command::new(&self.bin) .args(["pull", &self.name]) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) - .command_ok() + .output()?; + + exit_status_error(&output.status)?; + + Ok(output) } + /// Start a Docker container with given specifications. pub fn start(&self) -> Result { - Command::new(&self.bin) + let output = Command::new(&self.bin) .args([ "run", "--rm", @@ -102,9 +72,13 @@ impl Docker { ]) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) - .command_ok() - } + .output()?; + + exit_status_error(&output.status)?; + Ok(output) } + + /// Stop the latest Docker container with the given name. pub fn stop(&self) -> Result { let output = Command::new(&self.bin) .args([ @@ -115,20 +89,27 @@ impl Docker { "-q", ]) .stderr(Stdio::inherit()) - .command_ok()?; + .output()?; + + exit_status_error(&output.status)?; let docker_id: String = String::from_utf8_lossy(&output.stdout) .chars() .filter(|c| c.is_alphanumeric()) // This avoids newlines .collect(); - Command::new(&self.bin) + let output = Command::new(&self.bin) .args(["kill", &docker_id]) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) - .command_ok() + .output()?; + + exit_status_error(&output.status)?; + + Ok(output) } + /// Run a Docker command according to self.action. pub fn run_action(&self) -> Result { match self.action { Action::Pull => self.pull(), diff --git a/src/lib/error.rs b/src/lib/error.rs index d499d16..c27a86a 100644 --- a/src/lib/error.rs +++ b/src/lib/error.rs @@ -6,67 +6,66 @@ use std::process::ExitStatus; pub enum Error { #[cfg(feature = "cli")] #[error(transparent)] - /// Error from the command line parsing (see [clap::Error]) + /// Error from the command line parsing (see [clap::Error]). Cli(#[from] clap::Error), #[error("command failed: {body:?}")] + /// Error from a command line process (see [std::process:Command]). ExitStatusError { - /// Error body + /// Error body. body: String, }, #[error(transparent)] - /// Error from parsing JSON (see [serde_json::Error]) + /// Error from parsing JSON (see [serde_json::Error]). JSON(#[from] serde_json::Error), #[error(transparent)] - /// Error from reading and writing to IO (see [std::io::Error]) + /// Error from reading and writing to IO (see [std::io::Error]). IO(#[from] std::io::Error), #[error("invalid request: {body:?}")] - /// Error specifying an invalid request + /// Error specifying an invalid request. InvalidRequest { - /// Error body + /// Error body. body: String, }, #[error("invalid value: {body:?}")] - /// Error specifying an invalid value + /// Error specifying an invalid value. InvalidValue { - /// Error body + /// Error body. body: String, }, #[error("request could not be properly encoded: {source}")] - /// Error from request encoding + /// Error from request encoding. RequestEncode { - /// Source error + /// Source error. source: reqwest::Error, }, #[error("response could not be properly decoded: {source}")] - /// Error from request decoding + /// Error from request decoding. ResponseDecode { - /// Source error + /// Source error. source: reqwest::Error, }, #[error(transparent)] - /// Any other error from requests (see [reqwest::Error]) + /// Any other error from requests (see [reqwest::Error]). Reqwest(#[from] reqwest::Error), #[error(transparent)] - /// Error from reading environ variable (see [std::env::VarError]) + /// Error from reading environ variable (see [std::env::VarError]). VarError(#[from] std::env::VarError), } /// Result type alias with error type defined above (see [Error]). pub type Result = std::result::Result; -impl From for Result<(), Error::ExitStatusError> { - fn from(exit_status: ExitStatus) -> Self { - match exit_status.success() { - true => Ok(()), - false => match exit_status.code() { - Some(code) => Err(Error::ExitStatusError { - body: format!("Process terminated with exit code: {}", code), - }), - None => Err(Error::ExitStatusError { - body: "Process terminated by signal".to_string(), - }), - }, - } +pub(crate) fn exit_status_error(exit_status: &ExitStatus) -> Result<()> { + match exit_status.success() { + true => Ok(()), + false => match exit_status.code() { + Some(code) => Err(Error::ExitStatusError { + body: format!("Process terminated with exit code: {}", code), + }), + None => Err(Error::ExitStatusError { + body: "Process terminated by signal".to_string(), + }), + }, } } From 6cec2cff5255997d0654ea317d4f82e2224ee1ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Thu, 11 Aug 2022 17:16:51 +0200 Subject: [PATCH 05/11] wip(docker): some more code --- src/lib/docker.rs | 31 ++++++++++++++++++++++++++++--- src/lib/error.rs | 12 +++++++++--- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/lib/docker.rs b/src/lib/docker.rs index bf3c38a..9bcd816 100644 --- a/src/lib/docker.rs +++ b/src/lib/docker.rs @@ -1,7 +1,7 @@ //! Structures and methods to easily manipulate Docker images, especially for LanguageTool //! applications. -use crate::error::{exit_status_error, Result}; +use crate::error::{exit_status_error, Error, Result}; use clap::Parser; use std::process::{Command, Output, Stdio}; @@ -28,6 +28,7 @@ pub struct Docker { #[cfg_attr(feature = "cli", derive(clap::Subcommand))] #[derive(Clone, Debug)] +/// Enumerate supported Docker actions. enum Action { /// Pull a docker docker image. /// @@ -43,7 +44,30 @@ enum Action { Stop, } +impl FromStr for Action { + type Err = Error; + + fn from_str(s: &str) -> Result { + match s.lowercase().trim_matches(' ') { + "pull" => Ok(Action::Pull), + "start" => Ok(Action::Start), + "stop" => Ok(Action::Stop), + _ => Err(Error::ParseAction { s: s.to_string() }), + } + } +} + impl Docker { + fn from_env() -> Result { + let name = std::env::var("LANGUAGETOOL_DOCKER_NAME")?; + let bin = std::env::var("LANGUAGETOOL_DOCKER_IMAGE")?; + let name = std::env::var("LANGUAGETOOL_DOCKER_IMAGE")?; + let port = std::env::var("LANGUAGETOOL_DOCKER_PORT")?; + let name = std::env::var("LANGUAGETOOL_DOCKER_ACTION")?; + + Ok(Self { hostname, port }) + } + /// Pull a Docker image from the given repository/file/... pub fn pull(&self) -> Result { let output = Command::new(&self.bin) @@ -76,7 +100,8 @@ impl Docker { exit_status_error(&output.status)?; - Ok(output) } + Ok(output) + } /// Stop the latest Docker container with the given name. pub fn stop(&self) -> Result { @@ -106,7 +131,7 @@ impl Docker { exit_status_error(&output.status)?; - Ok(output) + Ok(output) } /// Run a Docker command according to self.action. diff --git a/src/lib/error.rs b/src/lib/error.rs index c27a86a..72ebc43 100644 --- a/src/lib/error.rs +++ b/src/lib/error.rs @@ -10,7 +10,7 @@ pub enum Error { Cli(#[from] clap::Error), #[error("command failed: {body:?}")] /// Error from a command line process (see [std::process:Command]). - ExitStatusError { + ExitStatus { /// Error body. body: String, }, @@ -32,6 +32,12 @@ pub enum Error { /// Error body. body: String, }, + #[error("could not parse `{s:?}` in a Docker action")] + /// Error while parsing Action. + ParseAction { + /// String that could not be parsed. + s: String, + }, #[error("request could not be properly encoded: {source}")] /// Error from request encoding. RequestEncode { @@ -59,10 +65,10 @@ pub(crate) fn exit_status_error(exit_status: &ExitStatus) -> Result<()> { match exit_status.success() { true => Ok(()), false => match exit_status.code() { - Some(code) => Err(Error::ExitStatusError { + Some(code) => Err(Error::ExitStatus { body: format!("Process terminated with exit code: {}", code), }), - None => Err(Error::ExitStatusError { + None => Err(Error::ExitStatus { body: "Process terminated by signal".to_string(), }), }, From 4833cb2417a55e23a600acb750aa6ef56544d5df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Fri, 26 Aug 2022 14:07:08 +0200 Subject: [PATCH 06/11] feat(docker): new Docker features, and some fixes --- .github/workflows/CI.yml | 2 +- CHANGELOG.md | 14 +++ Cargo.lock | 201 ++++++++++++++++++++------------------- Cargo.toml | 2 +- README.md | 15 +++ src/lib/docker.rs | 35 ++----- src/lib/server.rs | 2 +- 7 files changed, 140 insertions(+), 131 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 6c19c63..29bf54b 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -24,7 +24,7 @@ jobs: toolchain: stable override: true - - run: cargo publish --features cli --token ${CRATES_TOKEN} + - run: cargo publish --features full --token ${CRATES_TOKEN} env: CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }} check-publish: diff --git a/CHANGELOG.md b/CHANGELOG.md index 46b88f5..8c6e721 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.3.0](https://github.com/jeertmans/languagetool-rust/compare/v1.2.0...v1.3.0) + +### Chore + +- Fixed features flag in `CI.yml` action. [#12](https://github.com/jeertmans/languagetool-rust/pull/12) + +### Added + +- Added basic Docker support. [#12](https://github.com/jeertmans/languagetool-rust/pull/12) + +### Fixed + +- Fixed typo in message when no error was found. [#12](https://github.com/jeertmans/languagetool-rust/pull/12) + ## [1.2.0](https://github.com/jeertmans/languagetool-rust/compare/v1.1.1...v1.2.0) ### Chore diff --git a/Cargo.lock b/Cargo.lock index 86ff07e..c447af4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -54,15 +54,15 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.10.0" +version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" +checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" [[package]] name = "bytes" -version = "1.1.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" +checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" [[package]] name = "cast" @@ -95,9 +95,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.12" +version = "3.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab8b79fe3946ceb4a0b1c080b4018992b8d27e9ff363644c1c9b6387c854614d" +checksum = "29e724a68d9319343bb3328c9cc2dfde263f4b3142ee1059a9980580171c954b" dependencies = [ "atty", "bitflags", @@ -112,9 +112,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "3.2.7" +version = "3.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "759bf187376e1afa7b85b959e6a664a3e7a95203415dba952ad19139e798f902" +checksum = "13547f7012c01ab4a0e8f8967730ada8f9fdf419e8b6c792788f39cf4e46eefa" dependencies = [ "heck", "proc-macro-error", @@ -253,9 +253,9 @@ dependencies = [ [[package]] name = "either" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" [[package]] name = "encoding_rs" @@ -268,9 +268,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" +checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" dependencies = [ "instant", ] @@ -308,9 +308,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.21" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f73fe65f54d1e12b726f517d3e2135ca3125a437b6d998caf1962961f7172d9e" +checksum = "ab30e97ab6aacfe635fad58f22c2bb06c8b685f7421eb1e064a729e2a5f481fa" dependencies = [ "futures-channel", "futures-core", @@ -323,9 +323,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.21" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" +checksum = "2bfc52cbddcfd745bf1740338492bb0bd83d76c67b445f91c5fb29fae29ecaa1" dependencies = [ "futures-core", "futures-sink", @@ -333,15 +333,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.21" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" +checksum = "d2acedae88d38235936c3922476b10fced7b2b68136f5e3c03c2d5be348a1115" [[package]] name = "futures-executor" -version = "0.3.21" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6" +checksum = "1d11aa21b5b587a64682c0094c2bdd4df0076c5324961a40cc3abd7f37930528" dependencies = [ "futures-core", "futures-task", @@ -350,15 +350,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.21" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" +checksum = "93a66fc6d035a26a3ae255a6d2bca35eda63ae4c5512bef54449113f7a1228e5" [[package]] name = "futures-macro" -version = "0.3.21" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512" +checksum = "0db9cce532b0eae2ccf2766ab246f114b56b9cf6d445e00c2549fbc100ca045d" dependencies = [ "proc-macro2", "quote", @@ -367,21 +367,21 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.21" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" +checksum = "ca0bae1fe9752cf7fd9b0064c674ae63f97b37bc714d745cbde0afb7ec4e6765" [[package]] name = "futures-task" -version = "0.3.21" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" +checksum = "842fc63b931f4056a24d59de13fb1272134ce261816e063e634ad0c15cdc5306" [[package]] name = "futures-util" -version = "0.3.21" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" +checksum = "f0828a5471e340229c11c77ca80017937ce3c58cb788a17e5f1c2d5c485a9577" dependencies = [ "futures-channel", "futures-core", @@ -397,9 +397,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" +checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be" dependencies = [ "bytes", "fnv", @@ -449,7 +449,7 @@ checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" dependencies = [ "bytes", "fnv", - "itoa 1.0.2", + "itoa 1.0.3", ] [[package]] @@ -490,7 +490,7 @@ dependencies = [ "http-body", "httparse", "httpdate", - "itoa 1.0.2", + "itoa 1.0.3", "pin-project-lite", "socket2", "tokio", @@ -565,25 +565,25 @@ checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" [[package]] name = "itoa" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" +checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" [[package]] name = "js-sys" -version = "0.3.58" +version = "0.3.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3fac17f7123a73ca62df411b1bf727ccc805daa070338fda671c86dac1bdc27" +checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" dependencies = [ "wasm-bindgen", ] [[package]] name = "languagetool-rust" -version = "1.1.1" +version = "1.3.0" dependencies = [ "annotate-snippets", - "clap 3.2.12", + "clap 3.2.17", "criterion", "futures", "reqwest", @@ -601,9 +601,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" [[package]] name = "log" @@ -692,9 +692,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e" [[package]] name = "oorandom" @@ -759,9 +759,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.2.0" +version = "6.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4" +checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" [[package]] name = "percent-encoding" @@ -789,9 +789,9 @@ checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" [[package]] name = "plotters" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9428003b84df1496fb9d6eeee9c5f8145cb41ca375eb0dad204328888832811f" +checksum = "716b4eeb6c4a1d3ecc956f75b43ec2e8e8ba80026413e70a3f41fd3313d3492b" dependencies = [ "num-traits", "plotters-backend", @@ -808,9 +808,9 @@ checksum = "193228616381fecdc1224c62e96946dfbc73ff4384fba576e052ff8c1bea8142" [[package]] name = "plotters-svg" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0918736323d1baff32ee0eade54984f6f201ad7e97d5cfb5d6ab4a358529615" +checksum = "f9a81d2759aae1dae668f783c308bc5c8ebd191ff4184aaa1b37f65a6ae5a56f" dependencies = [ "plotters-backend", ] @@ -841,18 +841,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.40" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" +checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ "proc-macro2", ] @@ -883,9 +883,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.13" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ "bitflags", ] @@ -959,9 +959,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" [[package]] name = "same-file" @@ -990,9 +990,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "security-framework" -version = "2.6.1" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" +checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" dependencies = [ "bitflags", "core-foundation", @@ -1013,9 +1013,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.139" +version = "1.0.144" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0171ebb889e45aa68b44aee0859b3eede84c6f5f5c228e6f140c0b2a0a46cad6" +checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" dependencies = [ "serde_derive", ] @@ -1032,9 +1032,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.139" +version = "1.0.144" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc1d3230c1de7932af58ad8ffbe1d784bd55efd5a9d84ac24f69c72d83543dfb" +checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00" dependencies = [ "proc-macro2", "quote", @@ -1043,11 +1043,11 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.82" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7" +checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" dependencies = [ - "itoa 1.0.2", + "itoa 1.0.3", "ryu", "serde", ] @@ -1059,16 +1059,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" dependencies = [ "form_urlencoded", - "itoa 1.0.2", + "itoa 1.0.3", "ryu", "serde", ] [[package]] name = "slab" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" +checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +dependencies = [ + "autocfg", +] [[package]] name = "socket2" @@ -1088,9 +1091,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.98" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" +checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" dependencies = [ "proc-macro2", "quote", @@ -1137,18 +1140,18 @@ checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" [[package]] name = "thiserror" -version = "1.0.31" +version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" +checksum = "f5f6586b7f764adc0231f4c79be7b920e766bb2f3e51b3661cdb263828f19994" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.31" +version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" +checksum = "12bafc5b54507e0149cdf1b145a5d80ab80a90bcd9275df43d4fff68460f6c21" dependencies = [ "proc-macro2", "quote", @@ -1182,9 +1185,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.20.0" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57aec3cfa4c296db7255446efb4928a6be304b431a806216105542a67b6ca82e" +checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581" dependencies = [ "autocfg", "bytes", @@ -1242,9 +1245,9 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.35" +version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160" +checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" dependencies = [ "cfg-if", "pin-project-lite", @@ -1253,9 +1256,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.28" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b7358be39f2f274f322d2aaed611acc57f382e8eb1e5b48cb9ae30933495ce7" +checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" dependencies = [ "once_cell", ] @@ -1274,9 +1277,9 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-ident" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" +checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" [[package]] name = "unicode-normalization" @@ -1346,9 +1349,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.81" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994" +checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -1356,13 +1359,13 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.81" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a" +checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" dependencies = [ "bumpalo", - "lazy_static", "log", + "once_cell", "proc-macro2", "quote", "syn", @@ -1371,9 +1374,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.31" +version = "0.4.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de9a9cec1733468a8c657e57fa2413d2ae2c0129b95e87c5b72b8ace4d13f31f" +checksum = "fa76fb221a1f8acddf5b54ace85912606980ad661ac7a503b4570ffd3a624dad" dependencies = [ "cfg-if", "js-sys", @@ -1383,9 +1386,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.81" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa" +checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1393,9 +1396,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.81" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048" +checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" dependencies = [ "proc-macro2", "quote", @@ -1406,15 +1409,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.81" +version = "0.2.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be" +checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" [[package]] name = "web-sys" -version = "0.3.58" +version = "0.3.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fed94beee57daf8dd7d51f2b15dc2bcde92d7a72304cdf662a4371008b71b90" +checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index 4087b8f..40ad9ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "languagetool-rust" -version = "1.2.0" +version = "1.3.0" authors = ["Jérome Eertmans "] edition = "2021" description = "LanguageTool API bindings in Rust." diff --git a/README.md b/README.md index b5788e8..fac3495 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ 1. [About](#about) 2. [CLI Reference](#cli-reference) + - [Docker](#docker) 3. [API Reference](#api-reference) - [Feature Flags](#feature-flags) 4. [CHANGELOG](CHANGELOG.md) @@ -95,6 +96,20 @@ PONG! Delay: 110 ms > ltrs --help # for more details ``` +### Docker + +Since LanguageTool's installation might not be straighforward, we provide a basic Docker integration that allows to `pull`, `start`, and `stop` LanguageTool Docker containers in a few lines: + +```bash +ltrs docker pull # only once +ltrs docker start # start the LT server +ltrs --hostname http://localhost -p 8010 check -t "Some tex" +# Other commands... +ltrs docker stop # stop the LT server +``` + +> *Note:* Docker is a tool that facilitates running applications without worrying about dependencies, platform-related issues, and so on. Installation guidelines can be found [here](https://www.docker.com/get-started/). On Linux platform, you might need to circumvent the *sudo privilege issue* by doing [this](https://docs.docker.com/engine/install/linux-postinstall/). + ## API Reference If you would like to integrate LTRS within a Rust application or crate, then we recommend reading [documentation](https://docs.rs/languagetool-rust). diff --git a/src/lib/docker.rs b/src/lib/docker.rs index 9bcd816..bc4299b 100644 --- a/src/lib/docker.rs +++ b/src/lib/docker.rs @@ -1,7 +1,7 @@ //! Structures and methods to easily manipulate Docker images, especially for LanguageTool //! applications. -use crate::error::{exit_status_error, Error, Result}; +use crate::error::{exit_status_error, Result}; use clap::Parser; use std::process::{Command, Output, Stdio}; @@ -9,19 +9,19 @@ use std::process::{Command, Output, Stdio}; #[derive(Debug, Clone)] /// Commands to pull, start and stop a LanguageTool using Docker. pub struct Docker { - #[cfg_attr(feature = "cli", clap(default_value = "erikvl87/languagetool"))] + #[cfg_attr(feature = "cli", clap(default_value = "erikvl87/languagetool", env = "LANGUAGETOOL_DOCKER_IMAGE"))] /// Image or repository from a registry. name: String, - #[cfg_attr(feature = "cli", clap(short = 'b', long, default_value = "docker"))] + #[cfg_attr(feature = "cli", clap(short = 'b', long, default_value = "docker", env = "LANGUAGETOOL_DOCKER_BIN"))] /// Path to Docker's binaries. bin: String, - #[cfg_attr(feature = "cli", clap(long, default_value = "languagetool"))] + #[cfg_attr(feature = "cli", clap(long, default_value = "languagetool", env = "LANGUAGETOOL_DOCKER_NAME"))] /// Name assigned to the container. container_name: String, - #[cfg_attr(feature = "cli", clap(short = 'p', long, default_value = "8010:8010"))] + #[cfg_attr(feature = "cli", clap(short = 'p', long, default_value = "8010:8010", env = "LANGUAGETOOL_DOCKER_PORT"))] /// Publish a container's port(s) to the host. port: String, - #[clap(subcommand)] + #[cfg_attr(feature = "cli", clap(subcommand))] /// Docker action. action: Action, } @@ -44,30 +44,7 @@ enum Action { Stop, } -impl FromStr for Action { - type Err = Error; - - fn from_str(s: &str) -> Result { - match s.lowercase().trim_matches(' ') { - "pull" => Ok(Action::Pull), - "start" => Ok(Action::Start), - "stop" => Ok(Action::Stop), - _ => Err(Error::ParseAction { s: s.to_string() }), - } - } -} - impl Docker { - fn from_env() -> Result { - let name = std::env::var("LANGUAGETOOL_DOCKER_NAME")?; - let bin = std::env::var("LANGUAGETOOL_DOCKER_IMAGE")?; - let name = std::env::var("LANGUAGETOOL_DOCKER_IMAGE")?; - let port = std::env::var("LANGUAGETOOL_DOCKER_PORT")?; - let name = std::env::var("LANGUAGETOOL_DOCKER_ACTION")?; - - Ok(Self { hostname, port }) - } - /// Pull a Docker image from the given repository/file/... pub fn pull(&self) -> Result { let output = Command::new(&self.bin) diff --git a/src/lib/server.rs b/src/lib/server.rs index 6ff36a7..9e4b466 100644 --- a/src/lib/server.rs +++ b/src/lib/server.rs @@ -379,7 +379,7 @@ impl ServerClient { let resp = self.check(request).await?; if resp.matches.is_empty() { - return Ok("Not error were found in provided text".to_string()); + return Ok("No error were found in provided text".to_string()); } let replacements: Vec<_> = resp .matches From dcec7d1aed637eae2e06c73c7182244438d16a74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Fri, 26 Aug 2022 14:08:14 +0200 Subject: [PATCH 07/11] fix(fmt): cargo fmt --- src/lib/docker.rs | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/lib/docker.rs b/src/lib/docker.rs index bc4299b..4acbd1e 100644 --- a/src/lib/docker.rs +++ b/src/lib/docker.rs @@ -9,16 +9,41 @@ use std::process::{Command, Output, Stdio}; #[derive(Debug, Clone)] /// Commands to pull, start and stop a LanguageTool using Docker. pub struct Docker { - #[cfg_attr(feature = "cli", clap(default_value = "erikvl87/languagetool", env = "LANGUAGETOOL_DOCKER_IMAGE"))] + #[cfg_attr( + feature = "cli", + clap( + default_value = "erikvl87/languagetool", + env = "LANGUAGETOOL_DOCKER_IMAGE" + ) + )] /// Image or repository from a registry. name: String, - #[cfg_attr(feature = "cli", clap(short = 'b', long, default_value = "docker", env = "LANGUAGETOOL_DOCKER_BIN"))] + #[cfg_attr( + feature = "cli", + clap( + short = 'b', + long, + default_value = "docker", + env = "LANGUAGETOOL_DOCKER_BIN" + ) + )] /// Path to Docker's binaries. bin: String, - #[cfg_attr(feature = "cli", clap(long, default_value = "languagetool", env = "LANGUAGETOOL_DOCKER_NAME"))] + #[cfg_attr( + feature = "cli", + clap(long, default_value = "languagetool", env = "LANGUAGETOOL_DOCKER_NAME") + )] /// Name assigned to the container. container_name: String, - #[cfg_attr(feature = "cli", clap(short = 'p', long, default_value = "8010:8010", env = "LANGUAGETOOL_DOCKER_PORT"))] + #[cfg_attr( + feature = "cli", + clap( + short = 'p', + long, + default_value = "8010:8010", + env = "LANGUAGETOOL_DOCKER_PORT" + ) + )] /// Publish a container's port(s) to the host. port: String, #[cfg_attr(feature = "cli", clap(subcommand))] From 92cc4039d90a14991a55839dbd9e9fae363c29fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Fri, 26 Aug 2022 14:13:46 +0200 Subject: [PATCH 08/11] chore(lint): try super clippy --- benches/benchmarks/check_texts.rs | 4 ++-- src/lib/lib.rs | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/benches/benchmarks/check_texts.rs b/benches/benchmarks/check_texts.rs index b933830..e7cac0e 100644 --- a/benches/benchmarks/check_texts.rs +++ b/benches/benchmarks/check_texts.rs @@ -8,10 +8,10 @@ use languagetool_rust::{ async fn request_until_success(req: &CheckRequest, client: &ServerClient) -> CheckResponse { loop { - match client.check(&req).await { + match client.check(req).await { Ok(resp) => return resp, Err(Error::InvalidRequest { body }) - if body == "Error: Server overloaded, please try again later".to_string() => + if body == *"Error: Server overloaded, please try again later" => { continue } diff --git a/src/lib/lib.rs b/src/lib/lib.rs index fe5906d..88378d6 100644 --- a/src/lib/lib.rs +++ b/src/lib/lib.rs @@ -1,5 +1,12 @@ #![deny(missing_docs)] #![deny(missing_debug_implementations)] +#![warn( + clippy::all, + clippy::restriction, + clippy::pedantic, + clippy::nursery, + clippy::cargo +)] #![cfg_attr(docsrs, feature(doc_auto_cfg))] #![doc = include_str!("../../README.md")] //! From fb08f32bad37e33ccdef5e13886659da1e990411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Fri, 26 Aug 2022 14:21:36 +0200 Subject: [PATCH 09/11] chore(lint): clippy pedantic --- src/lib/check.rs | 10 +++++----- src/lib/docker.rs | 4 ++-- src/lib/languages.rs | 2 +- src/lib/lib.rs | 7 ------- src/lib/server.rs | 36 ++++++++++++++++++------------------ src/lib/words.rs | 12 ++++++------ 6 files changed, 32 insertions(+), 39 deletions(-) diff --git a/src/lib/check.rs b/src/lib/check.rs index bd3a872..3235120 100644 --- a/src/lib/check.rs +++ b/src/lib/check.rs @@ -73,7 +73,7 @@ pub struct Data { impl> FromIterator for Data { fn from_iter>(iter: I) -> Self { - let annotation = iter.into_iter().map(|x| x.into()).collect(); + let annotation = iter.into_iter().map(std::convert::Into::into).collect(); Data { annotation } } } @@ -140,9 +140,9 @@ impl std::str::FromStr for Level { #[derive(Clone, Deserialize, Debug, Default, PartialEq, Eq, Serialize)] #[serde(rename_all = "camelCase")] #[non_exhaustive] -/// LanguageTool POST check request. +/// `LanguageTool` POST check request. /// -/// The main feature - check a text with LanguageTool for possible style and grammar issues. +/// The main feature - check a text with `LanguageTool` for possible style and grammar issues. /// /// The structure below tries to follow as closely as possible the JSON API described /// [here](https://languagetool.org/http-api/swagger-ui/#!/default/post_check). @@ -458,7 +458,7 @@ pub struct Match { #[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] #[non_exhaustive] -/// LanguageTool software details. +/// `LanguageTool` software details. pub struct Software { /// LanguageTool API version pub api_version: usize, @@ -490,7 +490,7 @@ pub struct Warnings { #[derive(Clone, PartialEq, Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] #[non_exhaustive] -/// LanguageTool POST check response. +/// `LanguageTool` POST check response. pub struct CheckResponse { /// Language information pub language: LanguageResponse, diff --git a/src/lib/docker.rs b/src/lib/docker.rs index 4acbd1e..82314cf 100644 --- a/src/lib/docker.rs +++ b/src/lib/docker.rs @@ -1,4 +1,4 @@ -//! Structures and methods to easily manipulate Docker images, especially for LanguageTool +//! Structures and methods to easily manipulate Docker images, especially for `LanguageTool` //! applications. use crate::error::{exit_status_error, Result}; @@ -7,7 +7,7 @@ use std::process::{Command, Output, Stdio}; #[cfg_attr(feature = "cli", derive(Parser))] #[derive(Debug, Clone)] -/// Commands to pull, start and stop a LanguageTool using Docker. +/// Commands to pull, start and stop a `LanguageTool` container using Docker. pub struct Docker { #[cfg_attr( feature = "cli", diff --git a/src/lib/languages.rs b/src/lib/languages.rs index b82f18a..998d86b 100644 --- a/src/lib/languages.rs +++ b/src/lib/languages.rs @@ -15,7 +15,7 @@ pub struct Language { pub long_code: String, } -/// LanguageTool GET languages response. +/// `LanguageTool` GET languages response. /// /// List of all supported languages. pub type LanguagesResponse = Vec; diff --git a/src/lib/lib.rs b/src/lib/lib.rs index 88378d6..fe5906d 100644 --- a/src/lib/lib.rs +++ b/src/lib/lib.rs @@ -1,12 +1,5 @@ #![deny(missing_docs)] #![deny(missing_debug_implementations)] -#![warn( - clippy::all, - clippy::restriction, - clippy::pedantic, - clippy::nursery, - clippy::cargo -)] #![cfg_attr(docsrs, feature(doc_auto_cfg))] #![doc = include_str!("../../README.md")] //! diff --git a/src/lib/server.rs b/src/lib/server.rs index 9e4b466..43076d0 100644 --- a/src/lib/server.rs +++ b/src/lib/server.rs @@ -1,4 +1,4 @@ -//! Structure to communite with some LanguageTool server through the API. +//! Structure to communite with some `LanguageTool` server through the API. use crate::check::{CheckRequest, CheckResponse}; use crate::error::{Error, Result}; @@ -129,7 +129,7 @@ impl ConfigFile { "{}=\"{}\"", key, a.iter() - .map(|v| v.to_string()) + .map(std::string::ToString::to_string) .collect::>() .join(",") )?, @@ -183,7 +183,7 @@ impl Default for ConfigFile { #[cfg_attr(feature = "cli", derive(Parser))] #[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] #[non_exhaustive] -/// Server parameters that are to be used when instantiating a LanguageTool server +/// Server parameters that are to be used when instantiating a `LanguageTool` server pub struct ServerParameters { #[cfg_attr(feature = "cli", clap(long))] config: Option, @@ -223,7 +223,7 @@ impl Default for ServerParameters { #[cfg_attr(feature = "cli", derive(Parser))] #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] -/// Hostname and (optional) port to connect to a LanguageTool server. +/// Hostname and (optional) port to connect to a `LanguageTool` server. /// /// To use your local server instead of online api, set: /// - `hostname` to "http://localhost" @@ -255,9 +255,9 @@ impl Default for ServerCli { } impl ServerCli { - /// Create a new [ServeCli] instance from environ variables: - /// - LANGUAGETOOL_HOSTNAME - /// - LANGUAGETOOL_PORT + /// Create a new [`ServeCli`] instance from environ variables: + /// - `LANGUAGETOOL_HOSTNAME` + /// - `LANGUAGETOOL_PORT` /// /// If one or both environ variables are empty, an error is returned. pub fn from_env() -> Result { @@ -267,15 +267,15 @@ impl ServerCli { Ok(Self { hostname, port }) } - /// Create a new [ServerCli] instance from environ variables, - /// but defaults to [ServerCli::default()] if expected environ + /// Create a new [`ServerCli`] instance from environ variables, + /// but defaults to [`ServerCli::default`()] if expected environ /// variables are not set. pub fn from_env_or_default() -> Self { ServerCli::from_env().unwrap_or_default() } } -/// Client to communicate with the LanguageTool server using async requests. +/// Client to communicate with the `LanguageTool` server using async requests. #[derive(Clone, Debug)] pub struct ServerClient { /// API string: hostname and, optionally, port number (see [ServerCli]) @@ -296,7 +296,7 @@ impl ServerClient { /// Construct a new server client using hostname and (optional) port /// /// An empty string is accepeted as empty port. - /// For port validation, please use [is_port] as this constructor does not check anything. + /// For port validation, please use [`is_port`] as this constructor does not check anything. pub fn new(hostname: &str, port: &str) -> Self { let api = if port.is_empty() { format!("{}/v2", hostname) @@ -318,19 +318,19 @@ impl ServerClient { self } - /// Converts a [ServerCli] into a proper (usable) client + /// Converts a [`ServerCli`] into a proper (usable) client pub fn from_cli(cli: ServerCli) -> Self { cli.into() } #[cfg(feature = "cli")] - /// This function has the same sementics as [ServerCli::from_arg_matches] + /// This function has the same sementics as [`ServerCli::from_arg_matches`] pub fn from_arg_matches(matches: &clap::ArgMatches) -> Result { let params = ServerCli::from_arg_matches(matches)?; Ok(Self::from_cli(params)) } - /// This function has the same semantics as [ServerCli::command] + /// This function has the same semantics as [`ServerCli::command`] #[cfg(feature = "cli")] pub fn command<'help>() -> clap::Command<'help> { ServerCli::command() @@ -543,15 +543,15 @@ impl Default for ServerClient { } impl ServerClient { - /// Create a new [ServerClient] instance from environ variables. + /// Create a new [`ServerClient`] instance from environ variables. /// - /// See [ServerCli::from_env] for more details. + /// See [`ServerCli::from_env`] for more details. pub fn from_env() -> Result { Ok(Self::from_cli(ServerCli::from_env()?)) } - /// Create a new [ServerClient] instance from environ variables, - /// but defaults to [ServerClient::default()] if expected environ + /// Create a new [`ServerClient`] instance from environ variables, + /// but defaults to [`ServerClient::default`()] if expected environ /// variables are not set. pub fn from_env_or_default() -> Self { Self::from_cli(ServerCli::from_env_or_default()) diff --git a/src/lib/words.rs b/src/lib/words.rs index d26d714..9415572 100644 --- a/src/lib/words.rs +++ b/src/lib/words.rs @@ -42,7 +42,7 @@ pub struct LoginArgs { #[cfg_attr(feature = "cli", derive(Parser))] #[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)] #[non_exhaustive] -/// LanguageTool GET words request. +/// `LanguageTool` GET words request. /// /// List words in the user's personal dictionaries. pub struct WordsRequest { @@ -63,7 +63,7 @@ pub struct WordsRequest { #[cfg_attr(feature = "cli", derive(Parser))] #[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)] #[non_exhaustive] -/// LanguageTool POST words add request. +/// `LanguageTool` POST words add request. /// /// Add a word to one of the user's personal dictionaries. Please note that this feature is considered to be used for personal dictionaries which must not contain more than 500 words. If this is an issue for you, please contact us. pub struct WordsAddRequest { @@ -82,7 +82,7 @@ pub struct WordsAddRequest { #[cfg_attr(feature = "cli", derive(Parser))] #[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)] #[non_exhaustive] -/// LanguageTool POST words delete request. +/// `LanguageTool` POST words delete request. /// /// Remove a word from one of the user's personal dictionaries. pub struct WordsDeleteRequest { @@ -100,7 +100,7 @@ pub struct WordsDeleteRequest { #[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)] #[non_exhaustive] -/// LanguageTool GET words response. +/// `LanguageTool` GET words response. pub struct WordsResponse { /// List of words words: Vec, @@ -108,7 +108,7 @@ pub struct WordsResponse { #[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)] #[non_exhaustive] -/// LanguageTool POST word add response. +/// `LanguageTool` POST word add response. pub struct WordsAddResponse { /// `true` if word was correctly added added: bool, @@ -116,7 +116,7 @@ pub struct WordsAddResponse { #[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)] #[non_exhaustive] -/// LanguageTool POST word delete response. +/// `LanguageTool` POST word delete response. pub struct WordsDeleteResponse { /// `true` if word was correctly removed deleted: bool, From a915c1170190d6a892f1a6bd842d570114b08d21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Fri, 26 Aug 2022 14:26:36 +0200 Subject: [PATCH 10/11] fix(lib): dead code and cli feature --- src/lib/docker.rs | 1 + src/lib/error.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/lib/docker.rs b/src/lib/docker.rs index 82314cf..ee96a4c 100644 --- a/src/lib/docker.rs +++ b/src/lib/docker.rs @@ -2,6 +2,7 @@ //! applications. use crate::error::{exit_status_error, Result}; +#[cfg(feature = "cli")] use clap::Parser; use std::process::{Command, Output, Stdio}; diff --git a/src/lib/error.rs b/src/lib/error.rs index 72ebc43..c560a2f 100644 --- a/src/lib/error.rs +++ b/src/lib/error.rs @@ -61,6 +61,7 @@ pub enum Error { /// Result type alias with error type defined above (see [Error]). pub type Result = std::result::Result; +#[allow(dead_code)] pub(crate) fn exit_status_error(exit_status: &ExitStatus) -> Result<()> { match exit_status.success() { true => Ok(()), From 26c9f3308d00409b71cc3b11298722fcc7134dfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Fri, 26 Aug 2022 14:35:25 +0200 Subject: [PATCH 11/11] chore(README): update features flag --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fac3495..04d3ed9 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ async fn main() -> Result<(), Box> { #### Optional Features - **annotate**: Adds method(s) to annotate results from check request. If **cli** feature is also enabled, the CLI will by default print an annotated output. -- **full**: Enables all features that are mutually compatible (i.e., `cli` and `annotate`). +- **full**: Enables all features that are mutually compatible (i.e., `annotate`, `cli`, `docker`, and `unstable`). - **native-tls-vendored**: Enables the `vendored` feature of `native-tls`. This or `native-tls` should be activated if you are planning to use HTTPS servers. - **unstable**: Adds more fields to JSON responses that are not present in the [Model | Example Value](https://languagetool.org/http-api/swagger-ui/#!/default/) but might be present in some cases. All added fields are optional, hence the `Option` around them.