Skip to content

Commit f300aaa

Browse files
committed
chore: minor cleanup
Signed-off-by: Alexis Delain <quiet.syscall@proton.me>
1 parent 8d5833a commit f300aaa

File tree

9 files changed

+1106
-546
lines changed

9 files changed

+1106
-546
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ resolver = "2"
99
# Common dependencies can be defined here
1010
anyhow = "1"
1111
clap = { version = "4.5", features = ["derive"] }
12-
http = "1"
1312
jsonpath_lib = "0.3"
1413
openapiv3 = "1"
1514
regex = "1"

dummyjson-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "dummyjson-cli"
33
version = "0.1.0"
44
edition = "2021"
55
description = "A dummyjson.com mock AIP server CLI tool built with rclib"
6-
license = "Apache 2.0"
6+
license = "Apache-2.0"
77

88
[[bin]]
99
name = "dummyjson-cli"

dummyjson-cli/src/main.rs

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use std::collections::HashMap;
12
use std::env;
23
use std::fs;
3-
use std::collections::HashMap;
44

55
use anyhow::{Context, Result};
66

@@ -27,18 +27,22 @@ fn real_main() -> Result<()> {
2727

2828
// Load OpenAPI (for default base URL)
2929
let openapi_text = if let Some(path) = openapi_file.as_deref() {
30-
fs::read_to_string(path).with_context(|| format!("Failed to read openapi file: {}", path))?
30+
fs::read_to_string(path)
31+
.with_context(|| format!("Failed to read openapi file: {}", path))?
3132
} else {
3233
EMBEDDED_OPENAPI.to_string()
3334
};
3435
let openapi = rclib::parse_openapi(&openapi_text).context("OpenAPI parsing failed")?;
35-
let default_base_url = openapi.servers.first().map(|s| s.url.clone()).unwrap_or_else(|| {
36-
"https://dummyjson.com".to_string()
37-
});
36+
let default_base_url = openapi
37+
.servers
38+
.first()
39+
.map(|s| s.url.clone())
40+
.unwrap_or_else(|| "https://dummyjson.com".to_string());
3841

3942
// Load mapping used to build the dynamic command tree
4043
let mapping_yaml = if let Some(path) = mapping_file.as_deref() {
41-
fs::read_to_string(path).with_context(|| format!("Failed to read mapping file: {}", path))?
44+
fs::read_to_string(path)
45+
.with_context(|| format!("Failed to read mapping file: {}", path))?
4246
} else {
4347
EMBEDDED_MAPPING.to_string()
4448
};
@@ -66,7 +70,13 @@ fn real_main() -> Result<()> {
6670

6771
// Delegate command driving to rclib
6872
let user_agent = format!("{}/{}", APP_NAME, env!("CARGO_PKG_VERSION"));
69-
let exit_code = rclib::cli::drive_command(&mapping_root, &default_base_url, &matches, &reg, &user_agent)?;
73+
let exit_code = rclib::cli::drive_command(
74+
&mapping_root,
75+
&default_base_url,
76+
&matches,
77+
&reg,
78+
&user_agent,
79+
)?;
7080
std::process::exit(exit_code);
7181
}
7282

@@ -77,8 +87,14 @@ fn handle_export_users(
7787
json_output: bool,
7888
) -> Result<()> {
7989
let format = vars.get("format").map(|s| s.as_str()).unwrap_or("json");
80-
let output_file = vars.get("output_file").map(|s| s.as_str()).unwrap_or("users_export.json");
81-
let include_sensitive = vars.get("include_sensitive").map(|s| s == "true").unwrap_or(false);
90+
let output_file = vars
91+
.get("output_file")
92+
.map(|s| s.as_str())
93+
.unwrap_or("users_export.json");
94+
let include_sensitive = vars
95+
.get("include_sensitive")
96+
.map(|s| s == "true")
97+
.unwrap_or(false);
8298
let limit = vars.get("limit").map(|s| s.as_str()).unwrap_or("100");
8399
let skip = vars.get("skip").map(|s| s.as_str()).unwrap_or("0");
84100

@@ -101,10 +117,20 @@ fn handle_export_users(
101117
println!("User Export Operation");
102118
println!("Format: {}", format);
103119
println!("Output: {}", output_file);
104-
println!("Sensitive data: {}", if include_sensitive { "included" } else { "excluded" });
120+
println!(
121+
"Sensitive data: {}",
122+
if include_sensitive {
123+
"included"
124+
} else {
125+
"excluded"
126+
}
127+
);
105128
println!("Records: {} (starting from {})", limit, skip);
106129
println!("API Base: {}", base_url);
107-
println!("\n Export would fetch from: {}/users?limit={}&skip={}", base_url, limit, skip);
130+
println!(
131+
"\n Export would fetch from: {}/users?limit={}&skip={}",
132+
base_url, limit, skip
133+
);
108134
println!(" Would save to: {}", output_file);
109135
}
110136

@@ -117,10 +143,16 @@ fn handle_product_analytics(
117143
base_url: &str,
118144
json_output: bool,
119145
) -> Result<()> {
120-
let report_type = vars.get("report_type").map(|s| s.as_str()).unwrap_or("summary");
146+
let report_type = vars
147+
.get("report_type")
148+
.map(|s| s.as_str())
149+
.unwrap_or("summary");
121150
let category_filter = vars.get("category_filter").map(|s| s.as_str());
122151
let price_range = vars.get("price_range").map(|s| s.as_str());
123-
let output_format = vars.get("output_format").map(|s| s.as_str()).unwrap_or("table");
152+
let output_format = vars
153+
.get("output_format")
154+
.map(|s| s.as_str())
155+
.unwrap_or("table");
124156

125157
if json_output {
126158
let response = serde_json::json!({

rclib/Cargo.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ name = "rclib"
33
version = "0.1.0"
44
edition = "2021"
55
description = "A CLI builder library for Rust"
6-
license = "Apache 2.0"
6+
license = "Apache-2.0"
77
repository = "https://github.com/your-username/rclib"
88

99
[dependencies]
1010
clap = { workspace = true }
1111
serde = { workspace = true }
1212
anyhow = { workspace = true }
13-
http = { workspace = true }
1413
jsonpath_lib = { workspace = true }
1514
openapiv3 = { workspace = true }
1615
regex = { workspace = true }
@@ -19,7 +18,3 @@ serde_json = { workspace = true }
1918
serde_yaml = { workspace = true }
2019
once_cell = { workspace = true }
2120
uuid = { workspace = true }
22-
23-
[dev-dependencies]
24-
wiremock = "0.6"
25-
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }

0 commit comments

Comments
 (0)