@@ -45,6 +45,24 @@ pub mod visit_ast;
45
45
46
46
pub static SCHEMA_VERSION : & ' static str = "0.8.0" ;
47
47
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
+
48
66
local_data_key ! ( pub ctxtkey: @core:: DocContext )
49
67
50
68
enum OutputFormat {
@@ -61,7 +79,8 @@ pub fn opts() -> ~[groups::OptGroup] {
61
79
optmulti ( "L" , "library-path" , "directory to add to crate search path" ,
62
80
"DIR" ) ,
63
81
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",
65
84
"PASSES" ) ,
66
85
optmulti ( "" , "plugins" , "space separated list of plugins to also load" ,
67
86
"PLUGINS" ) ,
@@ -86,6 +105,22 @@ pub fn main_args(args: &[~str]) -> int {
86
105
return 0 ;
87
106
}
88
107
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
+
89
124
let ( format, cratefile) = match matches. free . clone ( ) {
90
125
[ ~"json", crate ] => ( JSON , crate ) ,
91
126
[ ~"html", crate ] => ( HTML , crate ) ,
@@ -118,9 +153,6 @@ pub fn main_args(args: &[~str]) -> int {
118
153
119
154
// Process all of the crate attributes, extracting plugin metadata along
120
155
// 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" ) ;
124
156
match crate . module. get_ref ( ) . doc_list ( ) {
125
157
Some ( nested) => {
126
158
for inner in nested. iter ( ) {
@@ -145,19 +177,20 @@ pub fn main_args(args: &[~str]) -> int {
145
177
None => { }
146
178
}
147
179
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
+ }
150
183
}
151
184
152
185
// Load all plugins/passes into a PluginManager
153
186
let mut pm = plugins:: PluginManager :: new ( Path ( "/tmp/rustdoc_ng/plugins" ) ) ;
154
187
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
+ } ,
161
194
} ;
162
195
pm. add_plugin ( plugin) ;
163
196
}
0 commit comments