Skip to content

Commit fe25cdc

Browse files
committed
chore: format codebase
1 parent 15ce607 commit fe25cdc

5 files changed

Lines changed: 56 additions & 46 deletions

File tree

src/commands/use_cmd.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,22 @@ impl Use {
7373
// Smart prompt logic
7474
if Path::new(".php-version").exists()
7575
&& let Ok(current_file_ver) = std::fs::read_to_string(".php-version")
76-
&& current_file_ver.trim() != version {
77-
let prompt = format!(
78-
"A .php-version file is present ({}). Do you want to apply this change to the directory?",
79-
current_file_ver.trim().yellow()
80-
);
81-
if Confirm::with_theme(&ColorfulTheme::default())
82-
.with_prompt(&prompt)
83-
.default(false)
84-
.interact_opt()?
85-
.unwrap_or(false)
86-
{
87-
std::fs::write(".php-version", &version).ok();
88-
eprintln!("{} Updated .php-version to {}", "✓".green(), version.bold());
89-
}
90-
}
76+
&& current_file_ver.trim() != version
77+
{
78+
let prompt = format!(
79+
"A .php-version file is present ({}). Do you want to apply this change to the directory?",
80+
current_file_ver.trim().yellow()
81+
);
82+
if Confirm::with_theme(&ColorfulTheme::default())
83+
.with_prompt(&prompt)
84+
.default(false)
85+
.interact_opt()?
86+
.unwrap_or(false)
87+
{
88+
std::fs::write(".php-version", &version).ok();
89+
eprintln!("{} Updated .php-version to {}", "✓".green(), version.bold());
90+
}
91+
}
9192

9293
let bin_dir = fs::get_version_bin_dir(&version)?;
9394
let s = shell::detect_shell();

src/fs.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ pub fn list_installed_versions() -> Result<Vec<String>> {
3838
for entry in std::fs::read_dir(versions_dir)? {
3939
let entry = entry?;
4040
if entry.file_type()?.is_dir()
41-
&& let Ok(name) = entry.file_name().into_string() {
42-
versions.push(name);
43-
}
41+
&& let Ok(name) = entry.file_name().into_string()
42+
{
43+
versions.push(name);
44+
}
4445
}
4546

4647
versions.sort_by(|a, b| {
@@ -55,9 +56,10 @@ pub fn get_current_version() -> String {
5556
if let Ok(path) = std::env::var("PVM_MULTISHELL_PATH") {
5657
let p = PathBuf::from(path);
5758
if let Some(parent) = p.parent()
58-
&& let Some(name) = parent.file_name() {
59-
return name.to_string_lossy().into_owned();
60-
}
59+
&& let Some(name) = parent.file_name()
60+
{
61+
return name.to_string_lossy().into_owned();
62+
}
6163
}
6264
"system".to_string()
6365
}

src/network.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@ pub async fn get_available_versions() -> Result<Vec<String>> {
2222
// 1. Try to load from valid cache
2323
if cache_path.exists()
2424
&& let Ok(metadata) = std::fs::metadata(&cache_path)
25-
&& let Ok(modified) = metadata.modified()
26-
&& let Ok(elapsed) = modified.elapsed()
27-
&& elapsed < CACHE_DURATION
28-
&& let Ok(mut file) = File::open(&cache_path) {
29-
let mut contents = String::new();
30-
if file.read_to_string(&mut contents).is_ok()
31-
&& let Ok(versions) = serde_json::from_str::<Vec<String>>(&contents)
32-
{
33-
return Ok(versions);
34-
}
35-
}
25+
&& let Ok(modified) = metadata.modified()
26+
&& let Ok(elapsed) = modified.elapsed()
27+
&& elapsed < CACHE_DURATION
28+
&& let Ok(mut file) = File::open(&cache_path)
29+
{
30+
let mut contents = String::new();
31+
if file.read_to_string(&mut contents).is_ok()
32+
&& let Ok(versions) = serde_json::from_str::<Vec<String>>(&contents)
33+
{
34+
return Ok(versions);
35+
}
36+
}
3637

3738
// 2. Fetch from remote with a spinner
3839
println!(
@@ -66,13 +67,14 @@ pub async fn get_available_versions() -> Result<Vec<String>> {
6667
{
6768
versions.push(version.to_string());
6869
}
69-
} else if href.starts_with("php-") && href.ends_with("-cli-linux-x86_64.tar.gz")
70+
} else if href.starts_with("php-")
71+
&& href.ends_with("-cli-linux-x86_64.tar.gz")
7072
&& let Some(version) = href
7173
.strip_prefix("php-")
7274
.and_then(|h| h.strip_suffix("-cli-linux-x86_64.tar.gz"))
73-
{
74-
versions.push(version.to_string());
75-
}
75+
{
76+
versions.push(version.to_string());
77+
}
7678
}
7779

7880
// Sort versions by splitting by dot and parsing as numbers

src/shell.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ pvm() {
5454
return $exit_code
5555
fi
5656
}
57-
".to_string()
57+
"
58+
.to_string()
5859
}
5960
}
6061

@@ -102,7 +103,8 @@ pvm() {
102103
return $exit_code
103104
fi
104105
}
105-
".to_string()
106+
"
107+
.to_string()
106108
}
107109
}
108110

@@ -148,7 +150,8 @@ function pvm
148150
return $exit_code
149151
end
150152
end
151-
".to_string()
153+
"
154+
.to_string()
152155
}
153156
}
154157

src/update.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ pub async fn check_for_updates(target_version: &str) -> Result<Option<String>> {
1515
let now = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
1616
if guard_file.exists()
1717
&& let Ok(contents) = std::fs::read_to_string(&guard_file)
18-
&& let Ok(last_check) = contents.trim().parse::<u64>()
19-
&& now - last_check < 86400 {
20-
return Ok(None);
21-
}
18+
&& let Ok(last_check) = contents.trim().parse::<u64>()
19+
&& now - last_check < 86400
20+
{
21+
return Ok(None);
22+
}
2223

2324
// Write the new timestamp to prevent spam on next commands
2425
std::fs::write(&guard_file, now.to_string()).ok();
@@ -36,9 +37,10 @@ pub async fn check_for_updates(target_version: &str) -> Result<Option<String>> {
3637

3738
// Fetch remotes and resolve the newest patch for that minor line
3839
if let Ok(latest_matching) = network::resolve_version(&minor_prefix).await
39-
&& latest_matching != target_version {
40-
return Ok(Some(latest_matching));
41-
}
40+
&& latest_matching != target_version
41+
{
42+
return Ok(Some(latest_matching));
43+
}
4244

4345
Ok(None)
4446
}

0 commit comments

Comments
 (0)