Skip to content

Commit bb6b9e0

Browse files
committed
style: reformat code
1 parent d75180f commit bb6b9e0

File tree

6 files changed

+135
-48
lines changed

6 files changed

+135
-48
lines changed

src/commands.rs

+68-22
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ use crate::utils::*;
1212
use crate::variables;
1313

1414
/// Run tool's command
15-
pub fn run_command<W: Write>(command: &Commands, config: Option<Config>, mut buffer: W) -> ExitCode {
15+
pub fn run_command<W: Write>(
16+
command: &Commands,
17+
config: Option<Config>,
18+
mut buffer: W,
19+
) -> ExitCode {
1620
match command {
1721
Commands::InitConfig => {
1822
if let Err(error) = config::init_config(config::get_config_file_path(), buffer) {
@@ -31,9 +35,11 @@ pub fn run_command<W: Write>(command: &Commands, config: Option<Config>, mut buf
3135
0.6,
3236
);
3337
if !similar_names.is_empty() {
34-
writeln!(&mut buffer, "Did you mean:").expect("Failed to write to buffer");
38+
writeln!(&mut buffer, "Did you mean:")
39+
.expect("Failed to write to buffer");
3540
for name in similar_names {
36-
writeln!(&mut buffer, " {}", &name).expect("Failed to write to buffer");
41+
writeln!(&mut buffer, " {}", &name)
42+
.expect("Failed to write to buffer");
3743
}
3844
}
3945
}
@@ -211,9 +217,13 @@ mod tests {
211217
no_similar_names: false,
212218
}),
213219
None,
214-
&mut buffer
220+
&mut buffer,
221+
);
222+
assert!(
223+
String::from_utf8(buffer)
224+
.unwrap()
225+
.contains("\"test_value\"")
215226
);
216-
assert!(String::from_utf8(buffer).unwrap().contains("\"test_value\""));
217227
unsafe { env::remove_var("TEST_RUN_VAR") };
218228
}
219229

@@ -246,7 +256,7 @@ mod tests {
246256
process: None,
247257
}),
248258
None,
249-
&mut buffer
259+
&mut buffer,
250260
);
251261

252262
assert_eq!(env::var("TEST_SET_RUN").unwrap(), "test_value");
@@ -267,7 +277,7 @@ mod tests {
267277
process: None,
268278
}),
269279
None,
270-
&mut buffer
280+
&mut buffer,
271281
);
272282
assert_eq!(env::var("TEST_ADD_RUN").unwrap(), "initial_value");
273283
unsafe { env::remove_var("TEST_ADD_RUN") };
@@ -278,8 +288,16 @@ mod tests {
278288
init();
279289
unsafe { env::set_var("TEST_PRINT_RUN", "test_value") };
280290
let mut buffer = vec![];
281-
run_command(&Commands::Print(PrintArgs { format: None }), None, &mut buffer);
282-
assert!(String::from_utf8(buffer).unwrap().contains("TEST_PRINT_RUN = \"test_value\""));
291+
run_command(
292+
&Commands::Print(PrintArgs { format: None }),
293+
None,
294+
&mut buffer,
295+
);
296+
assert!(
297+
String::from_utf8(buffer)
298+
.unwrap()
299+
.contains("TEST_PRINT_RUN = \"test_value\"")
300+
);
283301

284302
unsafe { env::remove_var("TEST_PRINT_RUN") };
285303
}
@@ -294,9 +312,13 @@ mod tests {
294312
format: Some("{name} = {value}".to_owned()),
295313
}),
296314
None,
297-
&mut buffer
315+
&mut buffer,
316+
);
317+
assert!(
318+
String::from_utf8(buffer)
319+
.unwrap()
320+
.contains("TEST_PRINT_RUN = test_value")
298321
);
299-
assert!(String::from_utf8(buffer).unwrap().contains("TEST_PRINT_RUN = test_value"));
300322
unsafe { env::remove_var("TEST_PRINT_RUN") };
301323
}
302324

@@ -312,7 +334,7 @@ mod tests {
312334
process: None,
313335
}),
314336
None,
315-
&mut buffer
337+
&mut buffer,
316338
);
317339

318340
assert!(env::var("TEST_DELETE_RUN").is_err());
@@ -331,7 +353,7 @@ mod tests {
331353
process: None,
332354
}),
333355
None,
334-
&mut buffer
356+
&mut buffer,
335357
);
336358

