From 2a67c6f6330c9cb510a63eb5896ca06e053d611b Mon Sep 17 00:00:00 2001 From: Raine Date: Sat, 14 Oct 2023 22:39:51 +0200 Subject: [PATCH] feat: add prompt to command --- pkgr/src/commands.rs | 16 ++++++++++++++-- pkgr/src/package/installer/mod.rs | 12 +++--------- pkgr/src/package/queue.rs | 20 +++++++++++++++++--- pkgr/src/tmpfs.rs | 2 +- pkgr/src/util/fs.rs | 5 +++-- pkgr/src/util/prompts.rs | 1 + 6 files changed, 39 insertions(+), 17 deletions(-) diff --git a/pkgr/src/commands.rs b/pkgr/src/commands.rs index 869e961..b996408 100644 --- a/pkgr/src/commands.rs +++ b/pkgr/src/commands.rs @@ -1,16 +1,17 @@ use std::process::exit; use clap::{Parser, Subcommand}; +use colored::Colorize; use log::{debug, error, info, trace, warn}; -use colored::Colorize; use manifest::package::PackageType; -use crate::CONFIG; + use crate::package::identifier::PackageIdentifier; use crate::package::Package; use crate::package::queue::PackageQueue; use crate::process::Process; use crate::types::fetch::TryFetch; +use crate::util::prompts::prompt_bool; #[derive(Parser, Debug)] #[clap(name = "pkgr", version)] @@ -25,6 +26,8 @@ pub enum Command { Install { #[arg(short, long, default_value_t = false)] build: bool, + #[arg(short, long, default_value_t = false)] + ask: bool, package_identifier: PackageIdentifier, }, /// Remove a package from the system @@ -57,6 +60,7 @@ impl Command { match self { Command::Install { build, + ask, package_identifier, } => { warn!("Installer does not run in isolation."); @@ -80,6 +84,14 @@ impl Command { let mut queue = PackageQueue::new(); queue.add_package(pkg, *build); trace!("Installing queue..."); + { + if *ask { + info!(target: "item", "{}", queue); + if prompt_bool("Install queue?", false) { + + } + } + } queue.install(*build); let end = std::time::Instant::now(); diff --git a/pkgr/src/package/installer/mod.rs b/pkgr/src/package/installer/mod.rs index da37f1b..30343cb 100644 --- a/pkgr/src/package/installer/mod.rs +++ b/pkgr/src/package/installer/mod.rs @@ -1,22 +1,16 @@ +use std::io; use std::fs::remove_dir_all; use std::path::Path; -use std::process::exit; -use std::{io, thread}; -use libc::SIGINT; -use log::{debug, error, info, trace}; +use log::{debug, trace}; use errors::{BinError, BuildError, InstallError}; use manifest::Manifest; use pkgfile::PKGFile; -use crate::CONFIG; -use crate::package::identifier::{PackageIdentifier, PackageLocator}; -use crate::package::Package; use crate::tmpfs::TempDir; use crate::types::fetch::TryFetch; -use crate::util::fs::{copy_recursively, visit_dirs}; -use crate::util::prompts::{is_noninteractive, prompt_bool}; +use crate::util::fs::copy_recursively; pub mod errors; diff --git a/pkgr/src/package/queue.rs b/pkgr/src/package/queue.rs index 16a7b95..601d8da 100644 --- a/pkgr/src/package/queue.rs +++ b/pkgr/src/package/queue.rs @@ -1,8 +1,11 @@ +use std::fmt::{Display, Formatter}; + use log::trace; + use crate::package::Package; pub struct PackageQueue { - packages: Vec + packages: Vec, } impl PackageQueue { @@ -17,7 +20,7 @@ impl PackageQueue { for dependency in dependencies { trace!("Checking package: {}", &dependency.identifier); if self.packages.contains(&dependency) { - continue + continue; } trace!("Adding package: {}", &dependency.identifier); self.packages.push(dependency); @@ -31,7 +34,18 @@ impl PackageQueue { self.packages .iter_mut() .for_each(|pkg| { - pkg.install(build); + pkg.install(build).expect("TODO: panic message"); }); } } + +impl Display for PackageQueue { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + for pkg in &self.packages { + if let Err(e) = write!(f, "{}", pkg.identifier) { + return Err(e); + } + } + write!(f, "") + } +} \ No newline at end of file diff --git a/pkgr/src/tmpfs.rs b/pkgr/src/tmpfs.rs index e83b860..7d68892 100644 --- a/pkgr/src/tmpfs.rs +++ b/pkgr/src/tmpfs.rs @@ -1,4 +1,4 @@ -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use crate::CONFIG; diff --git a/pkgr/src/util/fs.rs b/pkgr/src/util/fs.rs index 03b5cb2..815b950 100644 --- a/pkgr/src/util/fs.rs +++ b/pkgr/src/util/fs.rs @@ -1,6 +1,7 @@ -use std::path::Path; -use std::fs::DirEntry; use std::{fs, io}; +use std::fs::DirEntry; +use std::path::Path; + use log::trace; pub fn visit_dirs(dir: &Path, cb: &dyn Fn(&DirEntry)) -> std::io::Result<()> { diff --git a/pkgr/src/util/prompts.rs b/pkgr/src/util/prompts.rs index 6c3e11a..9dcae5d 100644 --- a/pkgr/src/util/prompts.rs +++ b/pkgr/src/util/prompts.rs @@ -1,4 +1,5 @@ use std::io::Write; + use log::trace; pub fn is_noninteractive() -> bool {