Skip to content

Commit eb5bb54

Browse files
committed
Add optional clap feature
… with some useful initial clap trait implementations.
1 parent 41088db commit eb5bb54

File tree

6 files changed

+68
-6
lines changed

6 files changed

+68
-6
lines changed

rust/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ categories = ["development-tools", "asynchronous", "network-programming", "web-p
1414
[features]
1515
default = ["http1", "native-tls"]
1616

17+
clap = ["dep:clap"]
1718
http1 = ["hyper-util/http1", "hyper-rustls?/http1"]
1819
http2 = ["hyper-util/http2", "hyper-rustls?/http2"]
1920
native-tls = ["dep:hyper-tls"]
@@ -39,6 +40,7 @@ time = "0.3"
3940
url = "2.2"
4041
tokio = { version = "1.41.0", features = ["time"] }
4142
serde_with = { version = "^3.8", default-features = false, features = ["base64", "std", "macros"] }
43+
clap = { version = "4.5.23", default-features = false, features = ["derive", "std"], optional = true }
4244

4345
[dev-dependencies]
4446
tokio = { version = "1.41.0", features = ["macros"] }

rust/src/api/application.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@ use super::PostOptions;
22
use crate::{apis::application_api, error::Result, models::*, Configuration};
33

44
#[derive(Default)]
5+
#[cfg_attr(feature = "clap", derive(clap::Args))]
56
pub struct ApplicationListOptions {
6-
pub iterator: Option<String>,
7+
/// Limit the number of returned items
8+
#[cfg_attr(feature = "clap", clap(long))]
79
pub limit: Option<i32>,
10+
11+
/// The iterator returned from a prior invocation
12+
#[cfg_attr(feature = "clap", clap(long))]
13+
pub iterator: Option<String>,
14+
15+
/// The sorting order of the returned items
16+
#[cfg_attr(feature = "clap", clap(long))]
817
pub order: Option<Ordering>,
918
}
1019

rust/src/api/endpoint.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@ use super::PostOptions;
22
use crate::{apis::endpoint_api, error::Result, models::*, Configuration};
33

44
#[derive(Default)]
5+
#[cfg_attr(feature = "clap", derive(clap::Args))]
56
pub struct EndpointListOptions {
6-
pub iterator: Option<String>,
7+
/// Limit the number of returned items
8+
#[cfg_attr(feature = "clap", clap(long))]
79
pub limit: Option<i32>,
10+
11+
/// The iterator returned from a prior invocation
12+
#[cfg_attr(feature = "clap", clap(long))]
13+
pub iterator: Option<String>,
14+
15+
/// The sorting order of the returned items
16+
#[cfg_attr(feature = "clap", clap(long))]
817
pub order: Option<Ordering>,
918
}
1019

rust/src/api/event_type.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,25 @@ use super::PostOptions;
22
use crate::{apis::event_type_api, error::Result, models::*, Configuration};
33

44
#[derive(Default)]
5+
#[cfg_attr(feature = "clap", derive(clap::Args))]
56
pub struct EventTypeListOptions {
6-
pub iterator: Option<String>,
7+
/// Limit the number of returned items
8+
#[cfg_attr(feature = "clap", clap(long))]
79
pub limit: Option<i32>,
8-
pub with_content: Option<bool>,
10+
11+
/// The iterator returned from a prior invocation
12+
#[cfg_attr(feature = "clap", clap(long))]
13+
pub iterator: Option<String>,
14+
15+
/// When `true` archived (deleted but not expunged) items are included in
16+
/// the response
17+
#[cfg_attr(feature = "clap", clap(long))]
918
pub include_archived: Option<bool>,
19+
20+
/// When `true` the full item (including the schema) is included in the
21+
/// response
22+
#[cfg_attr(feature = "clap", clap(long))]
23+
pub with_content: Option<bool>,
1024
}
1125

1226
pub struct EventType<'a> {
@@ -35,6 +49,7 @@ impl<'a> EventType<'a> {
3549
limit,
3650
with_content,
3751
include_archived,
52+
// FIXME: Not part of EventTypeListOptions for backwards compat, for now.
3853
order: None,
3954
},
4055
)

rust/src/api/integration.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@ use super::PostOptions;
22
use crate::{apis::integration_api, error::Result, models::*, Configuration};
33

44
#[derive(Default)]
5+
#[cfg_attr(feature = "clap", derive(clap::Args))]
56
pub struct IntegrationListOptions {
6-
pub iterator: Option<String>,
7+
/// Limit the number of returned items
8+
#[cfg_attr(feature = "clap", clap(long))]
79
pub limit: Option<i32>,
10+
11+
/// The iterator returned from a prior invocation
12+
#[cfg_attr(feature = "clap", clap(long))]
13+
pub iterator: Option<String>,
14+
15+
/// The sorting order of the returned items
16+
#[cfg_attr(feature = "clap", clap(long))]
817
pub order: Option<Ordering>,
918
}
1019

rust/src/model_ext.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
//! Extensions of the auto-generated "models" (schema structs).
22
3+
use std::str::FromStr;
4+
35
use serde_json::json;
46

5-
use crate::models::MessageIn;
7+
use crate::{api::Ordering, models::MessageIn};
68

79
impl MessageIn {
810
/// Create a new message with a pre-serialized payload.
@@ -38,3 +40,19 @@ impl MessageIn {
3840
self
3941
}
4042
}
43+
44+
#[derive(Debug, thiserror::Error)]
45+
#[error("invalid value for ordering")]
46+
pub struct OrderingFromStrError;
47+
48+
impl FromStr for Ordering {
49+
type Err = OrderingFromStrError;
50+
51+
fn from_str(s: &str) -> Result<Self, Self::Err> {
52+
match s {
53+
"ascending" => Ok(Self::Ascending),
54+
"descending" => Ok(Self::Descending),
55+
_ => Err(OrderingFromStrError),
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)