@@ -45,6 +45,24 @@ pub mod visit_ast;
4545
4646pub static SCHEMA_VERSION : & ' static str = "0.8.0" ;
4747
48+ type Pass = ( & ' static str , // name
49+ extern fn ( clean:: Crate ) -> plugins:: PluginResult , // fn
50+ & ' static str ) ; // description
51+
52+ static PASSES : & ' static [ Pass ] = & [
53+ ( "strip-hidden" , passes:: strip_hidden,
54+ "strips all doc(hidden) items from the output" ) ,
55+ ( "unindent-comments" , passes:: unindent_comments,
56+ "removes excess indentation on comments in order for markdown to like it" ) ,
57+ ( "collapse-docs" , passes:: collapse_docs,
58+ "concatenates all document attributes into one document attribute" ) ,
59+ ] ;
60+
61+ static DEFAULT_PASSES : & ' static [ & ' static str ] = & [
62+ "unindent-comments" ,
63+ "collapse-docs" ,
64+ ] ;
65+
4866local_data_key ! ( pub ctxtkey: @core:: DocContext )
4967
5068enum OutputFormat {
@@ -61,7 +79,8 @@ pub fn opts() -> ~[groups::OptGroup] {
6179 optmulti ( "L" , "library-path" , "directory to add to crate search path" ,
6280 "DIR" ) ,
6381 optmulti ( "" , "plugin-path" , "directory to load plugins from" , "DIR" ) ,
64- optmulti ( "" , "passes" , "space separated list of passes to also run" ,
82+ optmulti ( "" , "passes" , "space separated list of passes to also run, a \
83+ value of `list` will print available passes",
6584 "PASSES" ) ,
6685 optmulti ( "" , "plugins" , "space separated list of plugins to also load" ,
6786 "PLUGINS" ) ,
@@ -86,6 +105,22 @@ pub fn main_args(args: &[~str]) -> int {
86105 return 0 ;
87106 }
88107
108+ let mut default_passes = !matches. opt_present ( "nodefaults" ) ;
109+ let mut passes = matches. opt_strs ( "passes" ) ;
110+ let mut plugins = matches. opt_strs ( "plugins" ) ;
111+
112+ if passes == ~[ ~"list"] {
113+ println ( "Available passes for running rustdoc:" ) ;
114+ for & ( name, _, description) in PASSES . iter ( ) {
115+ println ! ( "{:>20s} - {}" , name, description) ;
116+ }
117+ println ( "\n Default passes for rustdoc:" ) ;
118+ for & name in DEFAULT_PASSES . iter ( ) {
119+ println ! ( "{:>20s}" , name) ;
120+ }
121+ return ;
122+ }
123+
89124 let ( format, cratefile) = match matches. free . clone ( ) {
90125 [ ~"json", crate ] => ( JSON , crate ) ,
91126 [ ~"html", crate ] => ( HTML , crate ) ,
@@ -118,9 +153,6 @@ pub fn main_args(args: &[~str]) -> int {
118153
119154 // Process all of the crate attributes, extracting plugin metadata along
120155 // with the passes which we are supposed to run.
121- let mut default_passes = !matches. opt_present ( "nodefaults" ) ;
122- let mut passes = matches. opt_strs ( "passes" ) ;
123- let mut plugins = matches. opt_strs ( "plugins" ) ;
124156 match crate . module. get_ref ( ) . doc_list ( ) {
125157 Some ( nested) => {
126158 for inner in nested. iter ( ) {
@@ -145,19 +177,20 @@ pub fn main_args(args: &[~str]) -> int {
145177 None => { }
146178 }
147179 if default_passes {
148- passes. unshift ( ~"collapse-docs") ;
149- passes. unshift ( ~"unindent-comments") ;
180+ for name in DEFAULT_PASSES . rev_iter ( ) {
181+ passes. unshift ( name. to_owned ( ) ) ;
182+ }
150183 }
151184
152185 // Load all plugins/passes into a PluginManager
153186 let mut pm = plugins:: PluginManager :: new ( Path ( "/tmp/rustdoc_ng/plugins" ) ) ;
154187 for pass in passes. iter ( ) {
155- let plugin = match pass . as_slice ( ) {
156- "strip-hidden" => passes :: strip_hidden ,
157- "unindent-comments" => passes :: unindent_comments ,
158- "collapse-docs" => passes :: collapse_docs ,
159- "collapse-privacy" => passes :: collapse_privacy ,
160- s => { error ! ( "unknown pass %s, skipping" , s ) ; loop } ,
188+ let plugin = match PASSES . iter ( ) . position ( | & ( p , _ , _ ) | p == * pass ) {
189+ Some ( i ) => PASSES [ i ] . n1 ( ) ,
190+ None => {
191+ error2 ! ( "unknown pass {}, skipping" , * pass ) ;
192+ loop
193+ } ,
161194 } ;
162195 pm. add_plugin ( plugin) ;
163196 }
0 commit comments