Super pedantic clippy, for fun

main
Michal 2 years ago
parent c1a6460f97
commit f6f7656caa
No known key found for this signature in database
GPG Key ID: A6A1A4DCB22279B9

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

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

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

@ -1,4 +1,4 @@
use colored::*; use colored::Colorize;
use std::process::exit; use std::process::exit;
use std::time::UNIX_EPOCH; use std::time::UNIX_EPOCH;
@ -30,7 +30,7 @@ macro_rules! crash {
pub fn info_fn<S: ToString>(msg: S) { pub fn info_fn<S: ToString>(msg: S) {
let msg = msg.to_string(); 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) { 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 clap::Parser;
use std::env; use std::env;
use std::path::Path; use std::path::Path;
@ -6,7 +12,7 @@ use std::process::Command;
use crate::args::{Args, Operation}; use crate::args::{Args, Operation};
use crate::internal::AppExitCode; use crate::internal::AppExitCode;
use crate::repository::create_config; use crate::repository::create_config;
use crate::workspace::read_cfg; use crate::internal::parse_cfg;
#[global_allocator] #[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
@ -15,7 +21,6 @@ mod args;
mod internal; mod internal;
mod operations; mod operations;
mod repository; mod repository;
mod workspace;
fn main() { fn main() {
if unsafe { libc::geteuid() } == 0 { if unsafe { libc::geteuid() } == 0 {
@ -29,7 +34,7 @@ fn main() {
log!(verbose, "Exclude: {:?}", exclude); log!(verbose, "Exclude: {:?}", exclude);
log!(verbose, "Verbose: You guess. :)"); log!(verbose, "Verbose: You guess. :)");
let config = read_cfg(verbose); let config = parse_cfg(verbose);
log!(verbose, "Config: {:?}", config); log!(verbose, "Config: {:?}", config);
if Path::exists("../.git".as_ref()) { if Path::exists("../.git".as_ref()) {
@ -88,19 +93,19 @@ fn main() {
crash!( crash!(
AppExitCode::BuildInWorkspace, AppExitCode::BuildInWorkspace,
"Cannot build packages in workspace mode" "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 { Operation::Pull {
packages, no_regen, .. packages, no_regen, ..
} => operations::pull(packages, exclude.to_vec(), verbose, no_regen), } => operations::pull(packages, exclude, verbose, no_regen),
Operation::RepoGen => { Operation::RepoGen => {
if !repository { if !repository {
crash!( crash!(
AppExitCode::BuildInWorkspace, AppExitCode::BuildInWorkspace,
"Cannot build packages in workspace mode" "Cannot build packages in workspace mode"
) );
} }
repository::generate(verbose); repository::generate(verbose);
} }

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

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

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

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

@ -2,11 +2,11 @@ use std::path::Path;
use std::process::Command; use std::process::Command;
use std::{env, fs}; 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) { pub fn generate(verbose: bool) {
// Read config struct from mlc.toml // Read config struct from mlc.toml
let config = read_cfg(verbose); let config = parse_cfg(verbose);
log!(verbose, "Config: {:?}", config); log!(verbose, "Config: {:?}", config);
// Get repository name from config // Get repository name from config

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