refactor: change name from builder to installer
This commit is contained in:
parent
c3db07dc64
commit
7a56816472
7 changed files with 70 additions and 41 deletions
|
@ -3,7 +3,7 @@ use crate::package::identifier::PackageIdentifier;
|
|||
use clap::{Parser, Subcommand};
|
||||
use log::{debug, error, info, trace, warn};
|
||||
use manifest::Manifest;
|
||||
use crate::package::builder::{InstallType, PackageInstaller};
|
||||
use crate::package::installer::{InstallType, PackageInstaller};
|
||||
use crate::package::fetch::fetch_package;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
|
@ -56,6 +56,7 @@ impl Command {
|
|||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap();
|
||||
|
||||
info!("Parsing package...");
|
||||
trace!("Fetching package: {}", package_identifier);
|
||||
let pkgfile = fetch_package(package_identifier.clone()).unwrap();
|
||||
debug!("size: manifest({}kb) data({}kb)", pkgfile.manifest.len() / 1024, pkgfile.data.len() / 1024);
|
||||
|
@ -64,6 +65,7 @@ impl Command {
|
|||
debug!("manifest pkg name: {}", manifest.package.name);
|
||||
trace!("creating installer");
|
||||
let installer = PackageInstaller::new(manifest.clone(), pkgfile, if *build { InstallType::Build } else { InstallType::Bin });
|
||||
info!("Installing: {}...", &manifest.package.name);
|
||||
|
||||
trace!("starting install");
|
||||
match installer.install() {
|
||||
|
|
57
pkgr/src/logging.rs
Normal file
57
pkgr/src/logging.rs
Normal file
|
@ -0,0 +1,57 @@
|
|||
use log::SetLoggerError;
|
||||
use fern::Dispatch;
|
||||
use std::env;
|
||||
use colored::Colorize;
|
||||
|
||||
pub fn setup_logger() -> Result<(), SetLoggerError> {
|
||||
Dispatch::new()
|
||||
.format(|out, message, record| {
|
||||
match record.metadata().target() {
|
||||
"command:stdout" => {
|
||||
out.finish(format_args!(
|
||||
"{} {}",
|
||||
"::".cyan(),
|
||||
message.to_string()
|
||||
));
|
||||
return;
|
||||
}
|
||||
"command:stderr" => {
|
||||
out.finish(format_args!(
|
||||
"{} {}",
|
||||
"!!".red(),
|
||||
message.to_string()
|
||||
));
|
||||
return;
|
||||
}
|
||||
_ => {
|
||||
out.finish(format_args!(
|
||||
"{} {}",
|
||||
// Some logic so messages look nice
|
||||
if message.to_string().len() > 0 {
|
||||
match record
|
||||
.level()
|
||||
.to_string()
|
||||
.chars()
|
||||
.nth(0)
|
||||
.unwrap_or('T')
|
||||
{
|
||||
'T' => "[TRACE]".bright_blue(),
|
||||
'D' => "??".green(),
|
||||
'I' => "=>".blue(),
|
||||
'W' => "##".yellow(),
|
||||
'E' => "!!".red(),
|
||||
_ => "**".blue(),
|
||||
}.to_string()
|
||||
} else { "".to_string() },
|
||||
message.to_string().bright_white()
|
||||
))
|
||||
}
|
||||
}
|
||||
})
|
||||
.level(env::var("PKGR_LOG_LEVEL")
|
||||
.unwrap_or_else(|_| "info".to_string())
|
||||
.parse()
|
||||
.unwrap_or(log::LevelFilter::Info))
|
||||
.chain(std::io::stdout())
|
||||
.apply()
|
||||
}
|
|
@ -1,15 +1,18 @@
|
|||
use std::process::Command;
|
||||
use clap::Parser;
|
||||
use colored::Colorize;
|
||||
use crate::commands::Cli;
|
||||
use log::{SetLoggerError, trace};
|
||||
use std::env;
|
||||
use log::trace;
|
||||
use crate::process::Process;
|
||||
|
||||
mod process;
|
||||
mod commands;
|
||||
mod package;
|
||||
mod tmp;
|
||||
mod tmpfs;
|
||||
mod logging;
|
||||
|
||||
fn main() {
|
||||
setup_logger().expect("Unable to setup logger.");
|
||||
logging::setup_logger().expect("Unable to setup logger.");
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
{
|
||||
|
@ -31,36 +34,3 @@ fn main() {
|
|||
|
||||
trace!("Exiting...");
|
||||
}
|
||||
|
||||
fn setup_logger() -> Result<(), SetLoggerError> {
|
||||
fern::Dispatch::new()
|
||||
.format(|out, message, record| {
|
||||
out.finish(format_args!(
|
||||
"{} {}",
|
||||
// Some logic so messages look nice
|
||||
if message.to_string().len() > 0 {
|
||||
match record
|
||||
.level()
|
||||
.to_string()
|
||||
.chars()
|
||||
.nth(0)
|
||||
.unwrap_or('T')
|
||||
{
|
||||
'T' => "[TRACE]".cyan(),
|
||||
'D' => "??".green(),
|
||||
'I' => "=>".blue(),
|
||||
'W' => "##".yellow(),
|
||||
'E' => "!!".red(),
|
||||
_ => "**".blue(),
|
||||
}.to_string()
|
||||
} else { "".to_string() },
|
||||
message.to_string().bright_white()
|
||||
))
|
||||
})
|
||||
.level(env::var("PKGR_LOG_LEVEL")
|
||||
.unwrap_or_else(|_| "info".to_string())
|
||||
.parse()
|
||||
.unwrap_or(log::LevelFilter::Info))
|
||||
.chain(std::io::stdout())
|
||||
.apply()
|
||||
}
|
||||
|
|
|
@ -3,9 +3,9 @@ use log::{debug, trace};
|
|||
use errors::{BinError, BuildError, InstallError};
|
||||
use manifest::Manifest;
|
||||
use pkgfile::PKGFile;
|
||||
use crate::tmp::TempDir;
|
||||
use crate::tmpfs::TempDir;
|
||||
|
||||
mod errors;
|
||||
pub mod errors;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum InstallType {
|
|
@ -1,3 +1,3 @@
|
|||
pub mod identifier;
|
||||
pub mod builder;
|
||||
pub mod installer;
|
||||
pub mod fetch;
|
Loading…
Reference in a new issue