Skip to content

Commit 5649434

Browse files
committed
Apply cargo fmt to all source files
1 parent fe9ce7a commit 5649434

4 files changed

Lines changed: 80 additions & 71 deletions

File tree

src/client.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{bail, Context, Result};
1+
use anyhow::{Context, Result, bail};
22
use indicatif::{ProgressBar, ProgressStyle};
33
use reqwest::header::{HeaderMap, HeaderValue};
44
use std::time::Duration;
@@ -14,10 +14,9 @@ pub struct Client {
1414

1515
impl Client {
1616
pub fn new(settings: &Settings, json_mode: bool) -> Result<Self> {
17-
let api_key = settings
18-
.api_key
19-
.as_deref()
20-
.context("API key is required — set it via --api-key, PLANE_CLI_API_KEY, or config file")?;
17+
let api_key = settings.api_key.as_deref().context(
18+
"API key is required — set it via --api-key, PLANE_CLI_API_KEY, or config file",
19+
)?;
2120

2221
let mut headers = HeaderMap::new();
2322
headers.insert(
@@ -97,7 +96,6 @@ impl Client {
9796
}
9897
result
9998
}
100-
10199
}
102100

103101
async fn handle_response(response: reqwest::Response) -> Result<serde_json::Value> {
@@ -184,7 +182,9 @@ mod tests {
184182
.and(path("/api/v1/items"))
185183
.and(query_param("per_page", "10"))
186184
.and(query_param("state", "active"))
187-
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({"results": []})))
185+
.respond_with(
186+
ResponseTemplate::new(200).set_body_json(serde_json::json!({"results": []})),
187+
)
188188
.expect(1)
189189
.mount(&mock_server)
190190
.await;
@@ -204,7 +204,9 @@ mod tests {
204204
Mock::given(method("POST"))
205205
.and(path("/api/v1/issues"))
206206
.and(body_json(&body))
207-
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({"id": "123"})))
207+
.respond_with(
208+
ResponseTemplate::new(200).set_body_json(serde_json::json!({"id": "123"})),
209+
)
208210
.expect(1)
209211
.mount(&mock_server)
210212
.await;

src/main.rs

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ mod settings;
33

44
use anyhow::{Context, Result};
55
use clap::{Parser, Subcommand};
6-
use comfy_table::{presets::UTF8_BORDERS_ONLY, Cell, Color, Table};
76
use client::Client;
7+
use comfy_table::{Cell, Color, Table, presets::UTF8_BORDERS_ONLY};
88
use settings::{CliOverrides, Settings};
99

1010
#[derive(Parser)]
@@ -192,10 +192,9 @@ async fn main() -> Result<()> {
192192
timeout: cli.timeout,
193193
})?;
194194

195-
let workspace = settings
196-
.workspace
197-
.as_deref()
198-
.context("workspace is required — set it via --workspace, PLANE_CLI_WORKSPACE, or config file")?;
195+
let workspace = settings.workspace.as_deref().context(
196+
"workspace is required — set it via --workspace, PLANE_CLI_WORKSPACE, or config file",
197+
)?;
199198

200199
let client = Client::new(&settings, json_mode)?;
201200

