Skip to content

Commit 1b57721

Browse files
committed
Fix CI: reformat with stable rustfmt, remove nightly-only rustfmt options
The rustfmt.toml contained nightly-only options (imports_granularity, group_imports) that were silently ignored by stable Rust. Code had been formatted using nightly rustfmt, so 'cargo fmt --check' on stable (as used in CI) failed with exit code 1. Remove the nightly-only options and reformat all files with stable rustfmt so the CI formatting check passes.
1 parent d1403a4 commit 1b57721

File tree

17 files changed

+151
-94
lines changed

17 files changed

+151
-94
lines changed

rustfmt.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
# Group imports: std, then third-party, then crate-local
2-
group_imports = "StdExternalCrate"
3-
imports_granularity = "Module"
1+

src/commands/account.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ use std::collections::HashMap;
66
/// Fetch and return the account information for the given API key.
77
pub async fn run(api_key: &str) -> Result<Value, CliError> {
88
let client = make_client(api_key)?;
9-
let result = client
10-
.account(HashMap::new())
11-
.await
12-
.map_err(network_err)?;
9+
let result = client.account(HashMap::new()).await.map_err(network_err)?;
1310
check_api_error(result)
1411
}

src/commands/archive.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ use serde_json::Value;
55
/// Retrieve a previously cached search result from the SerpApi archive by its ID.
66
pub async fn run(id: &str, api_key: &str) -> Result<Value, CliError> {
77
let client = make_client(api_key)?;
8-
let result = client
9-
.search_archive(id)
10-
.await
11-
.map_err(network_err)?;
8+
let result = client.search_archive(id).await.map_err(network_err)?;
129
check_api_error(result)
1310
}

src/commands/locations.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ pub async fn run(params: Vec<Param>) -> Result<Value, CliError> {
88
let params_map = params::params_to_hashmap(params);
99
// Locations endpoint is public – no API key needed.
1010
let client = make_client("")?;
11-
let result = client
12-
.location(params_map)
13-
.await
14-
.map_err(network_err)?;
11+
let result = client.location(params_map).await.map_err(network_err)?;
1512
check_api_error(result)
1613
}

src/commands/login.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ use std::collections::HashMap;
55

