mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 09:28:21 +00:00
Apply cargo fmt formatting
This commit is contained in:
parent
71cd862b78
commit
bdae3231b5
5 changed files with 305 additions and 257 deletions
29
src/args.rs
29
src/args.rs
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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::{
|
||||||
|
|
|
||||||
|
|
@ -17,109 +17,111 @@ use std::process::Command;
|
||||||
/// - `$args` - Arguments array (e.g., `["dnf", "upgrade", "gitui", "-y"]`)
|
/// - `$args` - Arguments array (e.g., `["dnf", "upgrade", "gitui", "-y"]`)
|
||||||
/// - `$success_msg` - Message printed on successful update
|
/// - `$success_msg` - Message printed on successful update
|
||||||
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")
|
||||||
println!("Already up to date!");
|
|| stderr.contains("already up-to-date")
|
||||||
Ok(())
|
{
|
||||||
} else {
|
println!("Already up to date!");
|
||||||
Err(format!("{} failed:\n{}", $cmd, stderr))
|
Ok(())
|
||||||
}
|
} else {
|
||||||
}
|
Err(format!("{} failed:\n{}", $cmd, stderr))
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
update_via!(
|
update_via!(
|
||||||
update_via_cargo,
|
update_via_cargo,
|
||||||
"cargo",
|
"cargo",
|
||||||
["install", "gitui", "--force"],
|
["install", "gitui", "--force"],
|
||||||
"Successfully updated via cargo!"
|
"Successfully updated via cargo!"
|
||||||
);
|
);
|
||||||
|
|
||||||
update_via!(
|
update_via!(
|
||||||
update_via_dnf,
|
update_via_dnf,
|
||||||
"sudo",
|
"sudo",
|
||||||
["dnf", "upgrade", "gitui", "-y"],
|
["dnf", "upgrade", "gitui", "-y"],
|
||||||
"Successfully updated via dnf!"
|
"Successfully updated via dnf!"
|
||||||
);
|
);
|
||||||
|
|
||||||
update_via!(
|
update_via!(
|
||||||
update_via_apt,
|
update_via_apt,
|
||||||
"sudo",
|
"sudo",
|
||||||
["apt", "upgrade", "gitui", "-y"],
|
["apt", "upgrade", "gitui", "-y"],
|
||||||
"Successfully updated via apt!"
|
"Successfully updated via apt!"
|
||||||
);
|
);
|
||||||
|
|
||||||
update_via!(
|
update_via!(
|
||||||
update_via_pacman,
|
update_via_pacman,
|
||||||
"sudo",
|
"sudo",
|
||||||
["pacman", "-Syu", "gitui", "--noconfirm"],
|
["pacman", "-Syu", "gitui", "--noconfirm"],
|
||||||
"Successfully updated via pacman!"
|
"Successfully updated via pacman!"
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
update_via!(
|
update_via!(
|
||||||
update_via_homebrew,
|
update_via_homebrew,
|
||||||
"brew",
|
"brew",
|
||||||
["upgrade", "gitui"],
|
["upgrade", "gitui"],
|
||||||
"Successfully updated via homebrew!"
|
"Successfully updated via homebrew!"
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(not(target_os = "macos"))]
|
#[cfg(not(target_os = "macos"))]
|
||||||
pub fn update_via_homebrew() -> Result<(), String> {
|
pub fn update_via_homebrew() -> Result<(), String> {
|
||||||
Err("Homebrew is only supported on macOS".to_string())
|
Err("Homebrew is only supported on macOS".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
update_via!(
|
update_via!(
|
||||||
update_via_scoop,
|
update_via_scoop,
|
||||||
"scoop",
|
"scoop",
|
||||||
["update", "gitui"],
|
["update", "gitui"],
|
||||||
"Successfully updated via scoop!"
|
"Successfully updated via scoop!"
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
pub fn update_via_scoop() -> Result<(), String> {
|
pub fn update_via_scoop() -> Result<(), String> {
|
||||||
Err("Scoop is only supported on Windows".to_string())
|
Err("Scoop is only supported on Windows".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
update_via!(
|
update_via!(
|
||||||
update_via_scoop_bucket,
|
update_via_scoop_bucket,
|
||||||
"scoop",
|
"scoop",
|
||||||
["update", "gitui"],
|
["update", "gitui"],
|
||||||
"Successfully updated via scoop bucket!"
|
"Successfully updated via scoop bucket!"
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
pub fn update_via_scoop_bucket() -> Result<(), String> {
|
pub fn update_via_scoop_bucket() -> Result<(), String> {
|
||||||
Err("Scoop is only supported on Windows".to_string())
|
Err("Scoop is only supported on Windows".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
update_via!(
|
update_via!(
|
||||||
update_via_chocolatey,
|
update_via_chocolatey,
|
||||||
"choco",
|
"choco",
|
||||||
["upgrade", "gitui", "-y"],
|
["upgrade", "gitui", "-y"],
|
||||||
"Successfully updated via chocolatey!"
|
"Successfully updated via chocolatey!"
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
pub fn update_via_chocolatey() -> Result<(), String> {
|
pub fn update_via_chocolatey() -> Result<(), String> {
|
||||||
Err("Chocolatey is only supported on Windows".to_string())
|
Err("Chocolatey is only supported on Windows".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_via_windows() -> Result<(), String> {
|
pub fn update_via_windows() -> Result<(), String> {
|
||||||
Err("Windows binary update not supported. Please download the latest release from GitHub.".to_string())
|
Err("Windows binary update not supported. Please download the latest release from GitHub.".to_string())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,140 +7,143 @@ use std::process::Command;
|
||||||
/// Installation methods supported by the self-update system.
|
/// Installation methods supported by the self-update system.
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum InstallMethod {
|
pub enum InstallMethod {
|
||||||
Cargo,
|
Cargo,
|
||||||
Homebrew,
|
Homebrew,
|
||||||
Apt,
|
Apt,
|
||||||
Dnf,
|
Dnf,
|
||||||
Pacman,
|
Pacman,
|
||||||
Windows,
|
Windows,
|
||||||
Scoop,
|
Scoop,
|
||||||
Chocolatey,
|
Chocolatey,
|
||||||
ScoopBucket,
|
ScoopBucket,
|
||||||
Unknown,
|
Unknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
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(
|
||||||
match self {
|
&self,
|
||||||
InstallMethod::Cargo => write!(f, "cargo"),
|
f: &mut std::fmt::Formatter<'_>,
|
||||||
InstallMethod::Homebrew => write!(f, "homebrew"),
|
) -> std::fmt::Result {
|
||||||
InstallMethod::Apt => write!(f, "apt"),
|
match self {
|
||||||
InstallMethod::Dnf => write!(f, "dnf"),
|
InstallMethod::Cargo => write!(f, "cargo"),
|
||||||
InstallMethod::Pacman => write!(f, "pacman"),
|
InstallMethod::Homebrew => write!(f, "homebrew"),
|
||||||
InstallMethod::Windows => write!(f, "windows"),
|
InstallMethod::Apt => write!(f, "apt"),
|
||||||
InstallMethod::Scoop => write!(f, "scoop"),
|
InstallMethod::Dnf => write!(f, "dnf"),
|
||||||
InstallMethod::Chocolatey => write!(f, "chocolatey"),
|
InstallMethod::Pacman => write!(f, "pacman"),
|
||||||
InstallMethod::ScoopBucket => write!(f, "scoop-bucket"),
|
InstallMethod::Windows => write!(f, "windows"),
|
||||||
InstallMethod::Unknown => write!(f, "unknown"),
|
InstallMethod::Scoop => write!(f, "scoop"),
|
||||||
}
|
InstallMethod::Chocolatey => write!(f, "chocolatey"),
|
||||||
}
|
InstallMethod::ScoopBucket => write!(f, "scoop-bucket"),
|
||||||
|
InstallMethod::Unknown => write!(f, "unknown"),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn detect_install_method() -> InstallMethod {
|
pub fn detect_install_method() -> InstallMethod {
|
||||||
let current_exe = std::env::current_exe().ok();
|
let current_exe = std::env::current_exe().ok();
|
||||||
let exe_path = current_exe.as_ref().map(|p| p.as_path());
|
let exe_path = current_exe.as_ref().map(|p| p.as_path());
|
||||||
|
|
||||||
let is_cargo_build = exe_path.map_or(false, |p| {
|
let is_cargo_build = exe_path.map_or(false, |p| {
|
||||||
let s = p.to_string_lossy();
|
let s = p.to_string_lossy();
|
||||||
s.contains(".cargo/bin")
|
s.contains(".cargo/bin")
|
||||||
|| s.contains("cargo/registry")
|
|| s.contains("cargo/registry")
|
||||||
|| s.contains("target/release")
|
|| s.contains("target/release")
|
||||||
|| s.contains("target/debug")
|
|| s.contains("target/debug")
|
||||||
});
|
});
|
||||||
|
|
||||||
if is_cargo_build {
|
if is_cargo_build {
|
||||||
if has_dnf_installation() {
|
if has_dnf_installation() {
|
||||||
return InstallMethod::Dnf;
|
return InstallMethod::Dnf;
|
||||||
}
|
}
|
||||||
if has_apt_installation() {
|
if has_apt_installation() {
|
||||||
return InstallMethod::Apt;
|
return InstallMethod::Apt;
|
||||||
}
|
}
|
||||||
if has_pacman_installation() {
|
if has_pacman_installation() {
|
||||||
return InstallMethod::Pacman;
|
return InstallMethod::Pacman;
|
||||||
}
|
}
|
||||||
return InstallMethod::Cargo;
|
return InstallMethod::Cargo;
|
||||||
}
|
}
|
||||||
|
|
||||||
exe_path.map_or(InstallMethod::Unknown, |p| {
|
exe_path.map_or(InstallMethod::Unknown, |p| {
|
||||||
let s = p.to_string_lossy();
|
let s = p.to_string_lossy();
|
||||||
|
|
||||||
if s.contains("homebrew") || s.contains("Cellar") {
|
if s.contains("homebrew") || s.contains("Cellar") {
|
||||||
return InstallMethod::Homebrew;
|
return InstallMethod::Homebrew;
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.contains("scoop") {
|
if s.contains("scoop") {
|
||||||
return if s.contains("scoop-bucket") {
|
return if s.contains("scoop-bucket") {
|
||||||
InstallMethod::ScoopBucket
|
InstallMethod::ScoopBucket
|
||||||
} else {
|
} else {
|
||||||
InstallMethod::Scoop
|
InstallMethod::Scoop
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.contains("chocolatey") {
|
if s.contains("chocolatey") {
|
||||||
return InstallMethod::Chocolatey;
|
return InstallMethod::Chocolatey;
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg!(target_os = "windows") {
|
if cfg!(target_os = "windows") {
|
||||||
return InstallMethod::Windows;
|
return InstallMethod::Windows;
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.contains("/usr/bin") || s.contains("/usr/local/bin") {
|
if s.contains("/usr/bin") || s.contains("/usr/local/bin") {
|
||||||
if has_dnf_installation() {
|
if has_dnf_installation() {
|
||||||
return InstallMethod::Dnf;
|
return InstallMethod::Dnf;
|
||||||
}
|
}
|
||||||
if has_apt_installation() {
|
if has_apt_installation() {
|
||||||
return InstallMethod::Apt;
|
return InstallMethod::Apt;
|
||||||
}
|
}
|
||||||
if has_pacman_installation() {
|
if has_pacman_installation() {
|
||||||
return InstallMethod::Pacman;
|
return InstallMethod::Pacman;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InstallMethod::Unknown
|
InstallMethod::Unknown
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn has_dnf_installation() -> bool {
|
fn has_dnf_installation() -> bool {
|
||||||
Path::new("/usr/bin/rpm").exists()
|
Path::new("/usr/bin/rpm").exists()
|
||||||
&& Command::new("rpm")
|
&& Command::new("rpm")
|
||||||
.args(["-q", "gitui"])
|
.args(["-q", "gitui"])
|
||||||
.output()
|
.output()
|
||||||
.map(|o| o.status.success())
|
.map(|o| o.status.success())
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "linux"))]
|
#[cfg(not(target_os = "linux"))]
|
||||||
fn has_dnf_installation() -> bool {
|
fn has_dnf_installation() -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn has_apt_installation() -> bool {
|
fn has_apt_installation() -> bool {
|
||||||
Path::new("/usr/bin/dpkg").exists()
|
Path::new("/usr/bin/dpkg").exists()
|
||||||
&& Command::new("dpkg")
|
&& Command::new("dpkg")
|
||||||
.args(["-l", "gitui"])
|
.args(["-l", "gitui"])
|
||||||
.output()
|
.output()
|
||||||
.map(|o| o.status.success())
|
.map(|o| o.status.success())
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "linux"))]
|
#[cfg(not(target_os = "linux"))]
|
||||||
fn has_apt_installation() -> bool {
|
fn has_apt_installation() -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn has_pacman_installation() -> bool {
|
fn has_pacman_installation() -> bool {
|
||||||
Path::new("/usr/bin/pacman").exists()
|
Path::new("/usr/bin/pacman").exists()
|
||||||
&& Command::new("pacman")
|
&& Command::new("pacman")
|
||||||
.args(["-Q", "gitui"])
|
.args(["-Q", "gitui"])
|
||||||
.output()
|
.output()
|
||||||
.map(|o| o.status.success())
|
.map(|o| o.status.success())
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "linux"))]
|
#[cfg(not(target_os = "linux"))]
|
||||||
fn has_pacman_installation() -> bool {
|
fn has_pacman_installation() -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,130 +11,160 @@ use std::io::{self, Write};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
pub fn self_update(include_prerelease: bool) -> Result<()> {
|
pub fn self_update(include_prerelease: bool) -> Result<()> {
|
||||||
let current = get_current_version();
|
let current = get_current_version();
|
||||||
let method = detect_install_method();
|
let method = detect_install_method();
|
||||||
|
|
||||||
println!("gitui version: {}", current);
|
println!("gitui version: {}", current);
|
||||||
|
|
||||||
if is_prerelease(¤t) {
|
if is_prerelease(¤t) {
|
||||||
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."
|
||||||
}
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
println!("Installation method: {}", method);
|
println!("Installation method: {}", method);
|
||||||
println!("Checking for updates...");
|
println!("Checking for updates...");
|
||||||
|
|
||||||
let latest = if include_prerelease {
|
let latest = if include_prerelease {
|
||||||
fetch_latest_version()
|
fetch_latest_version()
|
||||||
} else {
|
} else {
|
||||||
fetch_latest_stable()
|
fetch_latest_stable()
|
||||||
};
|
};
|
||||||
|
|
||||||
match latest {
|
match latest {
|
||||||
Some(v) if v == current => {
|
Some(v) if v == current => {
|
||||||
println!("Already up to date ({})", current);
|
println!("Already up to date ({})", current);
|
||||||
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 {
|
||||||
None => println!("Could not determine latest version."),
|
"Stable"
|
||||||
}
|
};
|
||||||
|
println!(
|
||||||
|
"{} update available: {} -> {}",
|
||||||
|
kind, current, v
|
||||||
|
);
|
||||||
|
}
|
||||||
|
None => println!("Could not determine latest version."),
|
||||||
|
}
|
||||||
|
|
||||||
if !confirm("Do you want to update gitui?")? {
|
if !confirm("Do you want to update gitui?")? {
|
||||||
println!("Update cancelled.");
|
println!("Update cancelled.");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("Updating via {}...", method);
|
println!("Updating via {}...", method);
|
||||||
|
|
||||||
let result = match method {
|
let result = match method {
|
||||||
InstallMethod::Cargo => update_via_cargo(),
|
InstallMethod::Cargo => update_via_cargo(),
|
||||||
InstallMethod::Homebrew => update_via_homebrew(),
|
InstallMethod::Homebrew => update_via_homebrew(),
|
||||||
InstallMethod::Dnf => update_via_dnf(),
|
InstallMethod::Dnf => update_via_dnf(),
|
||||||
InstallMethod::Apt => update_via_apt(),
|
InstallMethod::Apt => update_via_apt(),
|
||||||
InstallMethod::Pacman => update_via_pacman(),
|
InstallMethod::Pacman => update_via_pacman(),
|
||||||
InstallMethod::Scoop => update_via_scoop(),
|
InstallMethod::Scoop => update_via_scoop(),
|
||||||
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 {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
println!("Update complete! Please restart gitui.");
|
println!("Update complete! Please restart gitui.");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(e) => Err(anyhow!("Update failed: {}", e)),
|
Err(e) => Err(anyhow!("Update failed: {}", e)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_current_version() -> String {
|
fn get_current_version() -> String {
|
||||||
let build = env!("GITUI_BUILD_NAME");
|
let build = env!("GITUI_BUILD_NAME");
|
||||||
build.split_whitespace().next().unwrap_or(build).to_string()
|
build.split_whitespace().next().unwrap_or(build).to_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"]
|
[
|
||||||
.iter()
|
"nightly", "-rc", "-beta", "-alpha", "-dev", "preview",
|
||||||
.any(|&s| lower.contains(s))
|
"snapshot",
|
||||||
|
]
|
||||||
|
.iter()
|
||||||
|
.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([
|
||||||
.output()
|
"ls-remote",
|
||||||
.ok()?;
|
"--tags",
|
||||||
|
"--sort=-v:refname",
|
||||||
|
"https://github.com/extrawurst/gitui.git",
|
||||||
|
])
|
||||||
|
.output()
|
||||||
|
.ok()?;
|
||||||
|
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
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)?
|
||||||
.next()
|
.strip_prefix("refs/tags/")?
|
||||||
.map(String::from)
|
.strip_prefix('v')
|
||||||
|
})
|
||||||
|
.next()
|
||||||
|
.map(String::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
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([
|
||||||
.output()
|
"ls-remote",
|
||||||
.ok()?;
|
"--tags",
|
||||||
|
"--sort=-v:refname",
|
||||||
|
"https://github.com/extrawurst/gitui.git",
|
||||||
|
])
|
||||||
|
.output()
|
||||||
|
.ok()?;
|
||||||
|
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
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)?
|
||||||
.find(|&v| !is_prerelease(v))
|
.strip_prefix("refs/tags/")?
|
||||||
.map(String::from);
|
.strip_prefix('v')
|
||||||
|
})
|
||||||
|
.find(|&v| !is_prerelease(v))
|
||||||
|
.map(String::from);
|
||||||
|
|
||||||
if version.is_none() {
|
if version.is_none() {
|
||||||
println!("Warning: No stable release found. Use -n for pre-releases.");
|
println!("Warning: No stable release found. Use -n for pre-releases.");
|
||||||
}
|
}
|
||||||
|
|
||||||
version
|
version
|
||||||
}
|
}
|
||||||
|
|
||||||
fn confirm(prompt: &str) -> Result<bool> {
|
fn confirm(prompt: &str) -> Result<bool> {
|
||||||
print!("{} [y/N]: ", prompt);
|
print!("{} [y/N]: ", prompt);
|
||||||
io::stdout().flush()?;
|
io::stdout().flush()?;
|
||||||
|
|
||||||
let mut input = String::new();
|
let mut input = String::new();
|
||||||
io::stdin().read_line(&mut input)?;
|
io::stdin().read_line(&mut input)?;
|
||||||
|
|
||||||
Ok(input.trim().eq_ignore_ascii_case("y"))
|
Ok(input.trim().eq_ignore_ascii_case("y"))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue