1
+ use crate :: core:: compiler:: { Compilation , CompileKind } ;
1
2
use crate :: core:: { Shell , Workspace } ;
2
3
use crate :: ops;
3
4
use crate :: util:: config:: { Config , PathAndArgs } ;
@@ -61,16 +62,7 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> {
61
62
. ok_or_else ( || anyhow:: anyhow!( "no crates with documentation" ) ) ?;
62
63
let kind = options. compile_opts . build_config . single_requested_kind ( ) ?;
63
64
64
- let path = if matches ! ( options. output_format, OutputFormat :: Json ) {
65
- compilation. root_output [ & kind]
66
- . with_file_name ( "doc" )
67
- . join ( format ! ( "{}.json" , & name) )
68
- } else {
69
- compilation. root_output [ & kind]
70
- . with_file_name ( "doc" )
71
- . join ( & name)
72
- . join ( "index.html" )
73
- } ;
65
+ let path = path_by_output_format ( & compilation, & kind, & name, & options. output_format ) ;
74
66
75
67
if path. exists ( ) {
76
68
let config_browser = {
@@ -88,10 +80,8 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> {
88
80
} else {
89
81
for name in & compilation. root_crate_names {
90
82
for kind in & options. compile_opts . build_config . requested_kinds {
91
- let path = compilation. root_output [ & kind]
92
- . with_file_name ( "doc" )
93
- . join ( & name)
94
- . join ( "index.html" ) ;
83
+ let path =
84
+ path_by_output_format ( & compilation, & kind, & name, & options. output_format ) ;
95
85
if path. exists ( ) {
96
86
let mut shell = ws. config ( ) . shell ( ) ;
97
87
let link = shell. err_file_hyperlink ( & path) ;
@@ -107,6 +97,24 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> {
107
97
Ok ( ( ) )
108
98
}
109
99
100
+ fn path_by_output_format (
101
+ compilation : & Compilation < ' _ > ,
102
+ kind : & CompileKind ,
103
+ name : & str ,
104
+ output_format : & OutputFormat ,
105
+ ) -> PathBuf {
106
+ if matches ! ( output_format, OutputFormat :: Json ) {
107
+ compilation. root_output [ kind]
108
+ . with_file_name ( "doc" )
109
+ . join ( format ! ( "{}.json" , name) )
110
+ } else {
111
+ compilation. root_output [ kind]
112
+ . with_file_name ( "doc" )
113
+ . join ( name)
114
+ . join ( "index.html" )
115
+ }
116
+ }
117
+
110
118
fn open_docs (
111
119
path : & Path ,
112
120
shell : & mut Shell ,
0 commit comments