Put back output-format option for show-coverage

This commit is contained in:
Guillaume Gomez
2019-11-16 16:12:09 +01:00
parent 6af4fd385e
commit 8858d71d28
4 changed files with 56 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
use std::collections::BTreeMap;
use std::ffi::OsStr;
use std::convert::TryFrom;
use std::fmt;
use std::path::PathBuf;
@@ -24,6 +25,33 @@ use crate::opts;
use crate::passes::{self, Condition, DefaultPassOption};
use crate::theme;
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum OutputFormat {
Json,
HTML,
}
impl OutputFormat {
pub fn is_json(&self) -> bool {
match *self {
OutputFormat::Json => true,
_ => false,
}
}
}
impl TryFrom<&str> for OutputFormat {
type Error = String;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"json" => Ok(OutputFormat::Json),
"html" => Ok(OutputFormat::HTML),
_ => Err(format!("unknown output format `{}`", value)),
}
}
}
/// Configuration options for rustdoc.
#[derive(Clone)]
pub struct Options {
@@ -115,6 +143,8 @@ pub struct Options {
pub crate_version: Option<String>,
/// Collected options specific to outputting final pages.
pub render_options: RenderOptions,
/// Output format rendering (used only for "show-coverage" option for the moment)
pub output_format: Option<OutputFormat>,
}
impl fmt::Debug for Options {
@@ -425,14 +455,6 @@ impl Options {
}
}
match matches.opt_str("w").as_ref().map(|s| &**s) {
Some("html") | None => {}
Some(s) => {
diag.struct_err(&format!("unknown output format: {}", s)).emit();
return Err(1);
}
}
let index_page = matches.opt_str("index-page").map(|s| PathBuf::from(&s));
if let Some(ref index_page) = index_page {
if !index_page.is_file() {
@@ -469,6 +491,23 @@ impl Options {
}
};
let output_format = match matches.opt_str("output-format") {
Some(s) => match OutputFormat::try_from(s.as_str()) {
Ok(o) => {
if o.is_json() && !show_coverage {
diag.struct_err("json output format isn't supported for doc generation")
.emit();
return Err(1);
}
Some(o)
}
Err(e) => {
diag.struct_err(&e).emit();
return Err(1);
}
}
None => None,
};
let crate_name = matches.opt_str("crate-name");
let proc_macro_crate = crate_types.contains(&CrateType::ProcMacro);
let playground_url = matches.opt_str("playground-url");
@@ -553,6 +592,7 @@ impl Options {
generate_search_filter,
generate_redirect_pages,
},
output_format,
})
}
@@ -568,6 +608,9 @@ fn check_deprecated_options(matches: &getopts::Matches, diag: &rustc_errors::Han
for flag in deprecated_flags.iter() {
if matches.opt_present(flag) {
if *flag == "output-format" && matches.opt_present("show-coverage") {
continue;
}
let mut err =
diag.struct_warn(&format!("the '{}' flag is considered deprecated", flag));
err.warn(