From f1f41a86e042a37c912cb3a7d3a5eb5344c2bd23 Mon Sep 17 00:00:00 2001 From: Michal Date: Mon, 4 Jul 2022 13:56:25 +0000 Subject: [PATCH] Fixed Cargo.toml & flake.nix, solved issue #6, added new warn(); helper function. --- .envrc | 1 + .gitignore | 1 + Cargo.toml | 1 + flake.nix | 4 ++-- src/internal/strings.rs | 8 ++++++++ src/main.rs | 3 ++- src/operations/upgrade.rs | 17 ++++++++++++++--- 7 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 .envrc diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..8392d15 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake \ No newline at end of file diff --git a/.gitignore b/.gitignore index 4c72f7e..b7f9a44 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ ame.exe .idea result .DS_Store +.direnv \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 53dc266..4be0d1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ authors = ["michal ", "axtlos "] edition = "2021" description = "A fast and efficient AUR helper" license-file = "LICENSE.md" +default-run = "ame" [features] pkg-warner = [] diff --git a/flake.nix b/flake.nix index 293d992..f3e5eff 100644 --- a/flake.nix +++ b/flake.nix @@ -22,7 +22,7 @@ ]; }; - defaultPackage = packages.amethyst; + packages.default = packages.amethyst; apps.amethyst = utils.lib.mkApp { drv = packages.amethyst; @@ -30,7 +30,7 @@ apps.default = apps.amethyst; - devShell = pkgs.mkShell { + devShells.default = pkgs.mkShell { nativeBuildInputs = with pkgs; [ rustc cargo diff --git a/src/internal/strings.rs b/src/internal/strings.rs index 3ffe71d..b2340c2 100644 --- a/src/internal/strings.rs +++ b/src/internal/strings.rs @@ -13,6 +13,14 @@ pub fn info(msg: S) { println!("\x1b[2;22;35m❖\x1b[0m \x1b[1;37m{}\x1b[0m", a) } +#[allow(dead_code)] +pub fn warn(msg: S) { + let a = msg.to_string(); + let a = if internal::uwu_enabled() { uwu!(&a) } else { a }; + + println!("\x1b[2;22;33m!\x1b[0m \x1b[1;37m{}\x1b[0m", a) +} + pub fn crash(msg: S, exit_code: AppExitCode) -> ! { let a = msg.to_string(); let a = if internal::uwu_enabled() { uwu!(&a) } else { a }; diff --git a/src/main.rs b/src/main.rs index a9742b5..466c150 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,8 @@ use internal::commands::ShellCommand; use internal::error::SilentUnwrap; use crate::internal::exit_code::AppExitCode; -use crate::internal::{crash, info, init, log, sort, structs::Options}; +#[allow(unused_imports)] +use crate::internal::{crash, warn, prompt, info, init, log, sort, structs::Options}; #[global_allocator] static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; diff --git a/src/operations/upgrade.rs b/src/operations/upgrade.rs index f03d20d..582a121 100644 --- a/src/operations/upgrade.rs +++ b/src/operations/upgrade.rs @@ -3,7 +3,7 @@ use crate::internal::error::SilentUnwrap; use crate::internal::exit_code::AppExitCode; use crate::internal::rpc::rpcinfo; use crate::operations::aur_install::aur_install; -use crate::{info, log, Options}; +use crate::{info, log, prompt, Options}; pub fn upgrade(options: Options) { let verbosity = options.verbosity; @@ -18,12 +18,23 @@ pub fn upgrade(options: Options) { log("Upgrading repo packages".to_string()); } - ShellCommand::pacman() + let pacman_result = ShellCommand::pacman() .elevated() .args(pacman_args) - .wait_success() + .wait() .silent_unwrap(AppExitCode::PacmanError); + if pacman_result.success() { + info("Successfully upgraded repo packages".to_string()); + } else { + let cont = prompt("Failed to upgrade repo packages, continue to upgrading AUR packages?".to_string(), false); + if !cont { + info("Exiting".to_string()); + std::process::exit(AppExitCode::PacmanError as i32); + } + } + + if verbosity >= 1 { log("Upgrading AUR packages".to_string()); }