Apply cargo fmt formatting

This commit is contained in:
Erikk Shupp 2026-05-11 11:02:52 -04:00
parent 71cd862b78
commit bdae3231b5
5 changed files with 305 additions and 257 deletions

View file

@ -44,7 +44,8 @@ pub fn process_cmdline() -> Result<CliArgs> {
std::process::exit(0); std::process::exit(0);
} }
if let Some(update_cmd) = arg_matches.subcommand_matches("update") { if let Some(update_cmd) = arg_matches.subcommand_matches("update")
{
let include_prerelease = update_cmd.get_flag("nightly"); let include_prerelease = update_cmd.get_flag("nightly");
if let Err(e) = self_update(include_prerelease) { if let Err(e) = self_update(include_prerelease) {
eprintln!("Update failed: {}", e); eprintln!("Update failed: {}", e);
@ -61,9 +62,11 @@ pub fn process_cmdline() -> Result<CliArgs> {
let workdir = arg_matches let workdir = arg_matches
.get_one::<String>(WORKDIR_FLAG_ID) .get_one::<String>(WORKDIR_FLAG_ID)
.map(PathBuf::from); .map(PathBuf::from);
let gitdir = arg_matches let gitdir =
.get_one::<String>(GIT_DIR_FLAG_ID) arg_matches.get_one::<String>(GIT_DIR_FLAG_ID).map_or_else(
.map_or_else(|| PathBuf::from(DEFAULT_GIT_DIR), PathBuf::from); || PathBuf::from(DEFAULT_GIT_DIR),
PathBuf::from,
);
let select_file = arg_matches let select_file = arg_matches
.get_one::<String>(FILE_FLAG_ID) .get_one::<String>(FILE_FLAG_ID)
@ -81,11 +84,15 @@ pub fn process_cmdline() -> Result<CliArgs> {
let confpath = get_app_config_path()?; let confpath = get_app_config_path()?;
fs::create_dir_all(&confpath).with_context(|| { fs::create_dir_all(&confpath).with_context(|| {
format!("failed to create config directory: {}", confpath.display()) format!(
"failed to create config directory: {}",
confpath.display()
)
})?; })?;
let theme = confpath.join(arg_theme); let theme = confpath.join(arg_theme);
let notify_watcher = *arg_matches.get_one(WATCHER_FLAG_ID).unwrap_or(&false); let notify_watcher =
*arg_matches.get_one(WATCHER_FLAG_ID).unwrap_or(&false);
let key_bindings_path = arg_matches let key_bindings_path = arg_matches
.get_one::<String>(KEY_BINDINGS_FLAG_ID) .get_one::<String>(KEY_BINDINGS_FLAG_ID)
@ -218,7 +225,11 @@ fn setup_logging(path_override: Option<PathBuf>) -> Result<()> {
}); });
println!("Logging enabled. Log written to: {}", path.display()); println!("Logging enabled. Log written to: {}", path.display());
WriteLogger::init(LevelFilter::Trace, Config::default(), File::create(path)?)?; WriteLogger::init(
LevelFilter::Trace,
Config::default(),
File::create(path)?,
)?;
Ok(()) Ok(())
} }
@ -228,7 +239,9 @@ pub fn get_app_config_path() -> Result<PathBuf> {
} else { } else {
dirs::config_dir() dirs::config_dir()
} }
.ok_or_else(|| anyhow::anyhow!("failed to find os config dir."))?; .ok_or_else(|| {
anyhow::anyhow!("failed to find os config dir.")
})?;
path.push("gitui"); path.push("gitui");
Ok(path) Ok(path)

View file

