11//! Implementation of the `docset` subcommand.
22
3- use crate :: { error:: * , io:: * , DocsetParams } ;
3+ use crate :: { error:: * , io:: * , DocsetParams , WorkspaceMetadata } ;
44
55use cargo_metadata:: Metadata ;
66use derive_more:: Constructor ;
@@ -383,7 +383,7 @@ fn get_docset_platform_family(cfg: &DocsetParams, metadata: &Metadata) -> Option
383383 }
384384}
385385
386- pub fn generate_docset ( cfg : DocsetParams ) -> Result < ( ) > {
386+ pub fn generate_docset ( mut cfg : DocsetParams ) -> Result < ( ) > {
387387 // Step 1: generate rustdoc
388388 // Figure out for which crate to build the doc and invoke cargo doc.
389389 // If no crate is specified, run cargo doc for the current crate/workspace.
@@ -396,7 +396,50 @@ pub fn generate_docset(cfg: DocsetParams) -> Result<()> {
396396 ) ;
397397 }
398398
399+ // Merge the options specified in cargo metadata. Options specified on the CLI take precedence.
399400 let cargo_metadata = cfg. manifest . metadata ( ) . exec ( ) . context ( CargoMetadataSnafu ) ?;
401+ let workspace_metadata_res = serde_json:: from_value :: < WorkspaceMetadata > ( cargo_metadata. workspace_metadata . clone ( ) ) ;
402+ if let Ok ( workspace_metadata) = workspace_metadata_res {
403+ if !cfg. features . all_features && cfg. features . features . is_empty ( ) && workspace_metadata. features . is_some ( ) {
404+ cfg. features . features = workspace_metadata. features . unwrap ( ) ;
405+ }
406+
407+ if !cfg. no_dependencies && workspace_metadata. no_deps . unwrap_or ( false ) {
408+ cfg. no_dependencies = true ;
409+ }
410+
411+ if !cfg. doc_private_items && workspace_metadata. document_private_items . unwrap_or ( false ) {
412+ cfg. doc_private_items = true ;
413+ }
414+
415+ if cfg. target . is_none ( ) && workspace_metadata. target . is_some ( ) {
416+ cfg. target = workspace_metadata. target ;
417+ }
418+
419+ if !cfg. lib && workspace_metadata. lib . unwrap_or ( false ) {
420+ cfg. lib = true ;
421+ }
422+
423+ if cfg. bin . is_empty ( ) && workspace_metadata. bin . is_some ( ) {
424+ cfg. bin = workspace_metadata. bin . unwrap ( ) ;
425+ }
426+
427+ if !cfg. bins && workspace_metadata. bins . unwrap_or ( false ) {
428+ cfg. bins = true ;
429+ }
430+
431+ if cfg. docset_name . is_none ( ) && workspace_metadata. docset_name . is_some ( ) {
432+ cfg. docset_name = workspace_metadata. docset_name ;
433+ }
434+
435+ if cfg. docset_index . is_none ( ) && workspace_metadata. docset_index . is_some ( ) {
436+ cfg. docset_index = workspace_metadata. docset_index ;
437+ }
438+
439+ if cfg. platform_family . is_none ( ) && workspace_metadata. platform_family . is_some ( ) {
440+ cfg. platform_family = workspace_metadata. platform_family ;
441+ }
442+ }
400443
401444 // Clean the documentation directory if the user didn't explicitly ask not to clean it.
402445 if !cfg. no_clean {
0 commit comments