Skip to content

Commit 01f52cd

Browse files
committed
style: reformat code
1 parent 8680e8e commit 01f52cd

5 files changed

Lines changed: 51 additions & 55 deletions

File tree

src/commands.rs

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -60,50 +60,50 @@ pub fn run_command<W: Write>(
6060
};
6161
print_env(opt, buffer)
6262
}
63-
Commands::Load(opt) => {
64-
match load(opt) {
65-
Ok(code) => if let Some(exit_code) = code {
63+
Commands::Load(opt) => match load(opt) {
64+
Ok(code) => {
65+
if let Some(exit_code) = code {
6666
return ExitCode::from(exit_code.code().unwrap_or_default() as u8);
6767
}
68-
Err(error) => {
69-
error!("{}", error);
70-
return ExitCode::FAILURE;
71-
}
7268
}
73-
}
74-
Commands::Set(opt) => {
75-
match set(opt) {
76-
Ok(code) => if let Some(exit_code) = code {
69+
Err(error) => {
70+
error!("{}", error);
71+
return ExitCode::FAILURE;
72+
}
73+
},
74+
Commands::Set(opt) => match set(opt) {
75+
Ok(code) => {
76+
if let Some(exit_code) = code {
7777
return ExitCode::from(exit_code.code().unwrap_or_default() as u8);
7878
}
79-
Err(error) => {
80-
error!("{}", error);
81-
return ExitCode::FAILURE;
82-
}
8379
}
84-
}
85-
Commands::Add(opt) => {
86-
match add(opt) {
87-
Ok(code) => if let Some(exit_code) = code {
80+
Err(error) => {
81+
error!("{}", error);
82+
return ExitCode::FAILURE;
83+
}
84+
},
85+
Commands::Add(opt) => match add(opt) {
86+
Ok(code) => {
87+
if let Some(exit_code) = code {
8888
return ExitCode::from(exit_code.code().unwrap_or_default() as u8);
8989
}
90-
Err(error) => {
91-
error!("{}", error);
92-
return ExitCode::FAILURE;
93-
}
9490
}
95-
}
96-
Commands::Delete(opt) => {
97-
match delete(opt) {
98-
Ok(code) => if let Some(exit_code) = code {
91+
Err(error) => {
92+
error!("{}", error);
93+
return ExitCode::FAILURE;
94+
}
95+
},
96+
Commands::Delete(opt) => match delete(opt) {
97+
Ok(code) => {
98+
if let Some(exit_code) = code {
9999
return ExitCode::from(exit_code.code().unwrap_or_default() as u8);
100100
}
101-
Err(error) => {
102-
error!("{}", error);
103-
return ExitCode::FAILURE;
104-
}
105101
}
106-
}
102+
Err(error) => {
103+
error!("{}", error);
104+
return ExitCode::FAILURE;
105+
}
106+
},
107107
Commands::Interactive => {
108108
#[cfg(not(test))]
109109
let mut terminal = ratatui::init();
@@ -145,7 +145,7 @@ pub fn load(args: &LoadArgs) -> Result<Option<ExitStatus>, ErrorKind> {
145145
},
146146
)?;
147147
if let Some(process) = args.process.clone() {
148-
return run(process).map(|val| Some(val));
148+
return run(process).map(Some);
149149
}
150150
}
151151
Err(err) => {
@@ -183,7 +183,7 @@ pub fn set(args: &SetArgs) -> Result<Option<ExitStatus>, ErrorKind> {
183183
variables::set_variable(&args.key, &args.value, args.global)?;
184184
let process = args.process.clone();
185185
if let Some(process) = process {
186-
return run(process).map(|val| Some(val));
186+
return run(process).map(Some);
187187
}
188188
Ok(None)
189189
}
@@ -205,7 +205,7 @@ pub fn add(args: &AddArgs) -> Result<Option<ExitStatus>, ErrorKind> {
205205
)?;
206206
let process = args.process.clone();
207207
if let Some(process) = process {
208-
return run(process).map(|val| Some(val));
208+
return run(process).map(Some);
209209
}
210210
Ok(None)
211211
}
@@ -224,7 +224,7 @@ pub fn delete(args: &DeleteArgs) -> Result<Option<ExitStatus>, ErrorKind> {
224224
}
225225
}
226226
if let Some(process) = args.process.clone() {
227-
return run(process).map(|val| Some(val));
227+
return run(process).map(Some);
228228
}
229229
Ok(None)
230230
}
@@ -777,7 +777,7 @@ mod tests {
777777
fn test_delete_with_process() {
778778
init();
779779
unsafe { env::set_var("TEST_DELETE_PROCESS", "test_value") };
780-
780+
781781
#[cfg(windows)]
782782
let test_cmd = "echo test";
783783
#[cfg(not(windows))]

src/main.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ mod variables;
1313

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

2118
use log::{error, info};
2219

src/utils.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::process::{Command, ExitStatus};
21
#[cfg(test)]
32
use std::process::Stdio;
3+
use std::process::{Command, ExitStatus};
44

55
use crate::models::ErrorKind;
66
use log::{error, info};
@@ -23,10 +23,15 @@ pub fn run(process: String) -> Result<ExitStatus, ErrorKind> {
2323
cmd.arg(shell_arg).arg(process);
2424

2525
#[cfg(test)]
26-
cmd.stderr(Stdio::null()).stdout(Stdio::null()).stderr(Stdio::null());
26+
cmd.stderr(Stdio::null())
27+
.stdout(Stdio::null())
28+
.stderr(Stdio::null());
2729
match cmd.status() {
2830
Ok(code) => {
29-
info!("process exited with exit code {}", code.code().unwrap_or_default());
31+
info!(
32+
"process exited with exit code {}",
33+
code.code().unwrap_or_default()
34+
);
3035
Ok(code)
3136
}
3237
Err(err) => {

src/variables.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ pub fn get_variables() -> VariablesList {
1919
}
2020

2121
/// Set variable with given key and value
22-
pub fn set_variable(
23-
key: &str,
24-
value: &str,
25-
global: bool
26-
) -> Result<(), ErrorKind> {
22+
pub fn set_variable(key: &str, value: &str, global: bool) -> Result<(), ErrorKind> {
2723
if global {
2824
if let Err(err) = globalenv::set_var(key, value) {
2925
return Err(ErrorKind::CannotSetVariableGlobally(err.to_string()));

tests/cli.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ fn get_variable_exists() -> Result<(), Box<dyn std::error::Error>> {
5959
fn get_variable_doesnt_exists() -> Result<(), Box<dyn std::error::Error>> {
6060
let mut cmd = Command::cargo_bin("envfetch")?;
6161
cmd.arg("get").arg("MY_VARIABLE");
62-
cmd.assert().failure().stderr(predicate::str::contains(
63-
"Can't find variable: MY_VARIABLE",
64-
));
62+
cmd.assert()
63+
.failure()
64+
.stderr(predicate::str::contains("Can't find variable: MY_VARIABLE"));
6565
Ok(())
6666
}
6767

@@ -73,9 +73,7 @@ fn get_variable_doesnt_exists_similar_enabled() -> Result<(), Box<dyn std::error
7373
cmd.arg("get").arg("MY_VARIABLE");
7474
cmd.assert()
7575
.failure()
76-
.stderr(predicate::str::contains(
77-
"Can't find variable: MY_VARIABLE",
78-
))
76+
.stderr(predicate::str::contains("Can't find variable: MY_VARIABLE"))
7977
.stdout(predicate::str::contains("Did you mean:"))
8078
.stdout(predicate::str::contains("MY_VARIABLEE"));
8179
Ok(())

0 commit comments

Comments
 (0)