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 clap::{Parser, Subcommand};
|
||||||
use log::{debug, error, info, trace, warn};
|
use log::{debug, error, info, trace, warn};
|
||||||
use manifest::Manifest;
|
use manifest::Manifest;
|
||||||
use crate::package::builder::{InstallType, PackageInstaller};
|
use crate::package::installer::{InstallType, PackageInstaller};
|
||||||
use crate::package::fetch::fetch_package;
|
use crate::package::fetch::fetch_package;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
|
@ -56,6 +56,7 @@ impl Command {
|
||||||
.duration_since(std::time::UNIX_EPOCH)
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
info!("Parsing package...");
|
||||||
trace!("Fetching package: {}", package_identifier);
|
trace!("Fetching package: {}", package_identifier);
|
||||||
let pkgfile = fetch_package(package_identifier.clone()).unwrap();
|
let pkgfile = fetch_package(package_identifier.clone()).unwrap();
|
||||||
debug!("size: manifest({}kb) data({}kb)", pkgfile.manifest.len() / 1024, pkgfile.data.len() / 1024);
|
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);
|
debug!("manifest pkg name: {}", manifest.package.name);
|
||||||
trace!("creating installer");
|
trace!("creating installer");
|
||||||
let installer = PackageInstaller::new(manifest.clone(), pkgfile, if *build { InstallType::Build } else { InstallType::Bin });
|
let installer = PackageInstaller::new(manifest.clone(), pkgfile, if *build { InstallType::Build } else { InstallType::Bin });
|
||||||
|
info!("Installing: {}...", &manifest.package.name);
|
||||||
|
|
||||||
trace!("starting install");
|
trace!("starting install");
|
||||||
match installer.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 clap::Parser;
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use crate::commands::Cli;
|
use crate::commands::Cli;
|
||||||
use log::{SetLoggerError, trace};
|
use log::trace;
|
||||||
use std::env;
|
use crate::process::Process;
|
||||||
|
|
||||||
|
mod process;
|
||||||
mod commands;
|
mod commands;
|
||||||
mod package;
|
mod package;
|
||||||
mod tmp;
|
mod tmpfs;
|
||||||
|
mod logging;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
setup_logger().expect("Unable to setup logger.");
|
logging::setup_logger().expect("Unable to setup logger.");
|
||||||
|
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
{
|
{
|
||||||
|
@ -31,36 +34,3 @@ fn main() {
|
||||||
|
|
||||||
trace!("Exiting...");
|
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 errors::{BinError, BuildError, InstallError};
|
||||||
use manifest::Manifest;
|
use manifest::Manifest;
|
||||||
use pkgfile::PKGFile;
|
use pkgfile::PKGFile;
|
||||||
use crate::tmp::TempDir;
|
use crate::tmpfs::TempDir;
|
||||||
|
|
||||||
mod errors;
|
pub mod errors;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum InstallType {
|
pub enum InstallType {
|
|
@ -1,3 +1,3 @@
|
||||||
pub mod identifier;
|
pub mod identifier;
|
||||||
pub mod builder;
|
pub mod installer;
|
||||||
pub mod fetch;
|
pub mod fetch;
|
Loading…
Reference in a new issue