Skip to content

Commit 12985bd

Browse files
Fix formatting for update system
1 parent df6b2f2 commit 12985bd

File tree

5 files changed

+117
-93
lines changed

5 files changed

+117
-93
lines changed

src/cli/commands/update.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn execute_interactive_mode(check_only: bool, force: bool) -> Result<()> {
2323
Err(e) => {
2424
println!("{} Failed to check for updates: {}", "✗".red(), e);
2525
return Ok(());
26-
}
26+
},
2727
};
2828

2929
if !update_info.update_available {
@@ -73,20 +73,23 @@ fn execute_interactive_mode(check_only: bool, force: bool) -> Result<()> {
7373
match download_and_install_update(&download_url) {
7474
Ok(_) => {
7575
println!();
76-
println!("{}", "🎊 Update completed successfully!".bright_green().bold());
76+
println!(
77+
"{}",
78+
"🎊 Update completed successfully!".bright_green().bold()
79+
);
7780
println!(
7881
" {} Version {} is now installed",
7982
"→".cyan(),
8083
update_info.latest_version.bright_white()
8184
);
82-
}
85+
},
8386
Err(e) => {
8487
println!("{} Update failed: {}", "✗".red(), e);
8588
println!(
8689
" {} You can manually download from: https://github.com/DIG-Network/digstore/releases",
8790
"→".cyan()
8891
);
89-
}
92+
},
9093
}
9194
} else {
9295
println!("{} No installer available for your platform", "⚠".yellow());
@@ -128,7 +131,7 @@ fn execute_json_mode(check_only: bool, force: bool) -> Result<()> {
128131
"status": "success"
129132
});
130133
println!("{}", serde_json::to_string_pretty(&output)?);
131-
}
134+
},
132135
Err(e) => {
133136
let output = serde_json::json!({
134137
"action": "update_failed",
@@ -138,7 +141,7 @@ fn execute_json_mode(check_only: bool, force: bool) -> Result<()> {
138141
"manual_download": "https://github.com/DIG-Network/digstore/releases"
139142
});
140143
println!("{}", serde_json::to_string_pretty(&output)?);
141-
}
144+
},
142145
}
143146
} else {
144147
let output = serde_json::json!({

src/main.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ fn main() -> Result<()> {
202202
force,
203203
json,
204204
} => cli::commands::update::execute(check_only, force, json),
205-
205+
206206
Commands::Layer { command } => match command {
207207
LayerCommands::List {
208208
json,
@@ -367,7 +367,7 @@ fn needs_wallet_initialization(command: &Commands) -> bool {
367367
fn check_and_prompt_for_updates() -> Result<()> {
368368
use colored::Colorize;
369369
use dialoguer::Confirm;
370-
370+
371371
// Only check occasionally to avoid slowing down commands
372372
let update_info = match crate::update::check_for_updates() {
373373
Ok(info) => info,
@@ -398,12 +398,20 @@ fn check_and_prompt_for_updates() -> Result<()> {
398398
if let Some(download_url) = update_info.download_url {
399399
match crate::update::download_and_install_update(&download_url) {
400400
Ok(_) => {
401-
println!("{}", "✓ Update completed! Please restart your terminal.".green().bold());
402-
}
401+
println!(
402+
"{}",
403+
"✓ Update completed! Please restart your terminal."
404+
.green()
405+
.bold()
406+
);
407+
},
403408
Err(e) => {
404409
println!("{} Update failed: {}", "✗".red(), e);
405-
println!(" {} Manual download: https://github.com/DIG-Network/digstore/releases", "→".cyan());
406-
}
410+
println!(
411+
" {} Manual download: https://github.com/DIG-Network/digstore/releases",
412+
"→".cyan()
413+
);
414+
},
407415
}
408416
}
409417
} else {

src/update/installer.rs

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ pub enum InstallerType {
1919
/// Download and install an update
2020
pub fn download_and_install_update(download_url: &str) -> Result<()> {
2121
println!("{}", "Downloading update...".bright_blue());
22-
22+
2323
// Determine installer type from URL
2424
let installer_type = determine_installer_type(download_url)?;
25-
25+
2626
// Download the installer
2727
let temp_file = download_installer(download_url)?;
28-
28+
2929
println!("{}", "Installing update...".bright_green());
30-
30+
3131
// Install based on platform
3232
match installer_type {
3333
InstallerType::WindowsMsi => install_windows_msi(&temp_file),
@@ -36,13 +36,16 @@ pub fn download_and_install_update(download_url: &str) -> Result<()> {
3636
InstallerType::LinuxRpm => install_linux_rpm(&temp_file),
3737
InstallerType::LinuxAppImage => install_linux_appimage(&temp_file),
3838
}?;
39-
39+
4040
// Clean up temp file
4141
let _ = std::fs::remove_file(&temp_file);
42-
42+
4343
println!("{}", "✓ Update installed successfully!".green().bold());
44-
println!("{}", "Please restart your terminal to use the new version.".yellow());
45-
44+
println!(
45+
"{}",
46+
"Please restart your terminal to use the new version.".yellow()
47+
);
48+
4649
Ok(())
4750
}
4851

@@ -74,34 +77,34 @@ fn download_installer(url: &str) -> Result<std::path::PathBuf> {
7477
.map_err(|e| DigstoreError::NetworkError {
7578
reason: format!("Failed to create HTTP client: {}", e),
7679
})?;
77-
80+
7881
let response = client
7982
.get(url)
8083
.send()
8184
.map_err(|e| DigstoreError::NetworkError {
8285
reason: format!("Failed to download installer: {}", e),
8386
})?;
84-
87+
8588
if !response.status().is_success() {
8689
return Err(DigstoreError::NetworkError {
8790
reason: format!("Download failed with status: {}", response.status()),
8891
});
8992
}
90-
93+
9194
// Create temp file
9295
let temp_dir = std::env::temp_dir();
9396
let filename = url.split('/').last().unwrap_or("digstore-installer");
9497
let temp_file = temp_dir.join(filename);
95-
98+
9699
// Write downloaded content
97100
let content = response.bytes().map_err(|e| DigstoreError::NetworkError {
98101
reason: format!("Failed to read download content: {}", e),
99102
})?;
100-
103+
101104
std::fs::write(&temp_file, content)?;
102-
105+
103106
println!(" {} Downloaded to: {}", "✓".green(), temp_file.display());
104-
107+
105108
Ok(temp_file)
106109
}
107110

@@ -113,14 +116,14 @@ fn install_windows_msi(msi_path: &Path) -> Result<()> {
113116
.map_err(|e| DigstoreError::ConfigurationError {
114117
reason: format!("Failed to run msiexec: {}", e),
115118
})?;
116-
119+
117120
if !output.status.success() {
118121
let stderr = String::from_utf8_lossy(&output.stderr);
119122
return Err(DigstoreError::ConfigurationError {
120123
reason: format!("MSI installation failed: {}", stderr),
121124
});
122125
}
123-
126+
124127
Ok(())
125128
}
126129

@@ -133,13 +136,13 @@ fn install_macos_dmg(dmg_path: &Path) -> Result<()> {
133136
.map_err(|e| DigstoreError::ConfigurationError {
134137
reason: format!("Failed to mount DMG: {}", e),
135138
})?;
136-
139+
137140
if !mount_output.status.success() {
138141
return Err(DigstoreError::ConfigurationError {
139142
reason: "Failed to mount DMG".to_string(),
140143
});
141144
}
142-
145+
143146
// Extract mount point from output
144147
let mount_info = String::from_utf8_lossy(&mount_output.stdout);
145148
let mount_point = mount_info
@@ -149,30 +152,30 @@ fn install_macos_dmg(dmg_path: &Path) -> Result<()> {
149152
.ok_or_else(|| DigstoreError::ConfigurationError {
150153
reason: "Failed to determine mount point".to_string(),
151154
})?;
152-
155+
153156
// Copy app to Applications
154157
let app_name = "Digstore Min.app";
155158
let source = format!("{}/{}", mount_point, app_name);
156159
let destination = format!("/Applications/{}", app_name);
157-
160+
158161
let copy_output = Command::new("cp")
159162
.args(&["-r", &source, &destination])
160163
.output()
161164
.map_err(|e| DigstoreError::ConfigurationError {
162165
reason: format!("Failed to copy app: {}", e),
163166
})?;
164-
167+
165168
// Unmount DMG
166169
let _ = Command::new("hdiutil")
167170
.args(&["detach", mount_point])
168171
.output();
169-
172+
170173
if !copy_output.status.success() {
171174
return Err(DigstoreError::ConfigurationError {
172175
reason: "Failed to install app to Applications folder".to_string(),
173176
});
174177
}
175-
178+
176179
Ok(())
177180
}
178181

@@ -184,14 +187,14 @@ fn install_linux_deb(deb_path: &Path) -> Result<()> {
184187
.map_err(|e| DigstoreError::ConfigurationError {
185188
reason: format!("Failed to run dpkg: {}", e),
186189
})?;
187-
190+
188191
if !output.status.success() {
189192
let stderr = String::from_utf8_lossy(&output.stderr);
190193
return Err(DigstoreError::ConfigurationError {
191194
reason: format!("DEB installation failed: {}", stderr),
192195
});
193196
}
194-
197+
195198
Ok(())
196199
}
197200

@@ -203,14 +206,14 @@ fn install_linux_rpm(rpm_path: &Path) -> Result<()> {
203206
.map_err(|e| DigstoreError::ConfigurationError {
204207
reason: format!("Failed to run rpm: {}", e),
205208
})?;
206-
209+
207210
if !output.status.success() {
208211
let stderr = String::from_utf8_lossy(&output.stderr);
209212
return Err(DigstoreError::ConfigurationError {
210213
reason: format!("RPM installation failed: {}", stderr),
211214
});
212215
}
213-
216+
214217
Ok(())
215218
}
216219

@@ -223,28 +226,32 @@ fn install_linux_appimage(appimage_path: &Path) -> Result<()> {
223226
.map_err(|e| DigstoreError::ConfigurationError {
224227
reason: format!("Failed to make AppImage executable: {}", e),
225228
})?;
226-
229+
227230
if !chmod_output.status.success() {
228231
return Err(DigstoreError::ConfigurationError {
229232
reason: "Failed to make AppImage executable".to_string(),
230233
});
231234
}
232-
235+
233236
// Copy to /usr/local/bin (requires sudo)
234237
let copy_output = Command::new("sudo")
235-
.args(&["cp", appimage_path.to_str().unwrap(), "/usr/local/bin/digstore"])
238+
.args(&[
239+
"cp",
240+
appimage_path.to_str().unwrap(),
241+
"/usr/local/bin/digstore",
242+
])
236243
.output()
237244
.map_err(|e| DigstoreError::ConfigurationError {
238245
reason: format!("Failed to install AppImage: {}", e),
239246
})?;
240-
247+
241248
if !copy_output.status.success() {
242249
let stderr = String::from_utf8_lossy(&copy_output.stderr);
243250
return Err(DigstoreError::ConfigurationError {
244251
reason: format!("AppImage installation failed: {}", stderr),
245252
});
246253
}
247-
254+
248255
Ok(())
249256
}
250257

@@ -260,14 +267,14 @@ fn find_platform_download_url(assets: &[GitHubAsset]) -> Option<String> {
260267
} else {
261268
vec![]
262269
};
263-
270+
264271
for pattern in platform_patterns {
265272
for asset in assets {
266273
if asset.name.contains(pattern) {
267274
return Some(asset.browser_download_url.clone());
268275
}
269276
}
270277
}
271-
278+
272279
None
273280
}

src/update/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
//!
33
//! This module handles version checking and automatic updates
44
5-
pub mod version_check;
65
pub mod installer;
6+
pub mod version_check;
77

8-
pub use version_check::{check_for_updates, UpdateInfo};
98
pub use installer::{download_and_install_update, InstallerType};
9+
pub use version_check::{check_for_updates, UpdateInfo};

0 commit comments

Comments
 (0)