You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
malachite/src/main.rs

95 lines
3.1 KiB
Rust

#![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::cargo)]
#![allow(clippy::too_many_lines)]
2 years ago
use clap::Parser;
3 years ago
use crate::args::{Args, Operation};
use crate::internal::parse_cfg;
2 years ago
use crate::internal::AppExitCode;
3 years ago
#[cfg(target_os = "linux")]
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
mod args;
3 years ago
mod internal;
3 years ago
mod operations;
3 years ago
mod repository;
3 years ago
fn main() {
#[cfg(target_os = "linux")]
if unsafe { libc::geteuid() } == 0 {
crash!(AppExitCode::RunAsRoot, "Running malachite as root is disallowed as it can lead to system breakage. Instead, malachite will prompt you when it needs superuser permissions");
}
// Get required variables
let args: Args = Args::parse();
let exclude = &args.exclude;
let verbose = args.verbose;
log!(verbose, "Args: {:?}", args);
log!(verbose, "Exclude: {:?}", exclude);
log!(verbose, "Verbose: You guess. :)");
// Arg matching
match args.subcommand.unwrap_or(Operation::Clone) {
Operation::Clone => operations::clone(verbose),
Operation::Build {
packages, no_regen, ..
} => {
// Parse config
let config = parse_cfg(verbose);
log!(verbose, "Config: {:?}", config);
// Get repository mode status
let repository = config.base.mode == "repository";
log!(verbose, "Repository Mode: {:?}", repository);
if !repository {
crash!(
AppExitCode::BuildInWorkspace,
"Cannot build packages in workspace mode"
);
}
operations::build(&packages, exclude.clone(), no_regen, verbose);
}
Operation::Pull {
packages, no_regen, ..
} => operations::pull(packages, exclude, verbose, no_regen),
Operation::RepoGen => {
// Parse config
let config = parse_cfg(verbose);
log!(verbose, "Config: {:?}", config);
// Get repository mode status
let repository = config.base.mode == "repository";
log!(verbose, "Repository Mode: {:?}", repository);
if !repository {
2 years ago
crash!(
AppExitCode::BuildInWorkspace,
"Cannot generate repository in workspace mode"
);
}
repository::generate(verbose);
3 years ago
}
Operation::Config => operations::config(verbose),
Operation::Prune => {
// Parse config
let config = parse_cfg(verbose);
log!(verbose, "Config: {:?}", config);
// Get repository mode status
let repository = config.base.mode == "repository";
log!(verbose, "Repository Mode: {:?}", repository);
if !repository {
crash!(
AppExitCode::BuildInWorkspace,
"Cannot prune packages in workspace mode"
);
}
operations::prune(verbose);
}
Operation::Clean { force, .. } => operations::clean(verbose, force),
Operation::Info => operations::info(verbose),
}
3 years ago
}