Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: further separate CLI logic from the API related functionality (see #117) #124

Open
wants to merge 18 commits into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 64 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ required-features = ["cli"]
annotate-snippets = {version = "^0.9.1", optional = true}
clap = {version = "^4.5.18", features = ["cargo", "derive", "env", "wrap_help"], optional = true}
clap_complete = {version = "^4.5.2", optional = true}
enum_dispatch = {version = "0.3.13", optional = true}
is-terminal = {version = "0.4.3", optional = true}
lifetime = { version = "0.1.0", features = ["macros"] }
pulldown-cmark = {version = "0.10.2", optional = true}
reqwest = {version = "^0.11", default-features = false, features = ["json"]}
serde = {version = "^1.0", features = ["derive"]}
Expand All @@ -33,7 +35,7 @@ tokio = {version = "^1.0", features = ["macros"]}

[features]
annotate = ["dep:annotate-snippets"]
cli = ["annotate", "color", "dep:clap", "dep:is-terminal", "multithreaded"]
cli = ["annotate", "color", "dep:clap", "dep:enum_dispatch", "dep:is-terminal", "multithreaded"]
cli-complete = ["cli", "clap_complete"]
color = ["annotate-snippets?/color", "dep:termcolor"]
default = ["cli", "native-tls"]
Expand Down Expand Up @@ -61,7 +63,7 @@ license = "MIT"
name = "languagetool-rust"
readme = "README.md"
repository = "https://github.com/jeertmans/languagetool-rust"
rust-version = "1.74.0"
rust-version = "1.75.0"
version = "2.1.4"

[package.metadata.docs.rs]
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,14 @@ languagetool-rust = "^2.1"

```rust
use languagetool_rust::api::{check, server::ServerClient};
use std::borrow::Cow;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = ServerClient::from_env_or_default();

let req = check::Request::default()
.with_text("Some phrase with a smal mistake".to_string()); // # codespell:ignore smal
.with_text(Cow::Borrowed("Some phrase with a smal mistake")); // # codespell:ignore smal

println!(
"{}",
Expand Down
10 changes: 6 additions & 4 deletions benches/benchmarks/check_texts.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::borrow::Cow;

use codspeed_criterion_compat::{criterion_group, Criterion, Throughput};
use futures::future::join_all;
use languagetool_rust::{
Expand All @@ -14,7 +16,7 @@ static FILES: [(&str, &str); 3] = [
("large", include_str!("../large.txt")),
];

async fn request_until_success(req: &Request, client: &ServerClient) -> Response {
async fn request_until_success<'source>(req: &Request<'source>, client: &ServerClient) -> Response {
loop {
match client.check(req).await {
Ok(resp) => return resp,
Expand All @@ -29,12 +31,12 @@ async fn request_until_success(req: &Request, client: &ServerClient) -> Response
}

#[tokio::main]
async fn check_text_basic(text: &str) -> Response {
async fn check_text_basic(text: &'static str) -> Response {
let client = ServerClient::from_env().expect(
"Please use a local server for benchmarking, and configure the environ variables to use \
it.",
);
let req = Request::default().with_text(text.to_string());
let req = Request::default().with_text(Cow::Borrowed(text));
request_until_success(&req, &client).await
}

Expand All @@ -48,7 +50,7 @@ async fn check_text_split(text: &str) -> Response {

let resps = join_all(lines.map(|line| {
async {
let req = Request::default().with_text(line.to_string());
let req = Request::default().with_text(Cow::Owned(line.to_string()));
let resp = request_until_success(&req, &client).await;
check::ResponseWithContext::new(req.get_text(), resp)
}
Expand Down
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
condense_wildcard_suffixes = true
edition = "2021"
# error_on_line_overflow = true
# error_on_unformatted = true
force_multiline_blocks = true
Expand All @@ -9,5 +10,4 @@ imports_granularity = "Crate"
match_block_trailing_comma = true
normalize_doc_attributes = true
unstable_features = true
version = "Two"
wrap_comments = true
Loading
Loading