@@ -13,6 +13,7 @@ pub use crate::errors::*;
1313pub use crate :: notifications:: * ;
1414use crate :: toolchain:: * ;
1515pub ( crate ) use crate :: utils:: toml_utils;
16+ use anyhow:: { anyhow, Result } ;
1617
1718#[ macro_use]
1819extern crate rs_tracing;
@@ -36,6 +37,28 @@ pub static TOOLS: &[&str] = &[
3637// installation.
3738pub static DUP_TOOLS : & [ & str ] = & [ "rustfmt" , "cargo-fmt" ] ;
3839
40+ // If the given name is one of the tools we proxy.
41+ pub fn is_proxyable_tools ( tool : & str ) -> Result < ( ) > {
42+ if TOOLS
43+ . iter ( )
44+ . chain ( DUP_TOOLS . iter ( ) )
45+ . any ( |& name| name == tool)
46+ {
47+ Ok ( ( ) )
48+ } else {
49+ Err ( anyhow ! ( format!(
50+ "unknown proxy name: '{}'; valid proxy names are {}" ,
51+ tool,
52+ TOOLS
53+ . iter( )
54+ . chain( DUP_TOOLS . iter( ) )
55+ . map( |s| format!( "'{}'" , s) )
56+ . collect:: <Vec <_>>( )
57+ . join( ", " )
58+ ) ) )
59+ }
60+ }
61+
3962fn component_for_bin ( binary : & str ) -> Option < & ' static str > {
4063 use std:: env:: consts:: EXE_SUFFIX ;
4164
@@ -74,3 +97,25 @@ mod settings;
7497pub mod test;
7598mod toolchain;
7699pub mod utils;
100+
101+ #[ cfg( test) ]
102+ mod tests {
103+ use crate :: { is_proxyable_tools, DUP_TOOLS , TOOLS } ;
104+
105+ #[ test]
106+ fn test_is_proxyable_tools ( ) {
107+ for tool in TOOLS {
108+ assert ! ( is_proxyable_tools( tool) . is_ok( ) ) ;
109+ }
110+ for tool in DUP_TOOLS {
111+ assert ! ( is_proxyable_tools( tool) . is_ok( ) ) ;
112+ }
113+ let message = & "unknown proxy name: 'unknown-tool'; valid proxy names are 'rustc', \
114+ 'rustdoc', 'cargo', 'rust-lldb', 'rust-gdb', 'rust-gdbgui', 'rls', 'cargo-clippy', \
115+ 'clippy-driver', 'cargo-miri', 'rustfmt', 'cargo-fmt'";
116+ assert ! ( is_proxyable_tools( "unknown-tool" )
117+ . unwrap_err( )
118+ . to_string( )
119+ . eq( message) ) ;
120+ }
121+ }
0 commit comments