From 6c9527ab79ab66f3f8b8426e006cf58a447c0017 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 28 Feb 2012 21:27:38 -0800 Subject: [PATCH] rustdoc: Add -h flag --- src/rustdoc/config.rs | 23 +++++++++++++++++++---- src/rustdoc/rustdoc.rs | 5 +++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/rustdoc/config.rs b/src/rustdoc/config.rs index da84fef584d..2f5b3976054 100644 --- a/src/rustdoc/config.rs +++ b/src/rustdoc/config.rs @@ -4,6 +4,7 @@ export output_format::{}; export output_style::{}; export config; export parse_config; +export usage; #[doc = "The type of document to output"] enum output_format { @@ -34,20 +35,34 @@ fn opt_output_dir() -> str { "output-dir" } fn opt_output_format() -> str { "output-format" } fn opt_output_style() -> str { "output-style" } fn opt_pandoc_cmd() -> str { "pandoc-cmd" } +fn opt_help() -> str { "h" } fn opts() -> [(getopts::opt, str)] { [ (getopts::optopt(opt_output_dir()), - "put documents here"), + "--output-dir put documents here"), (getopts::optopt(opt_output_format()), - "either 'markdown' or 'html'"), + "--output-format either 'markdown' or 'html'"), (getopts::optopt(opt_output_style()), - "either 'doc-per-crate' or 'doc-per-mod'"), + "--output-style either 'doc-per-crate' or 'doc-per-mod'"), (getopts::optopt(opt_pandoc_cmd()), - "the command for running pandoc") + "--pandoc-cmd the command for running pandoc"), + (getopts::optflag(opt_help()), + "-h print help") ] } +fn usage() { + import std::io::println; + + println("Usage: rustdoc [options] \n"); + println("Options:\n"); + for opt in opts() { + println(#fmt(" %s", tuple::second(opt))); + } + println(""); +} + fn default_config(input_crate: str) -> config { { input_crate: input_crate, diff --git a/src/rustdoc/rustdoc.rs b/src/rustdoc/rustdoc.rs index ff2e49c760b..cc6fba261a7 100755 --- a/src/rustdoc/rustdoc.rs +++ b/src/rustdoc/rustdoc.rs @@ -95,6 +95,11 @@ fn test_run_passes() { fn main(argv: [str]) { + if vec::contains(argv, "-h") { + config::usage(); + ret; + } + if vec::len(argv) != 2u { std::io::println(#fmt("usage: %s ", argv[0])); ret;