@@ -16,8 +16,6 @@ use regex::Regex;
1616use serde:: { self , de, Deserialize , Deserializer , Serialize , Serializer } ;
1717use url:: Url ;
1818
19- use crate :: lock:: DEFAULT_TEMPLATES ;
20-
2119/// The Gist domain host.
2220const GIST_HOST : & str = "gist.github.com" ;
2321
@@ -190,7 +188,7 @@ pub struct RawConfig {
190188#[ derive( Debug ) ]
191189pub struct Config {
192190 /// What type of shell is being used.
193- pub shell : Option < Shell > ,
191+ pub shell : Shell ,
194192 /// Which files to match and use in a plugin's directory.
195193 pub matches : Option < Vec < String > > ,
196194 /// The default list of template names to apply to each matched file.
@@ -576,12 +574,13 @@ where
576574
577575/// Check whether the specifed templates actually exist.
578576fn validate_template_names (
577+ shell : & Shell ,
579578 apply : & Option < Vec < String > > ,
580579 templates : & IndexMap < String , Template > ,
581580) -> Result < ( ) > {
582581 if let Some ( apply) = apply {
583582 for name in apply {
584- if !DEFAULT_TEMPLATES . contains_key ( name) && !templates. contains_key ( name) {
583+ if !shell . default_templates ( ) . contains_key ( name) && !templates. contains_key ( name) {
585584 bail ! ( "unknown template `{}`" , name) ;
586585 }
587586 }
@@ -628,6 +627,7 @@ impl RawPlugin {
628627 pub fn normalize (
629628 self ,
630629 name : String ,
630+ shell : & Shell ,
631631 templates : & IndexMap < String , Template > ,
632632 warnings : & mut Vec < Error > ,
633633 ) -> Result < Plugin > {
@@ -733,7 +733,7 @@ impl RawPlugin {
733733 bail ! ( "the `proto` field is not supported by this plugin type" ) ;
734734 }
735735
736- validate_template_names ( & apply, templates) ?;
736+ validate_template_names ( shell , & apply, templates) ?;
737737
738738 Ok ( Plugin :: External ( ExternalPlugin {
739739 name,
@@ -815,15 +815,17 @@ impl RawConfig {
815815 }
816816 }
817817
818- validate_template_names ( & apply, & templates) ?;
818+ let shell = shell. unwrap_or_default ( ) ;
819+
820+ validate_template_names ( & shell, & apply, & templates) ?;
819821
820822 // Normalize the plugins.
821823 let mut normalized_plugins = Vec :: with_capacity ( plugins. len ( ) ) ;
822824
823825 for ( name, plugin) in plugins {
824826 normalized_plugins. push (
825827 plugin
826- . normalize ( name. clone ( ) , & templates, & mut warnings)
828+ . normalize ( name. clone ( ) , & shell , & templates, & mut warnings)
827829 . with_context ( s ! ( "failed to normalize plugin `{}`" , name) ) ?,
828830 ) ;
829831 }
@@ -1099,7 +1101,12 @@ mod tests {
10991101 let text = format ! ( "{} = '{}'\n {} = '{}'" , a, example_a, b, example_b) ;
11001102 let e = toml:: from_str :: < RawPlugin > ( & text)
11011103 . unwrap ( )
1102- . normalize ( "test" . to_string ( ) , & IndexMap :: new ( ) , & mut Vec :: new ( ) )
1104+ . normalize (
1105+ "test" . to_string ( ) ,
1106+ & Shell :: default ( ) ,
1107+ & IndexMap :: new ( ) ,
1108+ & mut Vec :: new ( ) ,
1109+ )
11031110 . unwrap_err ( ) ;
11041111 assert_eq ! ( e. to_string( ) , "plugin `test` has multiple source fields" )
11051112 }
@@ -1126,7 +1133,7 @@ mod tests {
11261133 } ;
11271134 assert_eq ! (
11281135 raw_plugin
1129- . normalize( name, & IndexMap :: new( ) , & mut Vec :: new( ) )
1136+ . normalize( name, & Shell :: default ( ) , & IndexMap :: new( ) , & mut Vec :: new( ) )
11301137 . unwrap( ) ,
11311138 expected
11321139 ) ;
@@ -1156,7 +1163,7 @@ mod tests {
11561163 } ;
11571164 assert_eq ! (
11581165 raw_plugin
1159- . normalize( name, & IndexMap :: new( ) , & mut Vec :: new( ) )
1166+ . normalize( name, & Shell :: default ( ) , & IndexMap :: new( ) , & mut Vec :: new( ) )
11601167 . unwrap( ) ,
11611168 expected
11621169 ) ;
@@ -1182,7 +1189,7 @@ mod tests {
11821189 } ;
11831190 assert_eq ! (
11841191 raw_plugin
1185- . normalize( name, & IndexMap :: new( ) , & mut Vec :: new( ) )
1192+ . normalize( name, & Shell :: default ( ) , & IndexMap :: new( ) , & mut Vec :: new( ) )
11861193 . unwrap( ) ,
11871194 expected
11881195 ) ;
@@ -1213,7 +1220,7 @@ mod tests {
12131220 } ;
12141221 assert_eq ! (
12151222 raw_plugin
1216- . normalize( name, & IndexMap :: new( ) , & mut Vec :: new( ) )
1223+ . normalize( name, & Shell :: default ( ) , & IndexMap :: new( ) , & mut Vec :: new( ) )
12171224 . unwrap( ) ,
12181225 expected
12191226 ) ;
@@ -1242,7 +1249,7 @@ mod tests {
12421249 } ;
12431250 assert_eq ! (
12441251 raw_plugin
1245- . normalize( name, & IndexMap :: new( ) , & mut Vec :: new( ) )
1252+ . normalize( name, & Shell :: default ( ) , & IndexMap :: new( ) , & mut Vec :: new( ) )
12461253 . unwrap( ) ,
12471254 expected
12481255 ) ;
@@ -1270,7 +1277,7 @@ mod tests {
12701277 } ;
12711278 assert_eq ! (
12721279 raw_plugin
1273- . normalize( name, & IndexMap :: new( ) , & mut Vec :: new( ) )
1280+ . normalize( name, & Shell :: default ( ) , & IndexMap :: new( ) , & mut Vec :: new( ) )
12741281 . unwrap( ) ,
12751282 expected
12761283 ) ;
@@ -1299,7 +1306,7 @@ mod tests {
12991306 } ;
13001307 assert_eq ! (
13011308 raw_plugin
1302- . normalize( name, & IndexMap :: new( ) , & mut Vec :: new( ) )
1309+ . normalize( name, & Shell :: default ( ) , & IndexMap :: new( ) , & mut Vec :: new( ) )
13031310 . unwrap( ) ,
13041311 expected
13051312 ) ;
@@ -1324,7 +1331,7 @@ mod tests {
13241331 } ;
13251332 assert_eq ! (
13261333 raw_plugin
1327- . normalize( name, & IndexMap :: new( ) , & mut Vec :: new( ) )
1334+ . normalize( name, & Shell :: default ( ) , & IndexMap :: new( ) , & mut Vec :: new( ) )
13281335 . unwrap( ) ,
13291336 expected
13301337 ) ;
@@ -1343,7 +1350,12 @@ mod tests {
13431350 ..Default :: default ( )
13441351 } ;
13451352 let error = raw_plugin
1346- . normalize ( "test" . to_string ( ) , & IndexMap :: new ( ) , & mut Vec :: new ( ) )
1353+ . normalize (
1354+ "test" . to_string ( ) ,
1355+ & Shell :: default ( ) ,
1356+ & IndexMap :: new ( ) ,
1357+ & mut Vec :: new ( ) ,
1358+ )
13471359 . unwrap_err ( ) ;
13481360 assert_eq ! (
13491361 error. to_string( ) ,
@@ -1364,7 +1376,12 @@ mod tests {
13641376 ..Default :: default ( )
13651377 } ;
13661378 let error = raw_plugin
1367- . normalize ( "test" . to_string ( ) , & IndexMap :: new ( ) , & mut Vec :: new ( ) )
1379+ . normalize (
1380+ "test" . to_string ( ) ,
1381+ & Shell :: default ( ) ,
1382+ & IndexMap :: new ( ) ,
1383+ & mut Vec :: new ( ) ,
1384+ )
13681385 . unwrap_err ( ) ;
13691386 assert_eq ! (
13701387 error. to_string( ) ,
@@ -1390,7 +1407,7 @@ mod tests {
13901407 } ;
13911408 assert_eq ! (
13921409 raw_plugin
1393- . normalize( name, & IndexMap :: new( ) , & mut Vec :: new( ) )
1410+ . normalize( name, & Shell :: default ( ) , & IndexMap :: new( ) , & mut Vec :: new( ) )
13941411 . unwrap( ) ,
13951412 expected
13961413 ) ;
@@ -1409,7 +1426,7 @@ mod tests {
14091426 } ;
14101427 assert_eq ! (
14111428 raw_plugin
1412- . normalize( name, & IndexMap :: new( ) , & mut Vec :: new( ) )
1429+ . normalize( name, & Shell :: default ( ) , & IndexMap :: new( ) , & mut Vec :: new( ) )
14131430 . unwrap( ) ,
14141431 expected
14151432 ) ;
@@ -1423,7 +1440,12 @@ mod tests {
14231440 ..Default :: default ( )
14241441 } ;
14251442 let error = raw_plugin
1426- . normalize ( "test" . to_string ( ) , & IndexMap :: new ( ) , & mut Vec :: new ( ) )
1443+ . normalize (
1444+ "test" . to_string ( ) ,
1445+ & Shell :: default ( ) ,
1446+ & IndexMap :: new ( ) ,
1447+ & mut Vec :: new ( ) ,
1448+ )
14271449 . unwrap_err ( ) ;
14281450 assert_eq ! (
14291451 error. to_string( ) ,
@@ -1442,7 +1464,12 @@ mod tests {
14421464 ..Default :: default ( )
14431465 } ;
14441466 let error = raw_plugin
1445- . normalize ( "test" . to_string ( ) , & IndexMap :: new ( ) , & mut Vec :: new ( ) )
1467+ . normalize (
1468+ "test" . to_string ( ) ,
1469+ & Shell :: default ( ) ,
1470+ & IndexMap :: new ( ) ,
1471+ & mut Vec :: new ( ) ,
1472+ )
14461473 . unwrap_err ( ) ;
14471474 assert_eq ! ( error. to_string( ) , "unknown template `test`" ) ;
14481475 }
0 commit comments