feat: add prompt to command
This commit is contained in:
parent
e4fe3c5779
commit
2a67c6f633
6 changed files with 39 additions and 17 deletions
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
use std::fmt::{Display, Formatter};
|
||||
|
||||
use log::trace;
|
||||
|
||||
use crate::package::Package;
|
||||
|
||||
pub struct PackageQueue {
|
||||
packages: Vec<Package>
|
||||
packages: Vec<Package>,
|
||||
}
|
||||
|
||||
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, "")
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
use std::path::{Path, PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::CONFIG;
|
||||
|
||||
|
|
|
@ -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<()> {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use std::io::Write;
|
||||
|
||||
use log::trace;
|
||||
|
||||
pub fn is_noninteractive() -> bool {
|
||||
|
|
Loading…
Reference in a new issue