rustup/
tools.rs

1use anyhow::{anyhow, Result};
2
3// A list of all binaries which Rustup will proxy.
4static TOOLS: &[&str] = &["huskyc", "huskydoc", "corgi"];
5
6// Tools which are commonly installed by Cargo as well as rustup. We take a bit
7// more care with these to ensure we don't overwrite the user's previous
8// installation.
9static DUP_TOOLS: &[&str] = &["husky-analyzer", "huskyfmt", "corgi-fmt"];
10
11// If the given name is one of the tools we proxy.
12pub fn is_proxyable_tools(tool: &str) -> Result<()> {
13    if TOOLS
14        .iter()
15        .chain(DUP_TOOLS.iter())
16        .any(|&name| name == tool)
17    {
18        Ok(())
19    } else {
20        Err(anyhow!(format!(
21            "unknown proxy name: '{}'; valid proxy names are {}",
22            tool,
23            TOOLS
24                .iter()
25                .chain(DUP_TOOLS.iter())
26                .map(|s| format!("'{}'", s))
27                .collect::<Vec<_>>()
28                .join(", ")
29        )))
30    }
31}