Super pedantic clippy, for fun

main
Michal 2 years ago
parent edc43e43f8
commit c94a885429

@ -5,6 +5,8 @@ authors = [ "michal <michal@tar.black>" ]
edition = "2021"
description = "Packaging tool for pacman repositories"
license-file = "LICENSE"
keywords = [ "pacman", "repository", "packaging" ]
categories = [ "filesystem", "development-tools" ]
[[bin]]
name = "mlc"

@ -1,5 +1,7 @@
pub use exit_codes::*;
pub use read::*;
mod exit_codes;
mod read;
pub mod strings;
pub mod structs;

@ -5,13 +5,13 @@ use crate::internal::structs::{Config, Repo, SplitRepo, UnexpandedConfig};
use crate::internal::AppExitCode;
use crate::{crash, log};
pub fn read_cfg(verbose: bool) -> Config {
pub fn parse_cfg(verbose: bool) -> Config {
// Crash if mlc.toml doesn't exist
if !Path::exists("mlc.toml".as_ref()) {
crash!(
AppExitCode::ConfigNotFound,
"Config file not found (mlc.toml)"
)
);
}
// Reading the config file to an UnexpandedConfig struct

@ -1,4 +1,4 @@
use colored::*;
use colored::Colorize;
use std::process::exit;
use std::time::UNIX_EPOCH;
@ -30,7 +30,7 @@ macro_rules! crash {
pub fn info_fn<S: ToString>(msg: S) {
let msg = msg.to_string();
println!("{} {}", LOGO_SYMBOL.black(), msg.bold())
println!("{} {}", LOGO_SYMBOL.black(), msg.bold());
}
pub fn log_fn<S: ToString>(msg: S, verbose: bool) {

@ -1,3 +1,9 @@
#![warn(
clippy::all,
clippy::pedantic,
clippy::nursery,
)]
use clap::Parser;
use std::env;
use std::path::Path;
@ -6,7 +12,7 @@ use std::process::Command;
use crate::args::{Args, Operation};
use crate::internal::AppExitCode;
use crate::repository::create_config;
use crate::workspace::read_cfg;
use crate::internal::parse_cfg;
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
@ -15,7 +21,6 @@ mod args;
mod internal;
mod operations;
mod repository;
mod workspace;
fn main() {
if unsafe { libc::geteuid() } == 0 {
@ -29,7 +34,7 @@ fn main() {
log!(verbose, "Exclude: {:?}", exclude);
log!(verbose, "Verbose: You guess. :)");
let config = read_cfg(verbose);
let config = parse_cfg(verbose);
log!(verbose, "Config: {:?}", config);
if Path::exists("../.git".as_ref()) {
@ -88,19 +93,19 @@ fn main() {
crash!(
AppExitCode::BuildInWorkspace,
"Cannot build packages in workspace mode"
)
);
}
operations::build(packages, exclude.to_vec(), no_regen, verbose)
operations::build(&packages, exclude.clone(), no_regen, verbose);
}
Operation::Pull {
packages, no_regen, ..
} => operations::pull(packages, exclude.to_vec(), verbose, no_regen),
} => operations::pull(packages, exclude, verbose, no_regen),
Operation::RepoGen => {
if !repository {
crash!(
AppExitCode::BuildInWorkspace,
"Cannot build packages in workspace mode"
)
);
}
repository::generate(verbose);
}

@ -1,10 +1,10 @@
use crate::internal::structs::{ErroredPackage, Repo};
use crate::internal::AppExitCode;
use crate::{crash, info, log, repository, workspace};
use crate::{crash, info, log, repository, internal};
pub fn build(packages: Vec<String>, exclude: Vec<String>, no_regen: bool, verbose: bool) {
pub fn build(packages: &[String], exclude: Vec<String>, no_regen: bool, verbose: bool) {
// Read config struct from mlc.toml
let config = workspace::read_cfg(verbose);
let config = internal::parse_cfg(verbose);
log!(verbose, "Config: {:?}", config);
let all = packages.is_empty();
log!(verbose, "All: {:?}", all);
@ -36,7 +36,7 @@ pub fn build(packages: Vec<String>, exclude: Vec<String>, no_regen: bool, verbos
let mut errored: Vec<ErroredPackage> = vec![];
if !packages.is_empty() && !all {
log!(verbose, "Packages not empty: {:?}", packages);
for pkg in &packages {
for pkg in packages.iter() {
// If repo is not in config, crash
if !repos.iter().map(|x| x.name.clone()).any(|x| x == *pkg) {
crash!(

@ -1,10 +1,10 @@
use std::process::Command;
use crate::{info, log, workspace};
use crate::{info, log};
pub fn clone(verbose: bool) {
// Read config struct from mlc.toml
let config = workspace::read_cfg(verbose);
let config = crate::internal::parse_cfg(verbose);
log!(verbose, "Config: {:?}", config);
let repos = &config.repositories;
log!(verbose, "Repos: {:?}", repos);

@ -16,7 +16,7 @@ struct RepoDisplay {
pub fn info(verbose: bool) {
log!(verbose, "Showing Info");
let config = crate::workspace::read_cfg(verbose);
let config = crate::internal::parse_cfg(verbose);
log!(verbose, "Config: {:?}", config);
// Add the branch to the name if it's not the default branch for said repository

@ -4,7 +4,7 @@ use std::path::PathBuf;
use crate::info;
use crate::log;
use crate::read_cfg;
use crate::parse_cfg;
#[derive(Debug, Clone)]
struct PackageFile {
@ -15,7 +15,7 @@ struct PackageFile {
pub fn prune(verbose: bool) {
// Read config struct from mlc.toml
let config = read_cfg(verbose);
let config = parse_cfg(verbose);
log!(verbose, "Config: {:?}", config);
// Read current directory
@ -46,6 +46,7 @@ pub fn prune(verbose: bool) {
for cap in re.captures_iter(file) {
let name = cap[1].to_string();
let mut ver = cap[2].to_string();
// Remove the leading "-" from the version and ext strings
ver.remove(0).to_string();
let mut ext = cap[3].to_string();
ext.remove(0).to_string();
@ -61,7 +62,7 @@ pub fn prune(verbose: bool) {
log!(verbose, "Sorting Package: {:?}", package);
let name = &package.name;
let mut found = false;
for p in packages_by_name.iter_mut() {
for p in &mut packages_by_name {
if &p[0].name == name {
log!(verbose, "Found {}", name);
found = true;
@ -75,14 +76,14 @@ pub fn prune(verbose: bool) {
}
// Sort each Vector of Vectors by version
for p in packages_by_name.iter_mut() {
for p in &mut packages_by_name {
log!(verbose, "Sorting {:?}", p);
p.sort_by(|a, b| b.ver.cmp(&a.ver));
}
// Pushes all but the 4 most recent versions of each package into a new Vector of PackageFiles
let mut packages_to_delete: Vec<PackageFile> = vec![];
for p in packages_by_name.iter() {
for p in &packages_by_name {
let mut to_delete = vec![];
for (i, _) in p.iter().enumerate() {
if i >= 3 {
@ -95,7 +96,7 @@ pub fn prune(verbose: bool) {
log!(verbose, "Packages to delete: {:?}", packages_to_delete);
// Delete all packages in packages_to_delete
for p in packages_to_delete.iter() {
for p in &packages_to_delete {
let path = format!("{}-{}-{}", p.name, p.ver, p.ext);
log!(verbose, "Deleting {}", path);
std::process::Command::new("bash")
@ -111,7 +112,7 @@ pub fn prune(verbose: bool) {
// Print which packages were deleted
if !packages_to_delete.is_empty() {
info!("Deleted the following packages:");
for p in packages_to_delete.iter_mut() {
for p in &mut packages_to_delete {
info!("{}-{}", p.name.replace("./", ""), p.ver);
}
} else {

@ -2,7 +2,7 @@ use std::env;
use std::process::Command;
use crate::info;
use crate::{crash, internal::AppExitCode, log, workspace::read_cfg};
use crate::{crash, internal::AppExitCode, log};
fn do_the_pulling(
repos: Vec<String>,
@ -84,14 +84,14 @@ fn do_the_pulling(
info!("Rebuilding packages: {}", &packages_to_rebuild.join(", "));
log!(verbose, "Rebuilding packages: {:?}", &packages_to_rebuild);
crate::operations::build(packages_to_rebuild, vec![], no_regen, verbose);
crate::operations::build(&packages_to_rebuild, vec![], no_regen, verbose);
}
}
}
pub fn pull(packages: Vec<String>, exclude: Vec<String>, verbose: bool, no_regen: bool) {
pub fn pull(packages: Vec<String>, exclude: &[String], verbose: bool, no_regen: bool) {
// Read config file
let config = read_cfg(verbose);
let config = crate::parse_cfg(verbose);
log!(verbose, "Config: {:?}", config);
// If no packages are specified, imply all
let all = packages.is_empty();
@ -117,7 +117,7 @@ pub fn pull(packages: Vec<String>, exclude: Vec<String>, verbose: bool, no_regen
// Subtract exclude from repos_applicable
if !exclude.is_empty() {
for ex in &exclude {
for ex in exclude.iter() {
repos_applicable.retain(|x| *x != *ex);
}
}

@ -2,11 +2,11 @@ use std::path::Path;
use std::process::Command;
use std::{env, fs};
use crate::{crash, info, internal::AppExitCode, log, workspace::read_cfg};
use crate::{crash, info, internal::AppExitCode, log, internal::parse_cfg};
pub fn generate(verbose: bool) {
// Read config struct from mlc.toml
let config = read_cfg(verbose);
let config = parse_cfg(verbose);
log!(verbose, "Config: {:?}", config);
// Get repository name from config

@ -1,3 +0,0 @@
pub use read::*;
mod read;
Loading…
Cancel
Save