diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-09-23 16:25:58 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-09-25 14:27:42 -0700 |
| commit | eaaf2bd41fa96fdf622f301182694c1a3f47f8cb (patch) | |
| tree | 29869f702dff9aafc38e252ede8c62e9fd4f4e4d /src/librustdoc/rustdoc.rs | |
| parent | bcc7daa6bcf9728eca36512975f9251a946618d7 (diff) | |
| download | rust-eaaf2bd41fa96fdf622f301182694c1a3f47f8cb.tar.gz rust-eaaf2bd41fa96fdf622f301182694c1a3f47f8cb.zip | |
rustdoc: Add the ability to list all passes
In doing so, also remove the collapse-privacy pass because it's a little over-zealous and may not be right 100% of the time (not used right now as well)
Diffstat (limited to 'src/librustdoc/rustdoc.rs')
| -rw-r--r-- | src/librustdoc/rustdoc.rs | 57 |
1 files changed, 45 insertions, 12 deletions
diff --git a/src/librustdoc/rustdoc.rs b/src/librustdoc/rustdoc.rs index c3d8cdf028e..69092618da2 100644 --- a/src/librustdoc/rustdoc.rs +++ b/src/librustdoc/rustdoc.rs @@ -45,6 +45,24 @@ pub mod visit_ast; pub static SCHEMA_VERSION: &'static str = "0.8.0"; +type Pass = (&'static str, // name + extern fn(clean::Crate) -> plugins::PluginResult, // fn + &'static str); // description + +static PASSES: &'static [Pass] = &[ + ("strip-hidden", passes::strip_hidden, + "strips all doc(hidden) items from the output"), + ("unindent-comments", passes::unindent_comments, + "removes excess indentation on comments in order for markdown to like it"), + ("collapse-docs", passes::collapse_docs, + "concatenates all document attributes into one document attribute"), +]; + +static DEFAULT_PASSES: &'static [&'static str] = &[ + "unindent-comments", + "collapse-docs", +]; + local_data_key!(pub ctxtkey: @core::DocContext) enum OutputFormat { @@ -61,7 +79,8 @@ pub fn opts() -> ~[groups::OptGroup] { optmulti("L", "library-path", "directory to add to crate search path", "DIR"), optmulti("", "plugin-path", "directory to load plugins from", "DIR"), - optmulti("", "passes", "space separated list of passes to also run", + optmulti("", "passes", "space separated list of passes to also run, a \ + value of `list` will print available passes", "PASSES"), optmulti("", "plugins", "space separated list of plugins to also load", "PLUGINS"), @@ -86,6 +105,22 @@ pub fn main_args(args: &[~str]) -> int { return 0; } + let mut default_passes = !matches.opt_present("nodefaults"); + let mut passes = matches.opt_strs("passes"); + let mut plugins = matches.opt_strs("plugins"); + + if passes == ~[~"list"] { + println("Available passes for running rustdoc:"); + for &(name, _, description) in PASSES.iter() { + println!("{:>20s} - {}", name, description); + } + println("\nDefault passes for rustdoc:"); + for &name in DEFAULT_PASSES.iter() { + println!("{:>20s}", name); + } + return; + } + let (format, cratefile) = match matches.free.clone() { [~"json", crate] => (JSON, crate), [~"html", crate] => (HTML, crate), @@ -118,9 +153,6 @@ pub fn main_args(args: &[~str]) -> int { // Process all of the crate attributes, extracting plugin metadata along // with the passes which we are supposed to run. - let mut default_passes = !matches.opt_present("nodefaults"); - let mut passes = matches.opt_strs("passes"); - let mut plugins = matches.opt_strs("plugins"); match crate.module.get_ref().doc_list() { Some(nested) => { for inner in nested.iter() { @@ -145,19 +177,20 @@ pub fn main_args(args: &[~str]) -> int { None => {} } if default_passes { - passes.unshift(~"collapse-docs"); - passes.unshift(~"unindent-comments"); + for name in DEFAULT_PASSES.rev_iter() { + passes.unshift(name.to_owned()); + } } // Load all plugins/passes into a PluginManager let mut pm = plugins::PluginManager::new(Path("/tmp/rustdoc_ng/plugins")); for pass in passes.iter() { - let plugin = match pass.as_slice() { - "strip-hidden" => passes::strip_hidden, - "unindent-comments" => passes::unindent_comments, - "collapse-docs" => passes::collapse_docs, - "collapse-privacy" => passes::collapse_privacy, - s => { error!("unknown pass %s, skipping", s); loop }, + let plugin = match PASSES.iter().position(|&(p, _, _)| p == *pass) { + Some(i) => PASSES[i].n1(), + None => { + error2!("unknown pass {}, skipping", *pass); + loop + }, }; pm.add_plugin(plugin); } |
