Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ download = {path = "download"}
error-chain = "0.12"
flate2 = "1"
git-testament = "0.1.4"
glob = "0.3"
home = {git = "https://github.com/rbtcollins/home", rev = "a243ee2fbee6022c57d56f5aa79aefe194eabe53"}
lazy_static = "1"
libc = "0.2"
Expand Down
1 change: 1 addition & 0 deletions src/cli/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ error_chain! {
Temp(temp::Error);
Io(io::Error);
Term(term::Error);
Glob(glob::PatternError);
}

errors {
Expand Down
24 changes: 21 additions & 3 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::process::Command;
use std::str::FromStr;

use clap::{App, AppSettings, Arg, ArgGroup, ArgMatches, Shell, SubCommand};
use glob::Pattern;

use super::common;
use super::errors::*;
Expand Down Expand Up @@ -404,6 +405,13 @@ pub fn cli() -> App<'static, 'static> {
SubCommand::with_name("uninstall")
.about("Uninstall a toolchain")
.alias("remove")
.arg(
Arg::with_name("pattern")
.help("Treat arguments as glob patterns")
.short("p")
.long("pattern")
.takes_value(false),
)
.arg(
Arg::with_name("toolchain")
.help(TOOLCHAIN_ARG_HELP)
Expand Down Expand Up @@ -1312,10 +1320,20 @@ fn toolchain_link(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
}

fn toolchain_remove(cfg: &mut Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
for toolchain in m.values_of("toolchain").unwrap() {
let toolchain = cfg.get_toolchain(toolchain, false)?;
toolchain.remove()?;
if m.is_present("pattern") {
for pattern_str in m.values_of("toolchain").unwrap() {
let pattern = Pattern::new(pattern_str)?;
for toolchain in cfg.get_toolchains_from_glob(pattern)? {
toolchain.remove()?;
}
}
} else {
for toolchain in m.values_of("toolchain").unwrap() {
let toolchain = cfg.get_toolchain(toolchain, false)?;
toolchain.remove()?;
}
}

Ok(utils::ExitCode(0))
}

Expand Down
35 changes: 25 additions & 10 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::borrow::Cow;
use std::fmt::{self, Display};
use std::io;
use std::iter;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::str::FromStr;
use std::sync::Arc;

use glob::Pattern;
use pgp::{Deserializable, SignedPublicKey};
use serde::Deserialize;

Expand Down Expand Up @@ -362,6 +364,16 @@ impl Cfg {
Toolchain::from(self, name)
}

pub fn get_toolchains_from_glob(
&self,
pattern: Pattern,
) -> Result<impl Iterator<Item = Toolchain<'_>>> {
Ok(self
.list_toolchains_iter()?
.filter(move |toolchain| pattern.matches(toolchain))
.map(move |toolchain| Toolchain::from(self, &toolchain).unwrap()))
}

pub fn verify_toolchain(&self, name: &str) -> Result<Toolchain<'_>> {
let toolchain = self.get_toolchain(name, false)?;
toolchain.verify()?;
Expand Down Expand Up @@ -694,18 +706,21 @@ impl Cfg {
}

pub fn list_toolchains(&self) -> Result<Vec<String>> {
if utils::is_directory(&self.toolchains_dir) {
let mut toolchains: Vec<_> = utils::read_dir("toolchains", &self.toolchains_dir)?
.filter_map(io::Result::ok)
.filter(|e| e.file_type().map(|f| !f.is_file()).unwrap_or(false))
.filter_map(|e| e.file_name().into_string().ok())
.collect();

utils::toolchain_sort(&mut toolchains);
let mut toolchains: Vec<_> = self.list_toolchains_iter()?.collect();
utils::toolchain_sort(&mut toolchains);
Ok(toolchains)
}

Ok(toolchains)
fn list_toolchains_iter(&self) -> Result<Box<dyn Iterator<Item = String>>> {
if utils::is_directory(&self.toolchains_dir) {
Ok(Box::new(
utils::read_dir("toolchains", &self.toolchains_dir)?
.filter_map(io::Result::ok)
.filter(|e| e.file_type().map(|f| !f.is_file()).unwrap_or(false))
.filter_map(|e| e.file_name().into_string().ok()),
))
} else {
Ok(Vec::new())
Ok(Box::new(iter::empty()))
}
}

Expand Down