Skip to content

Commit

Permalink
Implement -y flag for cargo install
Browse files Browse the repository at this point in the history
  • Loading branch information
tversteeg committed Mar 16, 2021
1 parent 97f6f4e commit 8e042bf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 27 deletions.
16 changes: 0 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ console = "0.14.1"
dialoguer = "0.8.0"
dirs = "3.0.1"
enum_dispatch = "0.3.5"
indoc = "1.0.3"
itertools = "0.10.0"
log = "0.4.14"
ron = "0.6.4"
Expand Down
19 changes: 12 additions & 7 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use dialoguer::MultiSelect;
use log::{debug, error};
use std::{path::Path, process::Command};

pub fn install<P>(config_path: P) -> Result<()>
pub fn install<P>(config_path: P, install_all: bool) -> Result<()>
where
P: AsRef<Path>,
{
Expand Down Expand Up @@ -44,12 +44,17 @@ where
if package_names.is_empty() {
println!("Nothing to install.");
} else {
// Prompt the user for which package to install
let selections = MultiSelect::new()
.with_prompt("Select the packages you want to install (space to add)")
.items(&package_names[..])
.interact()
.context("failed constructing checkboxes")?;
let selections = if install_all {
// Select all packages
(0..package_names.len()).collect()
} else {
// Prompt the user for which package to install
MultiSelect::new()
.with_prompt("Select the packages you want to install (space to add)")
.items(&package_names[..])
.interact()
.context("failed constructing checkboxes")?
};

// Install the selected packages
for selection in selections {
Expand Down
14 changes: 11 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use anyhow::{anyhow, Context, Result};
use bugreport::{
bugreport,
collector::{
CommandLine, CommandOutput, CompileTimeInformation, EnvironmentVariables, OperatingSystem,
CommandOutput, CompileTimeInformation, EnvironmentVariables, OperatingSystem,
SoftwareVersion,
},
format::Markdown,
Expand All @@ -39,7 +39,13 @@ fn public_clap_app<'a>() -> App<'a> {
.global_setting(AppSettings::ColoredHelp)
.subcommand(
App::new("install")
.about("Install the packages that have been mirrored from other machines"),
.about("Install the packages that have been mirrored from other machines")
.arg(
Arg::new("yes")
.short('y')
.long("yes")
.about("Don't prompt the user and try to install everything"),
),
)
.subcommand(App::new("clean").about("Remove package synching"))
.arg(
Expand Down Expand Up @@ -132,7 +138,9 @@ fn safe_main() -> Result<()> {

catch::catch(config_path, line).context("catching a command")
}
Some(("install", _)) => install::install(config_path).context("installing packages"),
Some(("install", sub_m)) => {
install::install(config_path, sub_m.is_present("yes")).context("installing packages")
}
Some(("clean", _)) => clean::clean(config_path).context("cleaning packages"),
Some(("history", sub_m)) => {
let hist_path = PathBuf::from(
Expand Down

0 comments on commit 8e042bf

Please sign in to comment.