@@ -223,7 +222,8 @@ async fn main() -> Result<()> {
223222
table.set_header(vec![header("Name"), header("Identifier"), header("ID")]);
224223
for project in results {
225224
table.add_row(vec![
226-
Cell::new(project["name"].as_str().unwrap_or("(unnamed)")).fg(Color::White),
225+
Cell::new(project["name"].as_str().unwrap_or("(unnamed)"))
226+
.fg(Color::White),
227227
Cell::new(project["identifier"].as_str().unwrap_or("")),
228228
Cell::new(project["id"].as_str().unwrap_or("")).fg(Color::DarkGrey),
229229
]);
@@ -235,7 +235,9 @@ async fn main() -> Result<()> {
235235
Command::States { action } => match action {
236236
StatesAction::List { project } => {
237237
let data = client
238-
.get(&format!("workspaces/{workspace}/projects/{project}/states/"))
238+
.get(&format!(
239+
"workspaces/{workspace}/projects/{project}/states/"
240+
))
239241
.await?;
240242

241243
if json_mode {
@@ -255,7 +257,8 @@ async fn main() -> Result<()> {
255257
table.set_header(vec![header("Name"), header("Group"), header("ID")]);
256258
for state in results {
257259
table.add_row(vec![
258-
Cell::new(state["name"].as_str().unwrap_or("(unnamed)")).fg(Color::White),
260+
Cell::new(state["name"].as_str().unwrap_or("(unnamed)"))
261+
.fg(Color::White),
259262
Cell::new(state["group"].as_str().unwrap_or("")),
260263
Cell::new(state["id"].as_str().unwrap_or("")).fg(Color::DarkGrey),
261264
]);
@@ -267,7 +270,9 @@ async fn main() -> Result<()> {
267270
Command::Labels { action } => match action {
268271
LabelsAction::List { project } => {
269272
let data = client
270-
.get(&format!("workspaces/{workspace}/projects/{project}/labels/"))
273+
.get(&format!(
274+
"workspaces/{workspace}/projects/{project}/labels/"
275+
))
271276
.await?;
272277

273278
if json_mode {
@@ -287,7 +292,8 @@ async fn main() -> Result<()> {
287292
table.set_header(vec![header("Name"), header("ID")]);
288293
for label in results {
289294
table.add_row(vec![
290-
Cell::new(label["name"].as_str().unwrap_or("(unnamed)")).fg(Color::White),
295+
Cell::new(label["name"].as_str().unwrap_or("(unnamed)"))
296+
.fg(Color::White),
291297
Cell::new(label["id"].as_str().unwrap_or("")).fg(Color::DarkGrey),
292298
]);
293299
}
@@ -298,19 +304,19 @@ async fn main() -> Result<()> {
298304
Command::Members { action } => match action {
299305
MembersAction::List { project } => {
300306
let data = client
301-
.get(&format!("workspaces/{workspace}/projects/{project}/members/"))
307+
.get(&format!(
308+
"workspaces/{workspace}/projects/{project}/members/"
309+
))
302310
.await?;
303311

304312
if json_mode {
305313
println!("{}", serde_json::to_string_pretty(&data)?);
306314
} else {
307315
let results = match data.as_array() {
308316
Some(arr) => arr,
309-
None => {
310-
data["results"]
311-
.as_array()
312-
.context("unexpected response format")?
313-
}
317+
None => data["results"]
318+
.as_array()
319+
.context("unexpected response format")?,
314320
};
315321

316322
if results.is_empty() {
@@ -323,7 +329,8 @@ async fn main() -> Result<()> {
323329
table.set_header(vec![header("Name"), header("ID")]);
324330
for member in results {
325331
table.add_row(vec![
326-
Cell::new(member["display_name"].as_str().unwrap_or("(unnamed)")).fg(Color::White),
332+
Cell::new(member["display_name"].as_str().unwrap_or("(unnamed)"))
333+
.fg(Color::White),
327334
Cell::new(member["id"].as_str().unwrap_or("")).fg(Color::DarkGrey),
328335
]);
329336
}
@@ -372,7 +379,12 @@ async fn main() -> Result<()> {
372379

373380
let mut table = Table::new();
374381
table.load_preset(UTF8_BORDERS_ONLY);
375-
table.set_header(vec![header("#"), header("Name"), header("Priority"), header("ID")]);
382+
table.set_header(vec![
383+
header("#"),
384+
header("Name"),
385+
header("Priority"),
386+
header("ID"),
387+
]);
376388
for issue in results {
377389
let prio = issue["priority"].as_str().unwrap_or("none");
378390
table.add_row(vec![
@@ -411,20 +423,14 @@ async fn main() -> Result<()> {
411423
println!(" {} {created}", cyan.apply_to("created: "));
412424

413425
if let Some(assignees) = data["assignees"].as_array() {
414-
let ids: Vec<&str> = assignees
415-
.iter()
416-
.filter_map(|a| a.as_str())
417-
.collect();
426+
let ids: Vec<&str> = assignees.iter().filter_map(|a| a.as_str()).collect();
418427
if !ids.is_empty() {
419428
println!(" {} {}", cyan.apply_to("assignees:"), ids.join(", "));
420429
}
421430
}
422431

423432
if let Some(labels) = data["labels"].as_array() {
424-
let ids: Vec<&str> = labels
425-
.iter()
426-
.filter_map(|l| l.as_str())
427-
.collect();
433+
let ids: Vec<&str> = labels.iter().filter_map(|l| l.as_str()).collect();
428434
if !ids.is_empty() {
429435
println!(" {} {}", cyan.apply_to("labels: "), ids.join(", "));
430436
}

src/settings.rs

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ fn merge_file(base: &mut serde_json::Value, path: &Path) -> Result<()> {
6868
}
6969
};
7070

71-
let overlay: serde_json::Value =
72-
serde_json::from_str(&content).with_context(|| format!("invalid JSON in {}", path.display()))?;
71+
let overlay: serde_json::Value = serde_json::from_str(&content)
72+
.with_context(|| format!("invalid JSON in {}", path.display()))?;
7373

7474
deep_merge(base, &overlay);
7575
Ok(())
@@ -173,7 +173,10 @@ mod tests {
173173
let mut base = serde_json::json!({"outer": {"a": 1, "b": 2}});
174174
let overlay = serde_json::json!({"outer": {"b": 99, "c": 3}});
175175
deep_merge(&mut base, &overlay);
176-
assert_eq!(base, serde_json::json!({"outer": {"a": 1, "b": 99, "c": 3}}));
176+
assert_eq!(
177+
base,
178+
serde_json::json!({"outer": {"a": 1, "b": 99, "c": 3}})
179+
);
177180
}
178181

179182
// ── merge_file ──
@@ -340,11 +343,7 @@ mod tests {
340343
let dir = TempDir::new().unwrap();
341344
let config_dir = dir.path().join("config");
342345
std::fs::create_dir_all(&config_dir).unwrap();
343-
std::fs::write(
344-
config_dir.join("settings.json"),
345-
r#"{"timeout": 60}"#,
346-
)
347-
.unwrap();
346+
std::fs::write(config_dir.join("settings.json"), r#"{"timeout": 60}"#).unwrap();
348347

349348
temp_env::with_vars(
350349
[
@@ -373,11 +372,7 @@ mod tests {
373372
r#"{"timeout": 60, "base_url": "https://base.api"}"#,
374373
)
375374
.unwrap();
376-
std::fs::write(
377-
config_dir.join("settings.local.json"),
378-
r#"{"timeout": 90}"#,
379-
)
380-
.unwrap();
375+
std::fs::write(config_dir.join("settings.local.json"), r#"{"timeout": 90}"#).unwrap();
381376

382377
temp_env::with_vars(
383378
[
@@ -401,11 +396,7 @@ mod tests {
401396
let dir = TempDir::new().unwrap();
402397
let config_dir = dir.path().join("config");
403398
std::fs::create_dir_all(&config_dir).unwrap();
404-
std::fs::write(
405-
config_dir.join("settings.json"),
406-
r#"{"timeout": 60}"#,
407-
)
408-
.unwrap();
399+
std::fs::write(config_dir.join("settings.json"), r#"{"timeout": 60}"#).unwrap();
409400

410401
temp_env::with_vars(
411402
[
@@ -428,11 +419,7 @@ mod tests {
428419
let dir = TempDir::new().unwrap();
429420
let config_dir = dir.path().join("config");
430421
std::fs::create_dir_all(&config_dir).unwrap();
431-
std::fs::write(
432-
config_dir.join("settings.json"),
433-
r#"{"timeout": 60}"#,
434-
)
435-
.unwrap();
422+
std::fs::write(config_dir.join("settings.json"), r#"{"timeout": 60}"#).unwrap();
436423

437424
temp_env::with_vars(
438425
[

tests/cli.rs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,15 @@ async fn test_projects_list_json() {
3030

3131
plane_cmd()
3232
.args([
33-
"--api-key", "test",
34-
"--workspace", "test-ws",
35-
"--base-url", &mock_server.uri(),
33+
"--api-key",
34+
"test",
35+
"--workspace",
36+
"test-ws",
37+
"--base-url",
38+
&mock_server.uri(),
3639
"--json",
37-
"projects", "list",
40+
"projects",
41+
"list",
3842
])
3943
.assert()
4044
.success()
@@ -56,10 +60,14 @@ async fn test_projects_list_table() {
5660

5761
plane_cmd()
5862
.args([
59-
"--api-key", "test",
60-
"--workspace", "test-ws",
61-
"--base-url", &mock_server.uri(),
62-
"projects", "list",
63+
"--api-key",
64+
"test",
65+
"--workspace",
66+
"test-ws",
67+
"--base-url",
68+
&mock_server.uri(),
69+
"projects",
70+
"list",
6371
])
6472
.assert()
6573
.success()
@@ -103,13 +111,19 @@ async fn test_issues_create_json() {
103111

104112
plane_cmd()
105113
.args([
106-
"--api-key", "test",
107-
"--workspace", "test-ws",
108-
"--base-url", &mock_server.uri(),
114+
"--api-key",
115+
"test",
116+
"--workspace",
117+
"test-ws",
118+
"--base-url",
119+
&mock_server.uri(),
109120
"--json",
110-
"issues", "create",
111-
"--project", "proj1",
112-
"--title", "New Bug",
121+
"issues",
122+
"create",
123+
"--project",
124+
"proj1",
125+
"--title",
126+
"New Bug",
113127
])
114128
.assert()
115129
.success()

0 commit comments

Comments
 (0)