@@ -56,16 +56,16 @@ fn try_help(config: &Config) -> CargoResult<bool> {
56
56
Some ( man) => man,
57
57
None => return Ok ( false ) ,
58
58
} ;
59
- write_and_spawn ( & man, "man" ) ?;
59
+ write_and_spawn ( & subcommand , & man, "man" ) ?;
60
60
} else {
61
61
let txt = match extract_man ( & subcommand, "txt" ) {
62
62
Some ( txt) => txt,
63
63
None => return Ok ( false ) ,
64
64
} ;
65
65
if resolve_executable ( Path :: new ( "less" ) ) . is_ok ( ) {
66
- write_and_spawn ( & txt, "less" ) ?;
66
+ write_and_spawn ( & subcommand , & txt, "less" ) ?;
67
67
} else if resolve_executable ( Path :: new ( "more" ) ) . is_ok ( ) {
68
- write_and_spawn ( & txt, "more" ) ?;
68
+ write_and_spawn ( & subcommand , & txt, "more" ) ?;
69
69
} else {
70
70
drop ( std:: io:: stdout ( ) . write_all ( & txt) ) ;
71
71
}
@@ -117,13 +117,20 @@ fn extract_man(subcommand: &str, extension: &str) -> Option<Vec<u8>> {
117
117
118
118
/// Write the contents of a man page to disk and spawn the given command to
119
119
/// display it.
120
- fn write_and_spawn ( contents : & [ u8 ] , command : & str ) -> CargoResult < ( ) > {
121
- let mut tmp = tempfile:: Builder :: new ( ) . prefix ( "cargo-man" ) . tempfile ( ) ?;
120
+ fn write_and_spawn ( name : & str , contents : & [ u8 ] , command : & str ) -> CargoResult < ( ) > {
121
+ let prefix = format ! ( "cargo-{}." , name) ;
122
+ let mut tmp = tempfile:: Builder :: new ( ) . prefix ( & prefix) . tempfile ( ) ?;
122
123
let f = tmp. as_file_mut ( ) ;
123
124
f. write_all ( contents) ?;
124
125
f. flush ( ) ?;
126
+ let path = tmp. path ( ) ;
127
+ // Use a path relative to the temp directory so that it can work on
128
+ // cygwin/msys systems which don't handle windows-style paths.
129
+ let mut relative_name = std:: ffi:: OsString :: from ( "./" ) ;
130
+ relative_name. push ( path. file_name ( ) . unwrap ( ) ) ;
125
131
let mut cmd = std:: process:: Command :: new ( command)
126
- . arg ( tmp. path ( ) )
132
+ . arg ( relative_name)
133
+ . current_dir ( path. parent ( ) . unwrap ( ) )
127
134
. spawn ( ) ?;
128
135
drop ( cmd. wait ( ) ) ;
129
136
Ok ( ( ) )
0 commit comments