File tree 1 file changed +16
-1
lines changed
1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -227,6 +227,21 @@ impl WrappedCommand {
227
227
}
228
228
}
229
229
230
+ /// Quote an argument that has spaces in it.
231
+ /// When our `WrappedCommand` is printed to the terminal, arguments that contain spaces needed to be quoted.
232
+ /// Otherwise, we will have output such as:
233
+ /// `pkg-config --libs --cflags foo foo < 3.11`
234
+ /// which cannot be used in a terminal - it will attempt to read a file named 3.11 and provide it as stdin for pkg-config.
235
+ /// Using this function, we instead get the correct output:
236
+ /// `pkg-config --libs --cflags foo 'foo < 3.11'`
237
+ fn quote_if_needed ( arg : String ) -> String {
238
+ if arg. contains ( ' ' ) {
239
+ format ! ( "'{}'" , arg)
240
+ } else {
241
+ arg
242
+ }
243
+ }
244
+
230
245
/// Output a command invocation that can be copy-pasted into the terminal.
231
246
/// `Command`'s existing debug implementation is not used for that reason,
232
247
/// as it can sometimes lead to output such as:
@@ -248,7 +263,7 @@ impl Display for WrappedCommand {
248
263
let args = self
249
264
. args
250
265
. iter ( )
251
- . map ( |arg| arg. to_string_lossy ( ) . to_string ( ) )
266
+ . map ( |arg| quote_if_needed ( arg. to_string_lossy ( ) . to_string ( ) ) )
252
267
. collect :: < Vec < String > > ( )
253
268
. join ( " " ) ;
254
269
You can’t perform that action at this time.
0 commit comments