66
/// Prompt the user for their SerpApi API key, verify it, and persist it to the config file.
77
pub async fn run() -> Result<(), CliError> {
8-
let api_key = rpassword::prompt_password("Enter your SerpApi API key: ")
9-
.map_err(|e| CliError::UsageError {
8+
let api_key = rpassword::prompt_password("Enter your SerpApi API key: ").map_err(|e| {
9+
CliError::UsageError {
1010
message: format!("Failed to read input: {e}"),
11-
})?;
11+
}
12+
})?;
1213
let api_key = api_key.trim();
1314

1415
if api_key.is_empty() {
@@ -18,10 +19,7 @@ pub async fn run() -> Result<(), CliError> {
1819
}
1920

2021
let client = make_client(api_key)?;
21-
let result = client
22-
.account(HashMap::new())
23-
.await
24-
.map_err(network_err)?;
22+
let result = client.account(HashMap::new()).await.map_err(network_err)?;
2523

2624
let result = check_api_error(result)?;
2725
let email = result

src/commands/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@ use std::collections::HashMap;
44

55
use crate::error::CliError;
66

7-
pub mod search;
87
pub mod account;
9-
pub mod locations;
108
pub mod archive;
9+
pub mod locations;
1110
pub mod login;
11+
pub mod search;
1212

1313
/// The query-parameter name used to pass the SerpApi key to every request.
1414
pub(crate) const API_KEY_PARAM: &str = "api_key";
1515

1616
/// Convert a `Box<dyn Error>` from the serpapi client into a [`CliError::NetworkError`].
1717
pub(crate) fn network_err(e: Box<dyn std::error::Error>) -> CliError {
18-
CliError::NetworkError { message: e.to_string() }
18+
CliError::NetworkError {
19+
message: e.to_string(),
20+
}
1921
}
2022

2123
/// Build a `serpapi::Client` authenticated with the given API key.

src/commands/search.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use std::collections::{HashMap, HashSet};
2-
use std::time::Duration;
3-
use url::Url;
41
use crate::commands::{check_api_error, make_client, network_err, API_KEY_PARAM};
52
use crate::error::CliError;
63
use crate::params::{self, Param};
74
use serde_json::Value;
5+
use std::collections::{HashMap, HashSet};
6+
use std::time::Duration;
7+
use url::Url;
88

99
/// Execute a SerpApi search, optionally accumulating all pages into a single result.
1010
pub async fn run(
@@ -19,13 +19,12 @@ pub async fn run(
1919

2020
if !all_pages && max_pages.is_none() {
2121
let client = make_client(api_key)?;
22-
let result = tokio::time::timeout(
23-
Duration::from_secs(30),
24-
client.search(params_map),
25-
)
26-
.await
27-
.map_err(|_| CliError::NetworkError { message: "Request timed out after 30s".to_string() })?
28-
.map_err(network_err)?;
22+
let result = tokio::time::timeout(Duration::from_secs(30), client.search(params_map))
23+
.await
24+
.map_err(|_| CliError::NetworkError {
25+
message: "Request timed out after 30s".to_string(),
26+
})?
27+
.map_err(network_err)?;
2928
return check_api_error(result);
3029
}
3130

@@ -45,7 +44,9 @@ pub async fn run(
4544
client.search(current_params.clone()),
4645
)
4746
.await
48-
.map_err(|_| CliError::NetworkError { message: "Request timed out after 30s".to_string() })?
47+
.map_err(|_| CliError::NetworkError {
48+
message: "Request timed out after 30s".to_string(),
49+
})?
4950
.map_err(network_err)?;
5051
let page = check_api_error(result)?;
5152
pages_fetched += 1;
@@ -67,8 +68,12 @@ pub async fn run(
6768
// are kept from the first page, as they describe the overall
6869
// query rather than per-page state.
6970
match acc_map.get_mut(key) {
70-
Some(Value::Array(existing)) => existing.extend(new_items.iter().cloned()),
71-
_ => { acc_map.insert(key.clone(), val.clone()); }
71+
Some(Value::Array(existing)) => {
72+
existing.extend(new_items.iter().cloned())
73+
}
74+
_ => {
75+
acc_map.insert(key.clone(), val.clone());
76+
}
7277
}
7378
}
7479
}

src/config.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use serde::{Deserialize, Serialize};
12
use std::fs;
23
use std::path::PathBuf;
3-
use serde::{Deserialize, Serialize};
44

55
#[derive(Serialize, Deserialize)]
66
struct Config {
@@ -43,10 +43,9 @@ pub fn save_config(api_key: &str) -> Result<(), crate::error::CliError> {
4343
}
4444
#[cfg(not(unix))]
4545
{
46-
std::fs::create_dir_all(&dir)
47-
.map_err(|e| crate::error::CliError::UsageError {
48-
message: format!("Failed to create config dir: {e}"),
49-
})?;
46+
std::fs::create_dir_all(&dir).map_err(|e| crate::error::CliError::UsageError {
47+
message: format!("Failed to create config dir: {e}"),
48+
})?;
5049
}
5150

5251
let config = Config {
@@ -69,7 +68,8 @@ pub fn save_config(api_key: &str) -> Result<(), crate::error::CliError> {
6968
.mode(0o600)
7069
.open(&tmp_path)
7170
.map_err(|e| to_cli_err(&e))?;
72-
file.write_all(content.as_bytes()).map_err(|e| to_cli_err(&e))?;
71+
file.write_all(content.as_bytes())
72+
.map_err(|e| to_cli_err(&e))?;
7373
}
7474
#[cfg(not(unix))]
7575
{
@@ -89,17 +89,15 @@ pub fn save_config(api_key: &str) -> Result<(), crate::error::CliError> {
8989

9090
/// Resolve the API key from the already-merged clap value (flag or env var), then
9191
/// fall back to the saved config file. The env-var lookup is handled by clap upstream.
92-
pub fn resolve_api_key(
93-
from_clap: Option<&str>,
94-
) -> Result<String, crate::error::CliError> {
92+
pub fn resolve_api_key(from_clap: Option<&str>) -> Result<String, crate::error::CliError> {
9593
if let Some(key) = from_clap {
9694
return Ok(key.to_string());
9795
}
98-
96+
9997
if let Some(key) = load_api_key() {
10098
return Ok(key);
10199
}
102-
100+
103101
Err(crate::error::CliError::UsageError {
104102
message: "No API key found. Run 'serpapi login' or set SERPAPI_KEY.".to_string(),
105103
})

src/error.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ pub fn print_error(err: &CliError) {
5252

5353
match serde_json::to_string_pretty(&error_json) {
5454
Ok(s) => eprintln!("{s}"),
55-
Err(_) => eprintln!("{{\"error\":{{\"code\":\"{code}\",\"message\":\"{}\"}}}}",
56-
message.replace('\\', "\\\\").replace('"', "\\\"")),
55+
Err(_) => eprintln!(
56+
"{{\"error\":{{\"code\":\"{code}\",\"message\":\"{}\"}}}}",
57+
message.replace('\\', "\\\\").replace('"', "\\\"")
58+
),
5759
}
5860
}
5961

src/jq.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ pub fn apply(expression: &str, input: Value) -> Result<Vec<Value>, Box<dyn std::
2424
let inputs = RcIter::new(std::iter::empty());
2525
let out: Vec<Value> = filter
2626
.run((Ctx::new(Vec::new(), &inputs), Val::from(input)))
27-
.map(|v| v.map(Value::from).map_err(|e| format!("jq runtime error: {e}")))
27+
.map(|v| {
28+
v.map(Value::from)
29+
.map_err(|e| format!("jq runtime error: {e}"))
30+
})
2831
.collect::<Result<Vec<_>, _>>()?;
2932

3033
Ok(out)

0 commit comments

Comments
 (0)