@@ -13,6 +13,7 @@ pub use crate::errors::*;
13
13
pub use crate :: notifications:: * ;
14
14
use crate :: toolchain:: * ;
15
15
pub ( crate ) use crate :: utils:: toml_utils;
16
+ use anyhow:: { anyhow, Result } ;
16
17
17
18
#[ macro_use]
18
19
extern crate rs_tracing;
@@ -36,6 +37,28 @@ pub static TOOLS: &[&str] = &[
36
37
// installation.
37
38
pub static DUP_TOOLS : & [ & str ] = & [ "rustfmt" , "cargo-fmt" ] ;
38
39
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
+
39
62
fn component_for_bin ( binary : & str ) -> Option < & ' static str > {
40
63
use std:: env:: consts:: EXE_SUFFIX ;
41
64
@@ -74,3 +97,25 @@ mod settings;
74
97
pub mod test;
75
98
mod toolchain;
76
99
pub 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