chore: upgrade to edition 2024
Co-authored-by: Ehren Bendler <a5ehren@gmail.com>
This commit is contained in:
@@ -9,7 +9,7 @@ rust-version = "1.87.0"
|
||||
version = "16.4.2"
|
||||
authors = ["Roey Darwish Dror <roey.ghost@gmail.com>", "Thomas Schönauer <t.schoenauer@hgs-wt.at>"]
|
||||
exclude = ["doc/screenshot.gif", "BREAKINGCHANGES_dev.md"]
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
readme = "README.md"
|
||||
|
||||
|
||||
@@ -4,17 +4,17 @@
|
||||
//! 1. The Topgrade being executed is a new major release
|
||||
//! 2. This is the first launch of that major release
|
||||
|
||||
use crate::terminal::print_separator;
|
||||
#[cfg(windows)]
|
||||
use crate::WINDOWS_DIRS;
|
||||
#[cfg(unix)]
|
||||
use crate::XDG_DIRS;
|
||||
use crate::terminal::print_separator;
|
||||
use color_eyre::eyre::Result;
|
||||
use etcetera::base_strategy::BaseStrategy;
|
||||
use rust_i18n::t;
|
||||
use std::{
|
||||
env::var,
|
||||
fs::{read_to_string, OpenOptions},
|
||||
fs::{OpenOptions, read_to_string},
|
||||
io::Write,
|
||||
path::PathBuf,
|
||||
str::FromStr,
|
||||
|
||||
@@ -5,8 +5,8 @@ use std::process::Child;
|
||||
use std::process::{Command, ExitStatus, Output};
|
||||
|
||||
use color_eyre::eyre;
|
||||
use color_eyre::eyre::eyre;
|
||||
use color_eyre::eyre::Context;
|
||||
use color_eyre::eyre::eyre;
|
||||
|
||||
use crate::error::TopgradeError;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use std::fs::{write, File};
|
||||
use std::fs::{File, write};
|
||||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! SIGINT handling in Unix systems.
|
||||
use crate::ctrlc::interrupted::set_interrupted;
|
||||
use nix::sys::signal::{sigaction, SaFlags, SigAction, SigHandler, SigSet, Signal};
|
||||
use nix::sys::signal::{SaFlags, SigAction, SigHandler, SigSet, Signal, sigaction};
|
||||
|
||||
/// Handle SIGINT. Set the interruption flag.
|
||||
extern "C" fn handle_sigint(_: i32) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//! A stub for Ctrl + C handling.
|
||||
use crate::ctrlc::interrupted::set_interrupted;
|
||||
use tracing::error;
|
||||
use windows::Win32::System::Console::{CTRL_C_EVENT, SetConsoleCtrlHandler};
|
||||
use windows::core::BOOL;
|
||||
use windows::Win32::System::Console::{SetConsoleCtrlHandler, CTRL_C_EVENT};
|
||||
|
||||
extern "system" fn handler(ctrl_type: u32) -> BOOL {
|
||||
match ctrl_type {
|
||||
|
||||
@@ -7,7 +7,7 @@ use std::process::{Child, Command, ExitStatus, Output};
|
||||
|
||||
use color_eyre::eyre::Result;
|
||||
use rust_i18n::t;
|
||||
use tracing::{debug, enabled, Level};
|
||||
use tracing::{Level, debug, enabled};
|
||||
|
||||
use crate::command::CommandExt;
|
||||
use crate::error::DryRun;
|
||||
|
||||
10
src/main.rs
10
src/main.rs
@@ -9,7 +9,7 @@ use std::time::Duration;
|
||||
|
||||
use crate::breaking_changes::{first_run_of_major_release, print_breaking_changes, should_skip, write_keep_file};
|
||||
use clap::CommandFactory;
|
||||
use clap::{crate_version, Parser};
|
||||
use clap::{Parser, crate_version};
|
||||
use color_eyre::eyre::Context;
|
||||
use color_eyre::eyre::Result;
|
||||
use console::Key;
|
||||
@@ -99,7 +99,7 @@ fn run() -> Result<()> {
|
||||
let mut parts = env.split('=');
|
||||
let var = parts.next().unwrap();
|
||||
let value = parts.next().unwrap();
|
||||
env::set_var(var, value);
|
||||
unsafe { env::set_var(var, value) };
|
||||
}
|
||||
|
||||
if opt.edit_config() {
|
||||
@@ -322,11 +322,7 @@ fn run() -> Result<()> {
|
||||
);
|
||||
}
|
||||
|
||||
if failed {
|
||||
Err(StepFailed.into())
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
if failed { Err(StepFailed.into()) } else { Ok(()) }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::ctrlc;
|
||||
use crate::error::{DryRun, MissingSudo, SkipStep};
|
||||
use crate::execution_context::ExecutionContext;
|
||||
use crate::step::Step;
|
||||
use crate::terminal::{print_error, print_warning, should_retry, ShouldRetry};
|
||||
use crate::terminal::{ShouldRetry, print_error, print_warning, should_retry};
|
||||
|
||||
pub enum StepResult {
|
||||
Success,
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
use std::env;
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::process::CommandExt as _;
|
||||
use std::process::Command;
|
||||
#[cfg(windows)]
|
||||
use std::process::exit;
|
||||
use std::process::Command;
|
||||
|
||||
use crate::step::Step;
|
||||
use color_eyre::eyre::Result;
|
||||
#[cfg(unix)]
|
||||
use color_eyre::eyre::bail;
|
||||
use color_eyre::eyre::Result;
|
||||
use rust_i18n::t;
|
||||
use self_update_crate::backends::github::Update;
|
||||
use self_update_crate::update::UpdateStatus;
|
||||
|
||||
@@ -6,7 +6,7 @@ use std::process::Command;
|
||||
|
||||
use color_eyre::eyre::Context;
|
||||
use color_eyre::eyre::Result;
|
||||
use color_eyre::eyre::{eyre, OptionExt};
|
||||
use color_eyre::eyre::{OptionExt, eyre};
|
||||
use tracing::{debug, error, warn};
|
||||
use wildmatch::WildMatch;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::command::CommandExt;
|
||||
use crate::execution_context::ExecutionContext;
|
||||
use crate::step::Step;
|
||||
use crate::terminal::print_separator;
|
||||
use crate::utils::{require, require_option, PathExt};
|
||||
use crate::utils::{PathExt, require, require_option};
|
||||
|
||||
const EMACS_UPGRADE: &str = include_str!("emacs.el");
|
||||
#[cfg(windows)]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use color_eyre::eyre::Context;
|
||||
use color_eyre::eyre::Result;
|
||||
use color_eyre::eyre::{eyre, OptionExt};
|
||||
use jetbrains_toolbox_updater::{find_jetbrains_toolbox, update_jetbrains_toolbox, FindError};
|
||||
use color_eyre::eyre::{OptionExt, eyre};
|
||||
use jetbrains_toolbox_updater::{FindError, find_jetbrains_toolbox, update_jetbrains_toolbox};
|
||||
use regex::bytes::Regex;
|
||||
use rust_i18n::t;
|
||||
use semver::Version;
|
||||
@@ -16,6 +16,7 @@ use std::{fs, io::Write};
|
||||
use tempfile::tempfile_in;
|
||||
use tracing::{debug, error, warn};
|
||||
|
||||
use crate::HOME_DIR;
|
||||
use crate::command::{CommandExt, Utf8Output};
|
||||
use crate::execution_context::ExecutionContext;
|
||||
use crate::executor::ExecutorOutput;
|
||||
@@ -23,8 +24,7 @@ use crate::output_changed_message;
|
||||
use crate::step::Step;
|
||||
use crate::sudo::SudoExecuteOpts;
|
||||
use crate::terminal::{print_separator, shell};
|
||||
use crate::utils::{check_is_python_2_or_shim, require, require_one, require_option, which, PathExt};
|
||||
use crate::HOME_DIR;
|
||||
use crate::utils::{PathExt, check_is_python_2_or_shim, require, require_one, require_option, which};
|
||||
use crate::{
|
||||
error::{SkipStep, StepFailed, TopgradeError},
|
||||
terminal::print_warning,
|
||||
@@ -65,7 +65,9 @@ pub fn run_cargo_update(ctx: &ExecutionContext) -> Result<()> {
|
||||
.or_else(|| cargo_dir.join("bin/cargo-install-update").if_exists());
|
||||
|
||||
let Some(cargo_update) = cargo_update else {
|
||||
let message = String::from("cargo-update isn't installed so Topgrade can't upgrade cargo packages.\nInstall cargo-update by running `cargo install cargo-update`");
|
||||
let message = String::from(
|
||||
"cargo-update isn't installed so Topgrade can't upgrade cargo packages.\nInstall cargo-update by running `cargo install cargo-update`",
|
||||
);
|
||||
print_warning(&message);
|
||||
return Err(SkipStep(message).into());
|
||||
};
|
||||
@@ -81,7 +83,9 @@ pub fn run_cargo_update(ctx: &ExecutionContext) -> Result<()> {
|
||||
if let Some(e) = cargo_cache {
|
||||
ctx.execute(e).args(["-a"]).status_checked()?;
|
||||
} else {
|
||||
let message = String::from("cargo-cache isn't installed so Topgrade can't cleanup cargo packages.\nInstall cargo-cache by running `cargo install cargo-cache`");
|
||||
let message = String::from(
|
||||
"cargo-cache isn't installed so Topgrade can't cleanup cargo packages.\nInstall cargo-cache by running `cargo install cargo-cache`",
|
||||
);
|
||||
print_warning(message);
|
||||
}
|
||||
}
|
||||
@@ -542,7 +546,7 @@ fn run_vscode_compatible(variant: VSCodeVariant, ctx: &ExecutionContext) -> Resu
|
||||
return Err(eyre!(output_changed_message!(
|
||||
&format!("{bin_name} --version"),
|
||||
"No first line"
|
||||
)))
|
||||
)));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1239,11 +1243,7 @@ pub fn run_helm_repo_update(ctx: &ExecutionContext) -> Result<()> {
|
||||
};
|
||||
}
|
||||
|
||||
if success {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(eyre!(StepFailed))
|
||||
}
|
||||
if success { Ok(()) } else { Err(eyre!(StepFailed)) }
|
||||
}
|
||||
|
||||
pub fn run_stew(ctx: &ExecutionContext) -> Result<()> {
|
||||
@@ -1428,8 +1428,7 @@ pub fn run_poetry(ctx: &ExecutionContext) -> Result<()> {
|
||||
.map_err(|e| SkipStep(format!("Could not find interpreter for {}: {}", poetry.display(), e)))?;
|
||||
debug!("poetry interpreter: {:?}, args: {:?}", interp, interp_args);
|
||||
|
||||
let check_official_install_script =
|
||||
"import sys; from os import path; print('Y') if path.isfile(path.join(sys.prefix, 'poetry_env')) else print('N')";
|
||||
let check_official_install_script = "import sys; from os import path; print('Y') if path.isfile(path.join(sys.prefix, 'poetry_env')) else print('N')";
|
||||
let mut command = Command::new(&interp);
|
||||
if let Some(args) = interp_args {
|
||||
command.arg(args);
|
||||
@@ -1708,7 +1707,10 @@ fn run_jetbrains_ide_generic<const IS_JETBRAINS: bool>(ctx: &ExecutionContext, b
|
||||
.code()
|
||||
.ok_or_eyre("Failed to get status code; was killed with signal")?;
|
||||
if status_code != 1 {
|
||||
return Err(eyre!("Expected status code 1 ('Only one instance of <IDE> can be run at a time.'), but found status code {}. Output: {output:?}", status_code));
|
||||
return Err(eyre!(
|
||||
"Expected status code 1 ('Only one instance of <IDE> can be run at a time.'), but found status code {}. Output: {output:?}",
|
||||
status_code
|
||||
));
|
||||
}
|
||||
// Don't crash, but don't be silent either
|
||||
warn!("{name} is already running, can't update it now.");
|
||||
|
||||
@@ -4,10 +4,10 @@ use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Output, Stdio};
|
||||
|
||||
use color_eyre::eyre::Context;
|
||||
use color_eyre::eyre::{eyre, Result};
|
||||
use color_eyre::eyre::{Result, eyre};
|
||||
use console::style;
|
||||
use futures::stream::{iter, FuturesUnordered, StreamExt};
|
||||
use glob::{glob_with, MatchOptions};
|
||||
use futures::stream::{FuturesUnordered, StreamExt, iter};
|
||||
use glob::{MatchOptions, glob_with};
|
||||
use tokio::process::Command as AsyncCommand;
|
||||
use tokio::runtime;
|
||||
use tracing::{debug, error};
|
||||
@@ -17,8 +17,8 @@ use crate::execution_context::ExecutionContext;
|
||||
use crate::step::Step;
|
||||
use crate::steps::emacs::Emacs;
|
||||
use crate::terminal::print_separator;
|
||||
use crate::utils::{require, PathExt};
|
||||
use crate::{error::SkipStep, terminal::print_warning, HOME_DIR};
|
||||
use crate::utils::{PathExt, require};
|
||||
use crate::{HOME_DIR, error::SkipStep, terminal::print_warning};
|
||||
use etcetera::base_strategy::BaseStrategy;
|
||||
use rust_i18n::t;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ use tracing::debug;
|
||||
|
||||
use crate::command::CommandExt;
|
||||
use crate::terminal::{print_info, print_separator};
|
||||
use crate::utils::{require, PathExt};
|
||||
use crate::utils::{PathExt, require};
|
||||
use crate::{error::SkipStep, execution_context::ExecutionContext};
|
||||
|
||||
enum NPMVariant {
|
||||
@@ -65,11 +65,7 @@ impl NPM {
|
||||
/// If the “NPM” version is larger than 8.11.0, we use
|
||||
/// `--location=global`; otherwise, use `-g`.
|
||||
fn global_location_arg(&self) -> &str {
|
||||
if self.is_npm_8() {
|
||||
"--location=global"
|
||||
} else {
|
||||
"-g"
|
||||
}
|
||||
if self.is_npm_8() { "--location=global" } else { "-g" }
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
|
||||
@@ -6,6 +6,7 @@ use ini::Ini;
|
||||
use rust_i18n::t;
|
||||
use tracing::{debug, warn};
|
||||
|
||||
use crate::HOME_DIR;
|
||||
use crate::command::CommandExt;
|
||||
use crate::error::{SkipStep, TopgradeError};
|
||||
use crate::execution_context::ExecutionContext;
|
||||
@@ -14,8 +15,7 @@ use crate::steps::generic::is_wsl;
|
||||
use crate::steps::os::archlinux;
|
||||
use crate::sudo::SudoExecuteOpts;
|
||||
use crate::terminal::{print_separator, prompt_yesno};
|
||||
use crate::utils::{require, require_one, which, PathExt};
|
||||
use crate::HOME_DIR;
|
||||
use crate::utils::{PathExt, require, require_one, which};
|
||||
|
||||
static OS_RELEASE_PATH: &str = "/etc/os-release";
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use color_eyre::eyre::Context;
|
||||
use color_eyre::eyre::Result;
|
||||
use color_eyre::eyre::{eyre, OptionExt};
|
||||
use color_eyre::eyre::{OptionExt, eyre};
|
||||
use etcetera::BaseStrategy;
|
||||
use ini::Ini;
|
||||
#[cfg(target_os = "linux")]
|
||||
@@ -20,10 +20,10 @@ use std::{env::var, path::Path};
|
||||
use std::{fs, io};
|
||||
use tracing::{debug, warn};
|
||||
|
||||
use crate::XDG_DIRS;
|
||||
use crate::command::CommandExt;
|
||||
use crate::sudo::SudoExecuteOpts;
|
||||
use crate::XDG_DIRS;
|
||||
use crate::{output_changed_message, HOME_DIR};
|
||||
use crate::{HOME_DIR, output_changed_message};
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
use super::linux::Distribution;
|
||||
@@ -33,7 +33,7 @@ use crate::execution_context::ExecutionContext;
|
||||
use crate::executor::Executor;
|
||||
use crate::step::Step;
|
||||
use crate::terminal::print_separator;
|
||||
use crate::utils::{require, PathExt};
|
||||
use crate::utils::{PathExt, require};
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
const INTEL_BREW: &str = "/usr/local/bin/brew";
|
||||
|
||||
@@ -254,11 +254,7 @@ pub fn microsoft_store(ctx: &ExecutionContext) -> Result<()> {
|
||||
}
|
||||
let ret_val = output.stdout.trim();
|
||||
debug!("Command return value: {}", ret_val);
|
||||
if ret_val == "0" {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
if ret_val == "0" { Ok(()) } else { Err(()) }
|
||||
})?;
|
||||
println!(
|
||||
"{}",
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
use color_eyre::eyre::Result;
|
||||
#[cfg(windows)]
|
||||
use color_eyre::eyre::eyre;
|
||||
use color_eyre::eyre::Result;
|
||||
use tracing::debug;
|
||||
|
||||
use crate::command::CommandExt;
|
||||
use crate::execution_context::ExecutionContext;
|
||||
use crate::terminal;
|
||||
use crate::utils::{which, PathExt};
|
||||
use crate::utils::{PathExt, which};
|
||||
|
||||
pub struct Powershell {
|
||||
path: PathBuf,
|
||||
|
||||
@@ -2,20 +2,20 @@ use std::env;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
use color_eyre::eyre::eyre;
|
||||
use color_eyre::eyre::Context;
|
||||
use color_eyre::eyre::Result;
|
||||
use color_eyre::eyre::eyre;
|
||||
use etcetera::base_strategy::BaseStrategy;
|
||||
|
||||
use crate::command::CommandExt;
|
||||
use crate::config::TmuxConfig;
|
||||
use crate::config::TmuxSessionMode;
|
||||
use crate::terminal::print_separator;
|
||||
use crate::{HOME_DIR, XDG_DIRS};
|
||||
use crate::{
|
||||
execution_context::ExecutionContext,
|
||||
utils::{which, PathExt},
|
||||
utils::{PathExt, which},
|
||||
};
|
||||
use crate::{HOME_DIR, XDG_DIRS};
|
||||
|
||||
use rust_i18n::t;
|
||||
#[cfg(unix)]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::HOME_DIR;
|
||||
use crate::command::CommandExt;
|
||||
use crate::error::{SkipStep, TopgradeError};
|
||||
use crate::HOME_DIR;
|
||||
use color_eyre::eyre::Result;
|
||||
use etcetera::base_strategy::BaseStrategy;
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::executor::{Executor, ExecutorOutput};
|
||||
use crate::terminal::print_separator;
|
||||
use crate::{
|
||||
execution_context::ExecutionContext,
|
||||
utils::{require, PathExt},
|
||||
utils::{PathExt, require},
|
||||
};
|
||||
use rust_i18n::t;
|
||||
use std::path::PathBuf;
|
||||
|
||||
@@ -6,13 +6,13 @@ use color_eyre::eyre::Result;
|
||||
use tracing::debug;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use crate::HOME_DIR;
|
||||
use crate::XDG_DIRS;
|
||||
use crate::command::CommandExt;
|
||||
use crate::execution_context::ExecutionContext;
|
||||
use crate::git::RepoStep;
|
||||
use crate::terminal::print_separator;
|
||||
use crate::utils::{require, PathExt};
|
||||
use crate::HOME_DIR;
|
||||
use crate::XDG_DIRS;
|
||||
use crate::utils::{PathExt, require};
|
||||
use etcetera::base_strategy::BaseStrategy;
|
||||
|
||||
pub fn run_zr(ctx: &ExecutionContext) -> Result<()> {
|
||||
@@ -162,7 +162,7 @@ pub fn run_oh_my_zsh(ctx: &ExecutionContext) -> Result<()> {
|
||||
if let Ok(output) = res_env_zsh {
|
||||
let env_zsh = output.stdout;
|
||||
debug!("Oh-my-zsh: under SSH, setting ZSH={}", env_zsh);
|
||||
env::set_var("ZSH", env_zsh);
|
||||
unsafe { env::set_var("ZSH", env_zsh) };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@ use std::path::PathBuf;
|
||||
|
||||
#[cfg(windows)]
|
||||
use color_eyre::eyre;
|
||||
#[cfg(windows)]
|
||||
use color_eyre::eyre::eyre;
|
||||
use color_eyre::eyre::Context;
|
||||
use color_eyre::eyre::Result;
|
||||
#[cfg(windows)]
|
||||
use color_eyre::eyre::eyre;
|
||||
use rust_i18n::t;
|
||||
use serde::Deserialize;
|
||||
use strum::Display;
|
||||
|
||||
@@ -8,7 +8,7 @@ use std::time::Duration;
|
||||
use chrono::{Local, Timelike};
|
||||
use color_eyre::eyre;
|
||||
use color_eyre::eyre::Context;
|
||||
use console::{style, Key, Term};
|
||||
use console::{Key, Term, style};
|
||||
use notify_rust::{Notification, Timeout};
|
||||
use rust_i18n::t;
|
||||
use tracing::{debug, error};
|
||||
|
||||
@@ -11,8 +11,8 @@ use tracing::{debug, error};
|
||||
use tracing_subscriber::layer::SubscriberExt;
|
||||
use tracing_subscriber::reload::{Handle, Layer};
|
||||
use tracing_subscriber::util::SubscriberInitExt;
|
||||
use tracing_subscriber::{fmt, Registry};
|
||||
use tracing_subscriber::{registry, EnvFilter};
|
||||
use tracing_subscriber::{EnvFilter, registry};
|
||||
use tracing_subscriber::{Registry, fmt};
|
||||
|
||||
use crate::command::CommandExt;
|
||||
use crate::config::DEFAULT_LOG_LEVEL;
|
||||
@@ -218,7 +218,7 @@ pub mod merge_strategies {
|
||||
where
|
||||
T: Merge,
|
||||
{
|
||||
if let Some(ref mut left_inner) = left {
|
||||
if let Some(left_inner) = left {
|
||||
if let Some(right_inner) = right {
|
||||
left_inner.merge(right_inner);
|
||||
}
|
||||
@@ -228,7 +228,7 @@ pub mod merge_strategies {
|
||||
}
|
||||
|
||||
pub fn commands_merge_opt(left: &mut Option<Commands>, right: Option<Commands>) {
|
||||
if let Some(ref mut left_inner) = left {
|
||||
if let Some(left_inner) = left {
|
||||
if let Some(right_inner) = right {
|
||||
left_inner.extend(right_inner);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user