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 std::process::exit;
|
||||||
|
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
use colored::Colorize;
|
||||||
use log::{debug, error, info, trace, warn};
|
use log::{debug, error, info, trace, warn};
|
||||||
|
|
||||||
use colored::Colorize;
|
|
||||||
use manifest::package::PackageType;
|
use manifest::package::PackageType;
|
||||||
use crate::CONFIG;
|
|
||||||
use crate::package::identifier::PackageIdentifier;
|
use crate::package::identifier::PackageIdentifier;
|
||||||
use crate::package::Package;
|
use crate::package::Package;
|
||||||
use crate::package::queue::PackageQueue;
|
use crate::package::queue::PackageQueue;
|
||||||
use crate::process::Process;
|
use crate::process::Process;
|
||||||
use crate::types::fetch::TryFetch;
|
use crate::types::fetch::TryFetch;
|
||||||
|
use crate::util::prompts::prompt_bool;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[clap(name = "pkgr", version)]
|
#[clap(name = "pkgr", version)]
|
||||||
|
@ -25,6 +26,8 @@ pub enum Command {
|
||||||
Install {
|
Install {
|
||||||
#[arg(short, long, default_value_t = false)]
|
#[arg(short, long, default_value_t = false)]
|
||||||
build: bool,
|
build: bool,
|
||||||
|
#[arg(short, long, default_value_t = false)]
|
||||||
|
ask: bool,
|
||||||
package_identifier: PackageIdentifier,
|
package_identifier: PackageIdentifier,
|
||||||
},
|
},
|
||||||
/// Remove a package from the system
|
/// Remove a package from the system
|
||||||
|
@ -57,6 +60,7 @@ impl Command {
|
||||||
match self {
|
match self {
|
||||||
Command::Install {
|
Command::Install {
|
||||||
build,
|
build,
|
||||||
|
ask,
|
||||||
package_identifier,
|
package_identifier,
|
||||||
} => {
|
} => {
|
||||||
warn!("Installer does not run in isolation.");
|
warn!("Installer does not run in isolation.");
|
||||||
|
@ -80,6 +84,14 @@ impl Command {
|
||||||
let mut queue = PackageQueue::new();
|
let mut queue = PackageQueue::new();
|
||||||
queue.add_package(pkg, *build);
|
queue.add_package(pkg, *build);
|
||||||
trace!("Installing queue...");
|
trace!("Installing queue...");
|
||||||
|
{
|
||||||
|
if *ask {
|
||||||
|
info!(target: "item", "{}", queue);
|
||||||
|
if prompt_bool("Install queue?", false) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
queue.install(*build);
|
queue.install(*build);
|
||||||
|
|
||||||
let end = std::time::Instant::now();
|
let end = std::time::Instant::now();
|
||||||
|
|
|
@ -1,22 +1,16 @@
|
||||||
|
use std::io;
|
||||||
use std::fs::remove_dir_all;
|
use std::fs::remove_dir_all;
|
||||||
use std::path::Path;
|
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 errors::{BinError, BuildError, InstallError};
|
||||||
use manifest::Manifest;
|
use manifest::Manifest;
|
||||||
use pkgfile::PKGFile;
|
use pkgfile::PKGFile;
|
||||||
|
|
||||||
use crate::CONFIG;
|
|
||||||
use crate::package::identifier::{PackageIdentifier, PackageLocator};
|
|
||||||
use crate::package::Package;
|
|
||||||
use crate::tmpfs::TempDir;
|
use crate::tmpfs::TempDir;
|
||||||
use crate::types::fetch::TryFetch;
|
use crate::types::fetch::TryFetch;
|
||||||
use crate::util::fs::{copy_recursively, visit_dirs};
|
use crate::util::fs::copy_recursively;
|
||||||
use crate::util::prompts::{is_noninteractive, prompt_bool};
|
|
||||||
|
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
|
use std::fmt::{Display, Formatter};
|
||||||
|
|
||||||
use log::trace;
|
use log::trace;
|
||||||
|
|
||||||
use crate::package::Package;
|
use crate::package::Package;
|
||||||
|
|
||||||
pub struct PackageQueue {
|
pub struct PackageQueue {
|
||||||
packages: Vec<Package>
|
packages: Vec<Package>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PackageQueue {
|
impl PackageQueue {
|
||||||
|
@ -17,7 +20,7 @@ impl PackageQueue {
|
||||||
for dependency in dependencies {
|
for dependency in dependencies {
|
||||||
trace!("Checking package: {}", &dependency.identifier);
|
trace!("Checking package: {}", &dependency.identifier);
|
||||||
if self.packages.contains(&dependency) {
|
if self.packages.contains(&dependency) {
|
||||||
continue
|
continue;
|
||||||
}
|
}
|
||||||
trace!("Adding package: {}", &dependency.identifier);
|
trace!("Adding package: {}", &dependency.identifier);
|
||||||
self.packages.push(dependency);
|
self.packages.push(dependency);
|
||||||
|
@ -31,7 +34,18 @@ impl PackageQueue {
|
||||||
self.packages
|
self.packages
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.for_each(|pkg| {
|
.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;
|
use crate::CONFIG;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::path::Path;
|
|
||||||
use std::fs::DirEntry;
|
|
||||||
use std::{fs, io};
|
use std::{fs, io};
|
||||||
|
use std::fs::DirEntry;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
use log::trace;
|
use log::trace;
|
||||||
|
|
||||||
pub fn visit_dirs(dir: &Path, cb: &dyn Fn(&DirEntry)) -> std::io::Result<()> {
|
pub fn visit_dirs(dir: &Path, cb: &dyn Fn(&DirEntry)) -> std::io::Result<()> {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
use log::trace;
|
use log::trace;
|
||||||
|
|
||||||
pub fn is_noninteractive() -> bool {
|
pub fn is_noninteractive() -> bool {
|
||||||
|
|
Loading…
Reference in a new issue