@@ -3,7 +3,8 @@ use std::path::Path;
33
44use crate :: { canonical_key, LocalizedText , Schema } ;
55
6- pub const EXAMPLE_CONFIG_FILE : & str = "AppleChu.example.toml" ;
6+ pub const EXAMPLE_CONFIG_FILE : & str = "example.toml" ;
7+ pub const FULL_CONFIG_FILE : & str = "full.toml" ;
78
89pub const DEFAULT_CONFIG_HEADER : & str = r#"## 这是 AppleChu 的 TOML 配置文件
910##
@@ -17,6 +18,14 @@ ConfigVersion = 1
1718
1819impl Schema {
1920 pub fn default_config_toml ( & self ) -> String {
21+ self . config_toml ( false )
22+ }
23+
24+ pub fn full_config_toml ( & self ) -> String {
25+ self . config_toml ( true )
26+ }
27+
28+ fn config_toml ( & self , include_advanced : bool ) -> String {
2029 let mut output = String :: from ( DEFAULT_CONFIG_HEADER ) ;
2130 for section in & self . sections {
2231 output. push ( '\n' ) ;
@@ -28,7 +37,7 @@ impl Schema {
2837 append_comment ( & mut output, description. zh_or_en ( ) ) ;
2938 }
3039 for entry in & section. entries {
31- if entry. advanced {
40+ if entry. advanced && !include_advanced {
3241 continue ;
3342 }
3443 if entry. emit_comment {
@@ -55,10 +64,9 @@ impl Schema {
5564 }
5665
5766 pub fn write_example_config ( & self , output : impl AsRef < Path > ) -> std:: io:: Result < ( ) > {
58- fs:: write (
59- output. as_ref ( ) . join ( EXAMPLE_CONFIG_FILE ) ,
60- self . default_config_toml ( ) ,
61- )
67+ let output = output. as_ref ( ) ;
68+ fs:: write ( output. join ( EXAMPLE_CONFIG_FILE ) , self . default_config_toml ( ) ) ?;
69+ fs:: write ( output. join ( FULL_CONFIG_FILE ) , self . full_config_toml ( ) )
6270 }
6371}
6472
@@ -80,7 +88,7 @@ mod tests {
8088 use std:: fs;
8189 use std:: time:: { SystemTime , UNIX_EPOCH } ;
8290
83- use crate :: { generate_from_rust_dir, EXAMPLE_CONFIG_FILE } ;
91+ use crate :: { generate_from_rust_dir, EXAMPLE_CONFIG_FILE , FULL_CONFIG_FILE } ;
8492
8593 #[ test]
8694 fn example_config_is_written_to_build_output ( ) {
@@ -106,7 +114,13 @@ mod tests {
106114 // Then: 固定文件名中的内容与内嵌默认配置完全一致。
107115 let example = fs:: read_to_string ( directory. join ( EXAMPLE_CONFIG_FILE ) )
108116 . expect ( "example config must be readable" ) ;
117+ let full = fs:: read_to_string ( directory. join ( FULL_CONFIG_FILE ) )
118+ . expect ( "full config must be readable" ) ;
109119 fs:: remove_dir_all ( & directory) . expect ( "output directory must be removed" ) ;
110120 assert_eq ! ( example, schema. default_config_toml( ) ) ;
121+ assert ! ( full. parse:: <toml:: Table >( ) . is_ok( ) ) ;
122+ assert ! ( !example. contains( "EnableConsole" ) ) ;
123+ assert ! ( full. contains( "#EnableConsole = true" ) ) ;
124+ assert ! ( full. contains( "#AppendConfigArgs = true" ) ) ;
111125 }
112126}
0 commit comments