Skip to content

Commit

Permalink
fix(install): add constraints to local installs binary name
Browse files Browse the repository at this point in the history
  • Loading branch information
QaidVoid committed Nov 6, 2024
1 parent 4bd9739 commit bfe004f
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 32 deletions.
10 changes: 5 additions & 5 deletions src/core/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
color::{Color, ColorExt},
constant::CAP_MKNOD,
},
success, warn,
successln, warnln,
};

use super::constant::CAP_SYS_ADMIN;
Expand Down Expand Up @@ -64,11 +64,11 @@ pub async fn check_health() {

println!("{0} USER NAMESPACE CHECK {0}", "☵".repeat(4));
for error in &errors {
warn!("{}", error);
warnln!("{}", error);
}

if errors.is_empty() {
success!("User namespace checked successfully.")
successln!("User namespace checked successfully.")
} else {
println!(
"{} {}",
Expand Down Expand Up @@ -168,13 +168,13 @@ async fn check_fusermount() {
}

if !error.is_empty() {
warn!(
warnln!(
"{}\n{} {}",
error,
"More info at:".color(Color::Cyan),
"https://l.ajam.dev/fuse".color(Color::Blue)
);
} else {
success!("Fuse checked successfully.");
successln!("Fuse checked successfully.");
}
}
36 changes: 32 additions & 4 deletions src/core/log.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,55 @@
#[macro_export]
macro_rules! warn {
macro_rules! warnln {
($($arg:tt)*) => {
println!("{} {}", "[WARN]".color(Color::BrightYellow).bold(), format!($($arg)*))
};
}

#[macro_export]
macro_rules! info {
macro_rules! infoln {
($($arg:tt)*) => {
println!("{} {}", "[INFO]".color(Color::BrightBlue).bold(), format!($($arg)*))
};
}

#[macro_export]
macro_rules! error {
macro_rules! errorln {
($($arg:tt)*) => {
eprintln!("{} {}", "[ERROR]".color(Color::BrightRed).bold(), format!($($arg)*))
};
}

#[macro_export]
macro_rules! success {
macro_rules! successln {
($($arg:tt)*) => {
println!("{} {}", "[SUCCESS]".color(Color::BrightGreen).bold(), format!($($arg)*))
};
}

#[macro_export]
macro_rules! warn {
($($arg:tt)*) => {
print!("{} {}", "[WARN]".color(Color::BrightYellow).bold(), format!($($arg)*))
};
}

#[macro_export]
macro_rules! info {
($($arg:tt)*) => {
print!("{} {}", "[INFO]".color(Color::BrightBlue).bold(), format!($($arg)*))
};
}

#[macro_export]
macro_rules! error {
($($arg:tt)*) => {
eprint!("{} {}", "[ERROR]".color(Color::BrightRed).bold(), format!($($arg)*))
};
}

#[macro_export]
macro_rules! success {
($($arg:tt)*) => {
print!("{} {}", "[SUCCESS]".color(Color::BrightGreen).bold(), format!($($arg)*))
};
}
2 changes: 1 addition & 1 deletion src/core/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ pub fn interactive_ask(ques: &str, ask_type: AskType) -> Result<String> {
if ask_type == AskType::Warn {
warn!("{ques}");
} else {
println!("{ques}");
print!("{ques}");
}

std::io::stdout().flush()?;
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub async fn init() -> Result<()> {

let path_env = env::var("PATH")?;
if !path_env.split(':').any(|p| Path::new(p) == *BIN_PATH) {
warn!(
warnln!(
"{} is not in {1}. Please add it to {1} to use installed binaries.",
&*BIN_PATH.to_string_lossy().color(Color::Blue),
"PATH".color(Color::BrightGreen).bold()
Expand Down
4 changes: 2 additions & 2 deletions src/misc/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
error,
package::parse_package_query,
registry::{select_single_package, PackageRegistry},
success,
successln,
};

fn extract_filename(url: &str) -> String {
Expand Down Expand Up @@ -117,7 +117,7 @@ async fn download(url: &str, output: Option<String>) -> Result<()> {
fs::set_permissions(&output_path, Permissions::from_mode(0o755)).await?;
}

success!("Downloaded {}", output_path.display().color(Color::Blue));
successln!("Downloaded {}", output_path.display().color(Color::Blue));

Ok(())
}
Expand Down
9 changes: 6 additions & 3 deletions src/package/appimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
constant::{BIN_PATH, PACKAGES_PATH},
util::{download, home_data_path},
},
error, info,
error, infoln,
};

use super::Package;
Expand Down Expand Up @@ -68,9 +68,12 @@ fn normalize_image(image: DynamicImage) -> DynamicImage {
let (new_width, new_height) = find_nearest_supported_dimension(width, height);

if (width, height) != (new_width, new_height) {
info!(
infoln!(
"Resizing image from {}x{} to {}x{}",
width, height, new_width, new_height
width,
height,
new_width,
new_height
);
image.resize(new_width, new_height, FilterType::Lanczos3)
} else {
Expand Down
11 changes: 10 additions & 1 deletion src/package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,16 @@ pub fn parse_package_query(query: &str) -> PackageQuery {

#[inline]
pub fn ask_package_info(name: &str, path: &Path, size: u64) -> Result<ResolvedPackage> {
let bin_name = interactive_ask("Binary Name:", AskType::Normal)?;
let bin_name = loop {
let bin_name = interactive_ask("Binary Name: ", AskType::Normal)?;
if bin_name.is_empty() {
eprintln!("Binary name can't be empty.");
} else if !bin_name.chars().all(|c| c.is_alphanumeric()) {
eprintln!("Binary name must only contain letters and numbers.");
} else {
break bin_name;
}
};

let package = Package {
pkg: name.to_owned(),
Expand Down
4 changes: 2 additions & 2 deletions src/package/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
},
package::appimage::remove_applinks,
registry::installed::{InstalledPackage, InstalledPackages},
success,
successln,
};

pub struct Remover {
Expand All @@ -34,7 +34,7 @@ impl Remover {
self.remove_package_path(&install_dir).await?;
installed_packages.unregister_package(&self.package).await?;

success!(
successln!(
"Package {} removed successfully.",
package.full_name('/').color(Color::Blue)
);
Expand Down
6 changes: 3 additions & 3 deletions src/package/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
color::{Color, ColorExt},
util::{format_bytes, validate_checksum},
},
error, info, warn,
error, infoln, warnln,
};

use super::ResolvedPackage;
Expand Down Expand Up @@ -43,7 +43,7 @@ impl Runner {
self.install_path.to_string_lossy().color(Color::Blue)
));
} else {
info!(
infoln!(
"Found existing cache for {}",
package_name.color(Color::Blue)
);
Expand Down Expand Up @@ -108,7 +108,7 @@ impl Runner {
}

if package.bsum == "null" {
warn!(
warnln!(
"Missing checksum for {}. Installing anyway.",
package.full_name('/').color(Color::Blue)
);
Expand Down
4 changes: 2 additions & 2 deletions src/package/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
core::color::{Color, ColorExt},
error,
registry::PackageRegistry,
success,
successln,
};

use super::{parse_package_query, PackageQuery, ResolvedPackage};
Expand Down Expand Up @@ -98,7 +98,7 @@ impl Updater {
}

total_progress_bar.finish_and_clear();
success!(
successln!(
"{} packages updated.",
update_count.color(Color::BrightMagenta)
);
Expand Down
4 changes: 2 additions & 2 deletions src/registry/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
color::{Color, ColorExt},
config::Repository,
},
warn,
warnln,
};

use super::fetcher::MetadataFetcher;
Expand All @@ -27,7 +27,7 @@ impl MetadataLoader {
.with_file_name(format!("{}.remote.bsum", repo.name));
let local_checksum = fs::read(&checksum_path).await.unwrap_or_default();
if checksum != local_checksum {
warn!("Local registry is outdated. Refetching...");
warnln!("Local registry is outdated. Refetching...");
let content = fetcher.execute(repo).await;
fs::write(checksum_path, &checksum).await?;
return content;
Expand Down
8 changes: 4 additions & 4 deletions src/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ use crate::{
config::CONFIG,
util::{get_terminal_width, wrap_text},
},
error, info,
error, infoln,
package::{
image::get_package_image_string, parse_package_query, update::Updater, ResolvedPackage,
},
success,
successln,
};

mod fetcher;
Expand Down Expand Up @@ -304,7 +304,7 @@ impl PackageRegistry {
drop(installed_guard);
match result {
Ok(_) => {
success!(
successln!(
"{} is linked to binary path",
package_name.color(Color::Blue)
);
Expand Down Expand Up @@ -336,7 +336,7 @@ impl PackageRegistry {
}

pub fn select_single_package(packages: &[ResolvedPackage]) -> Result<&ResolvedPackage> {
info!(
infoln!(
"Multiple packages available for {}",
packages[0].package.pkg.clone().color(Color::Blue)
);
Expand Down
4 changes: 2 additions & 2 deletions src/registry/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::{
ask_package_info, parse_package_query, run::Runner, Package, PackageQuery, ResolvedPackage,
},
registry::installed::InstalledPackages,
warn,
warnln,
};

use super::select_single_package;
Expand Down Expand Up @@ -126,7 +126,7 @@ impl PackageStorage {
.into_iter()
.filter_map(|(package, is_installed)| {
if is_installed {
warn!(
warnln!(
"{} is already installed - {}",
package.package.full_name('/'),
if force { "reinstalling" } else { "skipping" }
Expand Down

0 comments on commit bfe004f

Please sign in to comment.