8
8
use clap:: { builder:: ValueParser , parser:: ValueSource , Arg , ArgAction , Command } ;
9
9
use std:: ffi:: { OsStr , OsString } ;
10
10
use std:: fs:: { self , Metadata } ;
11
+ use std:: io:: { stdin, IsTerminal } ;
11
12
use std:: ops:: BitOr ;
12
13
#[ cfg( not( windows) ) ]
13
14
use std:: os:: unix:: ffi:: OsStrExt ;
@@ -576,6 +577,10 @@ fn prompt_dir(path: &Path, options: &Options) -> bool {
576
577
if options. interactive == InteractiveMode :: Never {
577
578
return true ;
578
579
}
580
+ // Silently proceed if stdin is not interactive terminal
581
+ if !stdin ( ) . is_terminal ( ) {
582
+ return true ;
583
+ }
579
584
580
585
// We can't use metadata.permissions.readonly for directories because it only works on files
581
586
// So we have to handle whether a directory is writable manually
@@ -591,6 +596,10 @@ fn prompt_file(path: &Path, options: &Options) -> bool {
591
596
if options. interactive == InteractiveMode :: Never {
592
597
return true ;
593
598
}
599
+ // Silently proceed if stdin is not interactive terminal
600
+ if !stdin ( ) . is_terminal ( ) {
601
+ return true ;
602
+ }
594
603
// If interactive is Always we want to check if the file is symlink to prompt the right message
595
604
if options. interactive == InteractiveMode :: Always {
596
605
if let Ok ( metadata) = fs:: symlink_metadata ( path) {
@@ -615,6 +624,10 @@ fn prompt_file(path: &Path, options: &Options) -> bool {
615
624
}
616
625
617
626
fn prompt_file_permission_readonly ( path : & Path ) -> bool {
627
+ // Silently proceed if stdin is not interactive terminal
628
+ if !stdin ( ) . is_terminal ( ) {
629
+ return true ;
630
+ }
618
631
match fs:: metadata ( path) {
619
632
Ok ( _) if is_writable ( path) => true ,
620
633
Ok ( metadata) if metadata. len ( ) == 0 => prompt_yes ! (
0 commit comments