1
1
//! Structures for `check` requests and responses.
2
2
3
- use crate :: error:: Error ;
4
- #[ cfg( feature = "cli" ) ]
3
+ #[ cfg( feature = "clap" ) ]
5
4
use clap:: Parser ;
6
5
#[ cfg( feature = "lazy_static" ) ]
7
6
use lazy_static:: lazy_static;
@@ -61,7 +60,7 @@ pub fn is_language_code(v: &str) -> crate::error::Result<()> {
61
60
if v == "auto" || RE . is_match ( v) {
62
61
Ok ( ( ) )
63
62
} else {
64
- Err ( Error :: InvalidValue {
63
+ Err ( crate :: error :: Error :: InvalidValue {
65
64
body : format ! (
66
65
"The value should be `auto` or match regex pattern: {}" ,
67
66
RE . as_str( )
@@ -157,7 +156,7 @@ impl Serialize for Data {
157
156
}
158
157
}
159
158
160
- #[ cfg( feature = "cli " ) ]
159
+ #[ cfg( feature = "clap " ) ]
161
160
impl std:: str:: FromStr for Data {
162
161
type Err = clap:: Error ;
163
162
@@ -205,7 +204,7 @@ impl Level {
205
204
}
206
205
}
207
206
208
- #[ cfg( feature = "cli " ) ]
207
+ #[ cfg( feature = "clap " ) ]
209
208
impl std:: str:: FromStr for Level {
210
209
type Err = clap:: Error ;
211
210
@@ -221,7 +220,7 @@ impl std::str::FromStr for Level {
221
220
}
222
221
}
223
222
224
- #[ cfg( feature = "cli " ) ]
223
+ #[ cfg( feature = "clap " ) ]
225
224
impl clap:: ValueEnum for Level {
226
225
fn value_variants < ' a > ( ) -> & ' a [ Self ] {
227
226
& [ Self :: Default , Self :: Picky ]
@@ -235,7 +234,7 @@ impl clap::ValueEnum for Level {
235
234
}
236
235
}
237
236
238
- #[ cfg_attr( feature = "cli " , derive( Parser ) ) ]
237
+ #[ cfg_attr( feature = "clap " , derive( Parser ) ) ]
239
238
#[ derive( Clone , Deserialize , Debug , Default , PartialEq , Eq , Serialize ) ]
240
239
#[ serde( rename_all = "camelCase" ) ]
241
240
#[ non_exhaustive]
@@ -246,21 +245,21 @@ impl clap::ValueEnum for Level {
246
245
/// The structure below tries to follow as closely as possible the JSON API described
247
246
/// [here](https://languagetool.org/http-api/swagger-ui/#!/default/post_check).
248
247
pub struct CheckRequest {
249
- #[ cfg( all( feature = "cli " , feature = "annotate" ) ) ]
248
+ #[ cfg( all( feature = "clap " , feature = "annotate" ) ) ]
250
249
#[ clap( short = 'r' , long, takes_value = false ) ]
251
250
#[ serde( skip_serializing) ]
252
251
/// If present, raw JSON output will be printed instead of annotated text.
253
252
pub raw : bool ,
254
- #[ cfg( feature = "cli " ) ]
253
+ #[ cfg( feature = "clap " ) ]
255
254
#[ clap( short = 'm' , long, takes_value = false ) ]
256
255
#[ serde( skip_serializing) ]
257
256
/// If present, more context (i.e., line number and line offset) will be added to response.
258
257
pub more_context : bool ,
259
- #[ cfg_attr( feature = "cli " , clap( short = 't' , long, conflicts_with = "data" , ) ) ]
258
+ #[ cfg_attr( feature = "clap " , clap( short = 't' , long, conflicts_with = "data" , ) ) ]
260
259
#[ serde( skip_serializing_if = "Option::is_none" ) ]
261
260
/// The text to be checked. This or 'data' is required.
262
261
pub text : Option < String > ,
263
- #[ cfg_attr( feature = "cli " , clap( short = 'd' , long, conflicts_with = "text" ) ) ]
262
+ #[ cfg_attr( feature = "clap " , clap( short = 'd' , long, conflicts_with = "text" ) ) ]
264
263
#[ serde( skip_serializing_if = "Option::is_none" ) ]
265
264
/// The text to be checked, given as a JSON document that specifies what's text and what's markup. This or 'text' is required.
266
265
///
@@ -285,14 +284,18 @@ pub struct CheckRequest {
285
284
/// The 'data' feature is not limited to HTML or XML, it can be used for any kind of markup. Entities will need to be expanded in this input.
286
285
pub data : Option < Data > ,
287
286
#[ cfg_attr(
288
- feature = "cli" ,
287
+ all ( feature = "clap" , feature = "lazy_static" , feature = "regex" ) ,
289
288
clap(
290
289
short = 'l' ,
291
290
long,
292
291
default_value = "auto" ,
293
292
validator = is_language_code
294
293
)
295
294
) ]
295
+ #[ cfg_attr(
296
+ all( feature = "clap" , not( all( feature = "lazy_static" , feature = "regex" ) ) ) ,
297
+ clap( short = 'l' , long, default_value = "auto" , )
298
+ ) ]
296
299
/// A language code like `en-US`, `de-DE`, `fr`, or `auto` to guess the language automatically (see `preferredVariants` below).
297
300
///
298
301
/// For languages with variants (English, German, Portuguese) spell checking will only be activated when you specify the variant, e.g. `en-GB` instead of just `en`.
@@ -301,45 +304,45 @@ pub struct CheckRequest {
301
304
#[ serde( skip_serializing_if = "Option::is_none" ) ]
302
305
/// Set to get Premium API access: Your username/email as used to log in at languagetool.org.
303
306
pub username : Option < String > ,
304
- #[ cfg_attr( feature = "cli " , clap( short = 'k' , long, requires = "username" ) ) ]
307
+ #[ cfg_attr( feature = "clap " , clap( short = 'k' , long, requires = "username" ) ) ]
305
308
#[ serde( skip_serializing_if = "Option::is_none" ) ]
306
309
/// Set to get Premium API access: [your API key](https://languagetool.org/editor/settings/api)
307
310
pub api_key : Option < String > ,
308
- #[ cfg_attr( feature = "cli " , clap( long, multiple_values = true ) ) ]
311
+ #[ cfg_attr( feature = "clap " , clap( long, multiple_values = true ) ) ]
309
312
#[ serde( skip_serializing_if = "Option::is_none" ) ]
310
313
/// Comma-separated list of dictionaries to include words from; uses special default dictionary if this is unset
311
314
pub dicts : Option < Vec < String > > ,
312
- #[ cfg_attr( feature = "cli " , clap( long) ) ]
315
+ #[ cfg_attr( feature = "clap " , clap( long) ) ]
313
316
#[ serde( skip_serializing_if = "Option::is_none" ) ]
314
317
/// A language code of the user's native language, enabling false friends checks for some language pairs.
315
318
pub mother_tongue : Option < String > ,
316
- #[ cfg_attr( feature = "cli " , clap( long, multiple_values = true ) ) ]
319
+ #[ cfg_attr( feature = "clap " , clap( long, multiple_values = true ) ) ]
317
320
#[ serde( skip_serializing_if = "Option::is_none" ) ]
318
321
/// Comma-separated list of preferred language variants.
319
322
///
320
323
/// The language detector used with `language=auto` can detect e.g. English, but it cannot decide whether British English or American English is used. Thus this parameter can be used to specify the preferred variants like `en-GB` and `de-AT`. Only available with `language=auto`. You should set variants for at least German and English, as otherwise the spell checking will not work for those, as no spelling dictionary can be selected for just `en` or `de`.
321
324
pub preferred_variants : Option < Vec < String > > ,
322
- #[ cfg_attr( feature = "cli " , clap( long, multiple_values = true ) ) ]
325
+ #[ cfg_attr( feature = "clap " , clap( long, multiple_values = true ) ) ]
323
326
#[ serde( skip_serializing_if = "Option::is_none" ) ]
324
327
/// IDs of rules to be enabled, comma-separated
325
328
pub enabled_rules : Option < Vec < String > > ,
326
- #[ cfg_attr( feature = "cli " , clap( long, multiple_values = true ) ) ]
329
+ #[ cfg_attr( feature = "clap " , clap( long, multiple_values = true ) ) ]
327
330
#[ serde( skip_serializing_if = "Option::is_none" ) ]
328
331
/// IDs of rules to be disabled, comma-separated
329
332
pub disabled_rules : Option < Vec < String > > ,
330
- #[ cfg_attr( feature = "cli " , clap( long, multiple_values = true ) ) ]
333
+ #[ cfg_attr( feature = "clap " , clap( long, multiple_values = true ) ) ]
331
334
#[ serde( skip_serializing_if = "Option::is_none" ) ]
332
335
/// IDs of categories to be enabled, comma-separated
333
336
pub enabled_categories : Option < Vec < String > > ,
334
- #[ cfg_attr( feature = "cli " , clap( long, multiple_values = true ) ) ]
337
+ #[ cfg_attr( feature = "clap " , clap( long, multiple_values = true ) ) ]
335
338
#[ serde( skip_serializing_if = "Option::is_none" ) ]
336
339
/// IDs of categories to be disabled, comma-separated
337
340
pub disabled_categories : Option < Vec < String > > ,
338
- #[ cfg_attr( feature = "cli " , clap( long, takes_value = false ) ) ]
341
+ #[ cfg_attr( feature = "clap " , clap( long, takes_value = false ) ) ]
339
342
#[ serde( skip_serializing_if = "is_false" ) ]
340
343
/// If true, only the rules and categories whose IDs are specified with `enabledRules` or `enabledCategories` are enabled.
341
344
pub enabled_only : bool ,
342
- #[ cfg_attr( feature = "cli " , clap( long, default_value = "default" , value_parser = clap:: builder:: EnumValueParser :: <Level >:: new( ) ) ) ]
345
+ #[ cfg_attr( feature = "clap " , clap( long, default_value = "default" , value_parser = clap:: builder:: EnumValueParser :: <Level >:: new( ) ) ) ]
343
346
#[ serde( skip_serializing_if = "Level::is_default" ) ]
344
347
/// If set to `picky`, additional rules will be activated, i.e. rules that you might only find useful when checking formal text.
345
348
pub level : Level ,
@@ -466,7 +469,7 @@ pub struct Context {
466
469
pub text : String ,
467
470
}
468
471
469
- #[ cfg( feature = "cli " ) ]
472
+ #[ cfg( feature = "clap " ) ]
470
473
#[ derive( Clone , Debug , Deserialize , PartialEq , Eq , Serialize ) ]
471
474
#[ non_exhaustive]
472
475
/// More context, post-processed in check response.
@@ -568,7 +571,7 @@ pub struct Match {
568
571
pub length : usize ,
569
572
/// Error message
570
573
pub message : String ,
571
- #[ cfg( feature = "cli " ) ]
574
+ #[ cfg( feature = "clap " ) ]
572
575
#[ serde( skip_serializing_if = "Option::is_none" ) ]
573
576
/// More context to match, post-processed using original text
574
577
pub more_context : Option < MoreContext > ,
@@ -726,7 +729,7 @@ impl CheckResponseWithContext {
726
729
}
727
730
}
728
731
729
- #[ cfg( feature = "cli " ) ]
732
+ #[ cfg( feature = "clap " ) ]
730
733
impl From < CheckResponseWithContext > for CheckResponse {
731
734
#[ allow( clippy:: needless_borrow) ]
732
735
fn from ( mut resp : CheckResponseWithContext ) -> Self {
0 commit comments