337359
assert_eq!(env::var("TEST_LOAD_RUN").unwrap(), "test_value");
@@ -346,7 +368,11 @@ mod tests {
346368

347369
let mut buffer = vec![];
348370
print_env(&PrintArgs { format: None }, &mut buffer);
349-
assert!(String::from_utf8(buffer).unwrap().contains("TEST_PRINT_VAR = \"test_value\""));
371+
assert!(
372+
String::from_utf8(buffer)
373+
.unwrap()
374+
.contains("TEST_PRINT_VAR = \"test_value\"")
375+
);
350376

351377
// Clean up
352378
unsafe { env::remove_var("TEST_PRINT_VAR") };
@@ -361,8 +387,16 @@ mod tests {
361387

362388
let mut buffer = vec![];
363389
print_env(&PrintArgs { format: None }, &mut buffer);
364-
assert!(String::from_utf8(buffer.clone()).unwrap().contains("TEST_VAR_1 = \"value1\""));
365-
assert!(String::from_utf8(buffer).unwrap().contains("TEST_VAR_2 = \"value2\""));
390+
assert!(
391+
String::from_utf8(buffer.clone())
392+
.unwrap()
393+
.contains("TEST_VAR_1 = \"value1\"")
394+
);
395+
assert!(
396+
String::from_utf8(buffer)
397+
.unwrap()
398+
.contains("TEST_VAR_2 = \"value2\"")
399+
);
366400

367401
// Clean up
368402
unsafe { env::remove_var("TEST_VAR_1") };
@@ -382,7 +416,11 @@ mod tests {
382416

383417
let result = get(&args, &mut buffer);
384418
assert!(result.is_ok());
385-
assert!(String::from_utf8(buffer).unwrap().contains("\"test_value\""));
419+
assert!(
420+
String::from_utf8(buffer)
421+
.unwrap()
422+
.contains("\"test_value\"")
423+
);
386424

387425
unsafe { env::remove_var("TEST_GET_VAR") };
388426
}
@@ -808,10 +846,18 @@ mod tests {
808846
unsafe { env::set_var("TEST_PRINT_ENV", "test_value") };
809847
let mut buffer = vec![];
810848
assert_eq!(
811-
run_command(&Commands::Print(PrintArgs { format: None }), None, &mut buffer),
849+
run_command(
850+
&Commands::Print(PrintArgs { format: None }),
851+
None,
852+
&mut buffer
853+
),
812854
ExitCode::SUCCESS
813855
);
814-
assert!(String::from_utf8(buffer).unwrap().contains("TEST_PRINT_ENV = \"test_value\""));
856+
assert!(
857+
String::from_utf8(buffer)
858+
.unwrap()
859+
.contains("TEST_PRINT_ENV = \"test_value\"")
860+
);
815861
unsafe { env::remove_var("TEST_PRINT_ENV") };
816862
}
817863

@@ -956,7 +1002,7 @@ mod tests {
9561002
init();
9571003
let mut temp_file = tempfile::NamedTempFile::new().unwrap();
9581004
writeln!(temp_file, "TEST_LOAD_PROC=test_value").unwrap();
959-
1005+
9601006
let mut buffer = vec![];
9611007
assert_eq!(
9621008
run_command(
@@ -986,7 +1032,7 @@ mod tests {
9861032
process: None,
9871033
}),
9881034
None,
989-
&mut buffer
1035+
&mut buffer,
9901036
);
9911037
// Test passes if operation succeeds OR fails with permission error
9921038
match result {
@@ -1014,7 +1060,7 @@ mod tests {
10141060
fn test_run_command_delete_with_process_fail() {
10151061
init();
10161062
unsafe { env::set_var("TEST_DELETE_PROC_FAIL", "test_value") };
1017-
1063+
10181064
let mut buffer = vec![];
10191065
assert_eq!(
10201066
run_command(

src/config.rs

+28-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
use std::{fs, io::{self, Write}, path::PathBuf};
1+
use std::{
2+
fs,
3+
io::{self, Write},
4+
path::PathBuf,
5+
};
26

37
use dirs::config_dir;
48

@@ -36,8 +40,14 @@ fn read_config(content: String) -> Result<Config, ConfigParsingError> {
3640
pub fn init_config<W: Write>(path: PathBuf, mut buffer: W) -> io::Result<()> {
3741
let default = default_config();
3842

39-
fs::write(&path, default)
40-
.map(|_| writeln!(buffer, "Successfully initialized config at {}", path.display()).expect("Failed to write to buffer"))
43+
fs::write(&path, default).map(|_| {
44+
writeln!(
45+
buffer,
46+
"Successfully initialized config at {}",
47+
path.display()
48+
)
49+
.expect("Failed to write to buffer")
50+
})
4151
}
4252

4353
/// Get default config ile content
@@ -58,30 +68,32 @@ mod tests {
5868

5969
#[test]
6070
fn test_get_config_file() {
61-
assert_eq!(get_config_file_path(), config_dir().unwrap_or_default().join("envfetch.toml"));
71+
assert_eq!(
72+
get_config_file_path(),
73+
config_dir().unwrap_or_default().join("envfetch.toml")
74+
);
6275
}
6376

6477
#[test]
6578
fn test_default_config() {
66-
assert_eq!(default_config(), include_str!("../assets/default_config.toml"));
79+
assert_eq!(
80+
default_config(),
81+
include_str!("../assets/default_config.toml")
82+
);
6783
}
6884

6985
#[test]
7086
fn test_read_config_default() {
7187
let result = read_config(default_config().to_owned()).unwrap();
72-
assert_eq!(result, Config {
73-
print_format: None
74-
})
88+
assert_eq!(result, Config { print_format: None })
7589
}
7690

7791
#[test]
7892
fn test_read_config_from_existent_file() {
7993
let file = assert_fs::NamedTempFile::new("envfetch.toml").unwrap();
8094
file.write_str(default_config()).unwrap();
8195
let result = read_config_from_file(file.path().to_path_buf()).unwrap();
82-
assert_eq!(result, Config {
83-
print_format: None
84-
})
96+
assert_eq!(result, Config { print_format: None })
8597
}
8698

8799
#[test]
@@ -91,7 +103,7 @@ mod tests {
91103
file.write_str("aegkbiv wlecn k").unwrap();
92104
match read_config_from_file(file.path().to_path_buf()) {
93105
Err(ConfigParsingError::ParsingError(_)) => (),
94-
_ => panic!("Should crash with ParsingError")
106+
_ => panic!("Should crash with ParsingError"),
95107
}
96108
}
97109

@@ -109,6 +121,9 @@ mod tests {
109121
let file = assert_fs::NamedTempFile::new("envfetch.toml").unwrap();
110122
let mut buffer = vec![];
111123
init_config(file.path().to_path_buf(), &mut buffer).unwrap();
112-
assert!(String::from_utf8(buffer).unwrap().contains(&format!("Successfully initialized config at {}", file.display())));
124+
assert!(String::from_utf8(buffer).unwrap().contains(&format!(
125+
"Successfully initialized config at {}",
126+
file.display()
127+
)));
113128
}
114129
}

src/interactive/tests.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,10 @@ fn test_value_truncation_and_name_padding() {
366366
let mut mode = InteractiveMode {
367367
entries: vec![
368368
("short".to_string(), "short_value".to_string()),
369-
("very_long_name".to_string(), "value_that_needs_truncation".to_string()),
369+
(
370+
"very_long_name".to_string(),
371+
"value_that_needs_truncation".to_string(),
372+
),
370373
],
371374
truncation_len: 10,
372375
current_index: 1,

src/main.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ mod utils;
1212
mod variables;
1313

1414
use clap::Parser;
15-
use config::{read_config_from_file, get_config_file_path};
16-
use std::{io::{stdout, Write}, process::ExitCode};
15+
use config::{get_config_file_path, read_config_from_file};
16+
use std::{
17+
io::{Write, stdout},
18+
process::ExitCode,
19+
};
1720

1821
use log::error;
1922

src/models.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,15 @@ mod tests {
235235
let test_cases = vec![
236236
(
237237
ConfigParsingError::FSError("Permission denied".to_string()),
238-
"Error while reading file: Permission denied"
238+
"Error while reading file: Permission denied",
239239
),
240240
(
241241
ConfigParsingError::ParsingError("Invalid JSON".to_string()),
242-
"Error while parsing file: Invalid JSON"
242+
"Error while parsing file: Invalid JSON",
243243
),
244244
(
245245
ConfigParsingError::FileDoesntExists,
246-
"Config file doesn't exists"
246+
"Config file doesn't exists",
247247
),
248248
];
249249

0 commit comments

Comments
 (0)