@ -62,7 +62,6 @@
mod app; mod app;
mod args; mod args;
mod bug_report; mod bug_report;
mod update;
mod clipboard; mod clipboard;
mod cmdbar; mod cmdbar;
mod components; mod components;
@ -79,6 +78,7 @@ mod string_utils;
mod strings; mod strings;
mod tabs; mod tabs;
mod ui; mod ui;
mod update;
mod watcher; mod watcher;
use crate::{ use crate::{

View file

@ -19,17 +19,19 @@ use std::process::Command;
macro_rules! update_via { macro_rules! update_via {
($name:ident, $cmd:expr, $args:expr, $success_msg:literal) => { ($name:ident, $cmd:expr, $args:expr, $success_msg:literal) => {
pub fn $name() -> Result<(), String> { pub fn $name() -> Result<(), String> {
let output = Command::new($cmd) let output =
.args($args) Command::new($cmd).args($args).output().map_err(
.output() |e| format!("Failed to run {}: {}", $cmd, e),
.map_err(|e| format!("Failed to run {}: {}", $cmd, e))?; )?;
if output.status.success() { if output.status.success() {
println!($success_msg); println!($success_msg);
Ok(()) Ok(())
} else { } else {
let stderr = String::from_utf8_lossy(&output.stderr); let stderr = String::from_utf8_lossy(&output.stderr);
if stderr.contains("already installed") || stderr.contains("already up-to-date") { if stderr.contains("already installed")
|| stderr.contains("already up-to-date")
{
println!("Already up to date!"); println!("Already up to date!");
Ok(()) Ok(())
} else { } else {

View file

@ -20,7 +20,10 @@ pub enum InstallMethod {
} }
impl std::fmt::Display for InstallMethod { impl std::fmt::Display for InstallMethod {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(
&self,
f: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
match self { match self {
InstallMethod::Cargo => write!(f, "cargo"), InstallMethod::Cargo => write!(f, "cargo"),
InstallMethod::Homebrew => write!(f, "homebrew"), InstallMethod::Homebrew => write!(f, "homebrew"),

View file

@ -19,7 +19,9 @@ pub fn self_update(include_prerelease: bool) -> Result<()> {
if is_prerelease(&current) { if is_prerelease(&current) {
println!("⚠️ Pre-release version detected."); println!("⚠️ Pre-release version detected.");
if !include_prerelease { if !include_prerelease {
println!(" Use 'gitui update -n' to include pre-releases."); println!(
" Use 'gitui update -n' to include pre-releases."
);
} }
} }
@ -38,8 +40,15 @@ pub fn self_update(include_prerelease: bool) -> Result<()> {
return Ok(()); return Ok(());
} }
Some(v) => { Some(v) => {
let kind = if is_prerelease(&v) { "Pre-release" } else { "Stable" }; let kind = if is_prerelease(&v) {
println!("{} update available: {} -> {}", kind, current, v); "Pre-release"
} else {
"Stable"
};
println!(
"{} update available: {} -> {}",
kind, current, v
);
} }
None => println!("Could not determine latest version."), None => println!("Could not determine latest version."),
} }
@ -61,7 +70,9 @@ pub fn self_update(include_prerelease: bool) -> Result<()> {
InstallMethod::Chocolatey => update_via_chocolatey(), InstallMethod::Chocolatey => update_via_chocolatey(),
InstallMethod::ScoopBucket => update_via_scoop_bucket(), InstallMethod::ScoopBucket => update_via_scoop_bucket(),
InstallMethod::Windows => update_via_windows(), InstallMethod::Windows => update_via_windows(),
InstallMethod::Unknown => Err("Unknown installation method".to_string()), InstallMethod::Unknown => {
Err("Unknown installation method".to_string())
}
}; };
match result { match result {
@ -80,14 +91,22 @@ fn get_current_version() -> String {
fn is_prerelease(v: &str) -> bool { fn is_prerelease(v: &str) -> bool {
let lower = v.to_lowercase(); let lower = v.to_lowercase();
["nightly", "-rc", "-beta", "-alpha", "-dev", "preview", "snapshot"] [
"nightly", "-rc", "-beta", "-alpha", "-dev", "preview",
"snapshot",
]
.iter() .iter()
.any(|&s| lower.contains(s)) .any(|&s| lower.contains(s))
} }
fn fetch_latest_version() -> Option<String> { fn fetch_latest_version() -> Option<String> {
let output = Command::new("git") let output = Command::new("git")
.args(["ls-remote", "--tags", "--sort=-v:refname", "https://github.com/extrawurst/gitui.git"]) .args([
"ls-remote",
"--tags",
"--sort=-v:refname",
"https://github.com/extrawurst/gitui.git",
])
.output() .output()
.ok()?; .ok()?;
@ -98,7 +117,10 @@ fn fetch_latest_version() -> Option<String> {
String::from_utf8_lossy(&output.stdout) String::from_utf8_lossy(&output.stdout)
.lines() .lines()
.filter_map(|line| { .filter_map(|line| {
line.split('\t').nth(1)?.strip_prefix("refs/tags/")?.strip_prefix('v') line.split('\t')
.nth(1)?
.strip_prefix("refs/tags/")?
.strip_prefix('v')
}) })
.next() .next()
.map(String::from) .map(String::from)
@ -106,7 +128,12 @@ fn fetch_latest_version() -> Option<String> {
fn fetch_latest_stable() -> Option<String> { fn fetch_latest_stable() -> Option<String> {
let output = Command::new("git") let output = Command::new("git")
.args(["ls-remote", "--tags", "--sort=-v:refname", "https://github.com/extrawurst/gitui.git"]) .args([
"ls-remote",
"--tags",
"--sort=-v:refname",
"https://github.com/extrawurst/gitui.git",
])
.output() .output()
.ok()?; .ok()?;
@ -117,7 +144,10 @@ fn fetch_latest_stable() -> Option<String> {
let version = String::from_utf8_lossy(&output.stdout) let version = String::from_utf8_lossy(&output.stdout)
.lines() .lines()
.filter_map(|line| { .filter_map(|line| {
line.split('\t').nth(1)?.strip_prefix("refs/tags/")?.strip_prefix('v') line.split('\t')
.nth(1)?
.strip_prefix("refs/tags/")?
.strip_prefix('v')
}) })
.find(|&v| !is_prerelease(v)) .find(|&v| !is_prerelease(v))
.map(String::from); .map(String::from);