Skip to content

Commit 37a2837

Browse files
author
lex
committed
style: apply cargo fmt across all crates
Bulk formatting fix to ensure CI cargo fmt --all --check passes.
1 parent 2188a78 commit 37a2837

44 files changed

Lines changed: 3508 additions & 1307 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/poste-cli/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ fn main() {
88
.unwrap_or_else(|| "unknown".to_string());
99

1010
println!("cargo:rustc-env=POSTE_TAG={tag}");
11-
}
11+
}

crates/poste-cli/src/connection.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::Result;
22
use clap::Parser;
33

4-
use poste_exec::sql_connection::{ConnectionStore, test_connection};
4+
use poste_exec::sql_connection::{test_connection, ConnectionStore};
55

66
#[derive(Parser)]
77
pub enum ConnectionAction {
@@ -73,7 +73,10 @@ pub async fn execute(action: ConnectionAction) -> Result<()> {
7373
let host = item["host"].as_str().unwrap_or("?");
7474
let port = item["port"].as_u64().unwrap_or(0);
7575
let db = item["database"].as_str().unwrap_or("?");
76-
println!(" {} {} ({}) — {}:{}/{}", icon, name, dialect, host, port, db);
76+
println!(
77+
" {} {} ({}) — {}:{}/{}",
78+
icon, name, dialect, host, port, db
79+
);
7780
}
7881

7982
// Show resolved URL
@@ -92,16 +95,27 @@ pub async fn execute(action: ConnectionAction) -> Result<()> {
9295
let store = ConnectionStore::load(&search_dir)?;
9396
let env_vars = crate::run::load_env_vars(&search_dir, &env);
9497

95-
let config = store.get(&name)
98+
let config = store
99+
.get(&name)
96100
.ok_or_else(|| anyhow::anyhow!("Connection '{}' not found", name))?;
97101

98102
// Resolve variables
99103
let mut resolved = config.clone();
100-
resolved.host = resolved.host.map(|s| poste_core::substitute_vars(&s, &env_vars));
101-
resolved.password = resolved.password.map(|s| poste_core::substitute_vars(&s, &env_vars));
102-
resolved.user = resolved.user.map(|s| poste_core::substitute_vars(&s, &env_vars));
103-
resolved.database = resolved.database.map(|s| poste_core::substitute_vars(&s, &env_vars));
104-
resolved.path = resolved.path.map(|s| poste_core::substitute_vars(&s, &env_vars));
104+
resolved.host = resolved
105+
.host
106+
.map(|s| poste_core::substitute_vars(&s, &env_vars));
107+
resolved.password = resolved
108+
.password
109+
.map(|s| poste_core::substitute_vars(&s, &env_vars));
110+
resolved.user = resolved
111+
.user
112+
.map(|s| poste_core::substitute_vars(&s, &env_vars));
113+
resolved.database = resolved
114+
.database
115+
.map(|s| poste_core::substitute_vars(&s, &env_vars));
116+
resolved.path = resolved
117+
.path
118+
.map(|s| poste_core::substitute_vars(&s, &env_vars));
105119

106120
print!("Testing connection '{}' ... ", name);
107121
std::io::Write::flush(&mut std::io::stdout())?;

crates/poste-cli/src/context.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ pub(crate) fn make_detect_response(result: &ContextResult) -> ContextDetectRespo
6060
sql_context::ContextType::SchemaTable { schema } => Some(schema.clone()),
6161
_ => None,
6262
};
63-
let tables: Vec<TableRefInfo> = result.tables.iter().map(|t| TableRefInfo {
64-
name: t.name.clone(),
65-
alias: t.alias.clone(),
66-
schema: t.schema.clone(),
67-
}).collect();
63+
let tables: Vec<TableRefInfo> = result
64+
.tables
65+
.iter()
66+
.map(|t| TableRefInfo {
67+
name: t.name.clone(),
68+
alias: t.alias.clone(),
69+
schema: t.schema.clone(),
70+
})
71+
.collect();
6872
ContextDetectResponse {
6973
version: 1,
7074
ctx_type,
@@ -112,8 +116,14 @@ pub fn execute(action: ContextAction) -> Result<()> {
112116
let lines: Vec<&str> = input.lines().collect();
113117
let span = sql_context::find_statement_span(&lines, cursor_line);
114118
let response = match span {
115-
Some((start, end)) => ContextStmtResponse { start_line: start, end_line: end },
116-
None => ContextStmtResponse { start_line: 0, end_line: 0 },
119+
Some((start, end)) => ContextStmtResponse {
120+
start_line: start,
121+
end_line: end,
122+
},
123+
None => ContextStmtResponse {
124+
start_line: 0,
125+
end_line: 0,
126+
},
117127
};
118128
println!("{}", serde_json::to_string(&response)?);
119129
}

crates/poste-cli/src/import.rs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,24 @@ pub enum ImportSource {
3030
}
3131

3232
pub fn execute(source: ImportSource) -> Result<()> {
33-
let (file, out_dir, importer): (String, String, Box<dyn poste_core::import::SpecImporter>) = match source {
34-
ImportSource::Openapi { file, out } => {
35-
(file, out, Box::new(poste_core::import::openapi::OpenApiImporter::new()))
36-
}
37-
ImportSource::Swagger { file, out } => {
38-
(file, out, Box::new(poste_core::import::swagger::SwaggerImporter))
39-
}
40-
ImportSource::Postman { file, out } => {
41-
(file, out, Box::new(poste_core::import::postman::PostmanImporter))
42-
}
43-
};
33+
let (file, out_dir, importer): (String, String, Box<dyn poste_core::import::SpecImporter>) =
34+
match source {
35+
ImportSource::Openapi { file, out } => (
36+
file,
37+
out,
38+
Box::new(poste_core::import::openapi::OpenApiImporter::new()),
39+
),
40+
ImportSource::Swagger { file, out } => (
41+
file,
42+
out,
43+
Box::new(poste_core::import::swagger::SwaggerImporter),
44+
),
45+
ImportSource::Postman { file, out } => (
46+
file,
47+
out,
48+
Box::new(poste_core::import::postman::PostmanImporter),
49+
),
50+
};
4451

4552
let spec_content = std::fs::read_to_string(&file)
4653
.map_err(|e| anyhow::anyhow!("Cannot read spec file '{}': {}", file, e))?;
@@ -53,11 +60,15 @@ pub fn execute(source: ImportSource) -> Result<()> {
5360
for http_file in &result.files {
5461
let full_path = out_path.join(&http_file.path);
5562
if let Some(parent) = full_path.parent() {
56-
std::fs::create_dir_all(parent)
57-
.map_err(|e| anyhow::anyhow!("Cannot create subdirectory '{}': {}", parent.display(), e))?;
63+
std::fs::create_dir_all(parent).map_err(|e| {
64+
anyhow::anyhow!("Cannot create subdirectory '{}': {}", parent.display(), e)
65+
})?;
5866
}
5967
if full_path.exists() {
60-
eprintln!("[poste import] warning: overwriting {}", full_path.display());
68+
eprintln!(
69+
"[poste import] warning: overwriting {}",
70+
full_path.display()
71+
);
6172
}
6273
std::fs::write(&full_path, &http_file.content)
6374
.map_err(|e| anyhow::anyhow!("Cannot write '{}': {}", full_path.display(), e))?;
@@ -72,7 +83,11 @@ pub fn execute(source: ImportSource) -> Result<()> {
7283
std::fs::write(&env_path, &env_content)?;
7384
}
7485

75-
println!("OK — imported {} file(s) to {}", result.files.len(), out_dir);
86+
println!(
87+
"OK — imported {} file(s) to {}",
88+
result.files.len(),
89+
out_dir
90+
);
7691
if !result.env_vars.is_empty() {
7792
println!(" env.json: {} variable(s)", result.env_vars.len());
7893
}

crates/poste-cli/src/introspect.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,21 @@ pub async fn execute(args: IntrospectArgs) -> Result<()> {
4444

4545
// Resolve variables and build URL
4646
let mut resolved = config.clone();
47-
resolved.host = resolved.host.map(|s| poste_core::substitute_vars(&s, &env_vars));
48-
resolved.password = resolved.password.map(|s| poste_core::substitute_vars(&s, &env_vars));
49-
resolved.user = resolved.user.map(|s| poste_core::substitute_vars(&s, &env_vars));
50-
resolved.database = resolved.database.map(|s| poste_core::substitute_vars(&s, &env_vars));
51-
resolved.path = resolved.path.map(|s| poste_core::substitute_vars(&s, &env_vars));
47+
resolved.host = resolved
48+
.host
49+
.map(|s| poste_core::substitute_vars(&s, &env_vars));
50+
resolved.password = resolved
51+
.password
52+
.map(|s| poste_core::substitute_vars(&s, &env_vars));
53+
resolved.user = resolved
54+
.user
55+
.map(|s| poste_core::substitute_vars(&s, &env_vars));
56+
resolved.database = resolved
57+
.database
58+
.map(|s| poste_core::substitute_vars(&s, &env_vars));
59+
resolved.path = resolved
60+
.path
61+
.map(|s| poste_core::substitute_vars(&s, &env_vars));
5262

5363
let mut connection_url = resolved.to_url();
5464
let dialect_name = resolved.dialect.clone();

crates/poste-cli/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use clap::{Parser, Subcommand};
21
use anyhow::Result;
2+
use clap::{Parser, Subcommand};
33

4-
mod run;
5-
mod context;
64
mod connection;
5+
mod context;
76
mod fmt;
87
mod import;
98
mod introspect;
9+
mod run;
1010
mod serve;
1111
mod util;
1212

crates/poste-cli/src/run.rs

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ pub async fn execute(args: RunArgs) -> Result<()> {
4141
.and_then(|e| e.to_str())
4242
.unwrap_or("http")
4343
.to_string();
44-
let dir = abs.parent()
44+
let dir = abs
45+
.parent()
4546
.unwrap_or_else(|| std::path::Path::new("."))
4647
.to_path_buf();
4748
(dir, ext)
@@ -59,7 +60,10 @@ pub async fn execute(args: RunArgs) -> Result<()> {
5960
.and_then(|e| e.to_str())
6061
.unwrap_or("http")
6162
.to_string();
62-
let dir = canonical.parent().context("File path resolves to root")?.to_path_buf();
63+
let dir = canonical
64+
.parent()
65+
.context("File path resolves to root")?
66+
.to_path_buf();
6367
(dir, ext)
6468
};
6569

@@ -68,7 +72,11 @@ pub async fn execute(args: RunArgs) -> Result<()> {
6872
let env_vars = loop {
6973
let candidate = dir.join("env.json");
7074
if candidate.exists() {
71-
let env_file = poste_core::Environment::load(candidate.to_str().context("env.json path is not valid UTF-8")?)?;
75+
let env_file = poste_core::Environment::load(
76+
candidate
77+
.to_str()
78+
.context("env.json path is not valid UTF-8")?,
79+
)?;
7280
let vars = env_file.envs.get(&args.env).cloned().unwrap_or_default();
7381
break vars;
7482
}
@@ -84,8 +92,7 @@ pub async fn execute(args: RunArgs) -> Result<()> {
8492
std::io::stdin().read_to_string(&mut buf)?;
8593
buf
8694
} else {
87-
let canonical = std::fs::canonicalize(&file_path)
88-
.unwrap_or(file_path.clone());
95+
let canonical = std::fs::canonicalize(&file_path).unwrap_or(file_path.clone());
8996
std::fs::read_to_string(&canonical)?
9097
};
9198

@@ -94,10 +101,14 @@ pub async fn execute(args: RunArgs) -> Result<()> {
94101
let mut request = parser.parse_at_line(&content, args.line, &file_ext)?;
95102

96103
// Resolve connection name for SQL protocols
97-
if crate::util::is_sql_protocol(&request.protocol) && !crate::util::is_connection_url(&request.connection) && !request.connection.is_empty() {
104+
if crate::util::is_sql_protocol(&request.protocol)
105+
&& !crate::util::is_connection_url(&request.connection)
106+
&& !request.connection.is_empty()
107+
{
98108
let conn_name = request.connection.clone();
99109
let conn_store = poste_exec::sql_connection::ConnectionStore::load(&search_dir)?;
100-
request.connection = conn_store.resolve(&conn_name, &env_vars)
110+
request.connection = conn_store
111+
.resolve(&conn_name, &env_vars)
101112
.map_err(|e| anyhow::anyhow!("Failed to resolve connection '{}': {}", conn_name, e))?;
102113
}
103114

@@ -109,10 +120,14 @@ pub async fn execute(args: RunArgs) -> Result<()> {
109120
}
110121

111122
// Auto-detect protocol from connection URL for .sql files
112-
if request.protocol == poste_core::Protocol::Postgres && request.connection.starts_with("sqlite:") {
123+
if request.protocol == poste_core::Protocol::Postgres
124+
&& request.connection.starts_with("sqlite:")
125+
{
113126
request.protocol = poste_core::Protocol::Sqlite;
114127
}
115-
if request.protocol == poste_core::Protocol::Postgres && request.connection.starts_with("mysql://") {
128+
if request.protocol == poste_core::Protocol::Postgres
129+
&& request.connection.starts_with("mysql://")
130+
{
116131
request.protocol = poste_core::Protocol::Mysql;
117132
}
118133

@@ -141,7 +156,10 @@ pub async fn execute(args: RunArgs) -> Result<()> {
141156
if !response.cookies.is_empty() {
142157
println!("Cookies:");
143158
for c in &response.cookies {
144-
println!(" {}={} (domain={}, path={})", c.name, c.value, c.domain, c.path);
159+
println!(
160+
" {}={} (domain={}, path={})",
161+
c.name, c.value, c.domain, c.path
162+
);
145163
}
146164
}
147165
println!("Headers:");
@@ -165,12 +183,19 @@ pub async fn execute(args: RunArgs) -> Result<()> {
165183
}
166184

167185
/// Load env vars for variable substitution.
168-
pub fn load_env_vars(search_dir: &std::path::Path, env_name: &str) -> std::collections::HashMap<String, String> {
186+
pub fn load_env_vars(
187+
search_dir: &std::path::Path,
188+
env_name: &str,
189+
) -> std::collections::HashMap<String, String> {
169190
let mut dir = search_dir;
170191
loop {
171192
let candidate = dir.join("env.json");
172193
if candidate.exists() {
173-
if let Ok(env_file) = poste_core::Environment::load(candidate.to_str().expect("env.json path must be valid UTF-8")) {
194+
if let Ok(env_file) = poste_core::Environment::load(
195+
candidate
196+
.to_str()
197+
.expect("env.json path must be valid UTF-8"),
198+
) {
174199
if let Some(vars) = env_file.envs.get(env_name) {
175200
return vars.clone();
176201
}

0 commit comments

Comments
 (0)