Skip to content

Commit

Permalink
Implement output path flag
Browse files Browse the repository at this point in the history
  • Loading branch information
hjr3 authored and steveklabnik committed Dec 31, 2017
1 parent 1af1a22 commit 8637f38
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
14 changes: 13 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ pub struct Config {
/// Path to the `Cargo.toml` file for the crate being analyzed
manifest_path: PathBuf,

/// Path to place rustdoc output
output_path: Option<PathBuf>,

/// Contains the Cargo analysis output for the crate being documented
host: analysis::AnalysisHost,
}
Expand All @@ -85,6 +88,7 @@ impl Config {
Ok(Config {
ui: Ui::new(verbosity),
manifest_path,
output_path: None,
host,
})
}
Expand All @@ -97,7 +101,15 @@ impl Config {

/// Returns the directory where output files should be placed
pub fn output_path(&self) -> PathBuf {
self.root_path().join("target").join("doc")
match self.output_path {
Some(ref path) => path.clone(),
None => self.root_path().join("target").join("doc"),
}
}

/// Set the directory where output files should be placed
pub fn set_output_path(&mut self, output_path: PathBuf) {
self.output_path = Some(output_path);
}

/// Returns the path to the generated documentation.
Expand Down
9 changes: 6 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,20 @@ fn run() -> Result<()> {
} else {
Verbosity::Normal
};
let config = Config::new(verbosity, manifest_path)?;
let mut config = Config::new(verbosity, manifest_path)?;

match matches.subcommand() {
("build", Some(matches)) => {

// FIXME: Workaround for clap #1056. Use `.default_value()` once the issue is fixed.
let artifacts: Vec<&str> = matches
.values_of("artifacts")
.map(|values| values.collect())
.unwrap_or_else(|| DEFAULT_ARTIFACTS.iter().map(|&artifact| artifact).collect());

if let Some(output_path) = matches.value_of("output") {
config.set_output_path(PathBuf::from(output_path));
}

build(&config, &artifacts)?;
if matches.is_present("open") {
config.open_docs()?;
Expand Down Expand Up @@ -277,7 +281,6 @@ fn check_unimplemented_flags(matches: &ArgMatches) {
];

let unimplemented_build_flags = [
"output",
"crate-name",
"library-path",
"cfg",
Expand Down

0 comments on commit 8637f38

Please sign in to comment.