@@ -67,6 +67,7 @@ use serde::Deserialize;
6767use serde:: Serialize ;
6868
6969use super :: flags_net;
70+ use crate :: util:: env:: resolve_cwd;
7071use crate :: util:: fs:: canonicalize_path;
7172
7273#[ derive( Clone , Debug , Default , Eq , PartialEq ) ]
@@ -1415,7 +1416,7 @@ impl Flags {
14151416 exclude : excluded_paths,
14161417 ..
14171418 } ) ) => {
1418- let cwd = std :: env :: current_dir ( ) ?;
1419+ let cwd = resolve_cwd ( self . initial_cwd . as_deref ( ) ) ?;
14191420 PathOrPatternSet :: from_exclude_relative_path_or_patterns (
14201421 & cwd,
14211422 excluded_paths,
@@ -6145,7 +6146,8 @@ fn completions_parse(
61456146 unsafe {
61466147 std:: env:: set_var ( "COMPLETE" , & shell) ;
61476148 }
6148- handle_shell_completion_with_args ( std:: env:: args_os ( ) . take ( 1 ) ) ?;
6149+ let cwd = resolve_cwd ( None ) ?;
6150+ handle_shell_completion_with_args ( std:: env:: args_os ( ) . take ( 1 ) , & cwd) ?;
61496151 Ok ( ( ) )
61506152 } ) ,
61516153 ) ) ;
@@ -7024,8 +7026,8 @@ fn task_parse(
70247026 Ok ( ( ) )
70257027}
70267028
7027- pub fn handle_shell_completion ( ) -> Result < ( ) , AnyError > {
7028- handle_shell_completion_with_args ( std:: env:: args_os ( ) )
7029+ pub fn handle_shell_completion ( cwd : & Path ) -> Result < ( ) , AnyError > {
7030+ handle_shell_completion_with_args ( std:: env:: args_os ( ) , cwd )
70297031}
70307032
70317033struct ZshCompleterUnsorted ;
@@ -7112,6 +7114,7 @@ compdef _clap_dynamic_completer_NAME BIN"#
71127114
71137115fn handle_shell_completion_with_args (
71147116 args : impl IntoIterator < Item = OsString > ,
7117+ cwd : & Path ,
71157118) -> Result < ( ) , AnyError > {
71167119 let args = args. into_iter ( ) . collect :: < Vec < _ > > ( ) ;
71177120 let app = clap_root ( ) ;
@@ -7124,7 +7127,7 @@ fn handle_shell_completion_with_args(
71247127 & clap_complete:: env:: Powershell ,
71257128 & ZshCompleterUnsorted ,
71267129 ] ) )
7127- . try_complete ( args, Some ( & std :: env :: current_dir ( ) ? ) ) ?;
7130+ . try_complete ( args, Some ( cwd ) ) ?;
71287131
71297132 // we should only run this function when we're doing completions
71307133 assert ! ( ran_completion) ;
@@ -12560,12 +12563,12 @@ mod tests {
1256012563 #[ test]
1256112564 fn test_config_path_args ( ) {
1256212565 let flags = flags_from_vec ( svec ! [ "deno" , "run" , "foo.js" ] ) . unwrap ( ) ;
12563- let cwd = std :: env :: current_dir ( ) . unwrap ( ) ;
12566+ let cwd = resolve_cwd ( None ) . unwrap ( ) . into_owned ( ) ;
1256412567
1256512568 assert_eq ! ( flags. config_path_args( & cwd) , Some ( vec![ cwd. clone( ) ] ) ) ;
1256612569
1256712570 let flags = flags_from_vec ( svec ! [ "deno" , "run" , "sub_dir/foo.js" ] ) . unwrap ( ) ;
12568- let cwd = std :: env :: current_dir ( ) . unwrap ( ) ;
12571+ let cwd = resolve_cwd ( None ) . unwrap ( ) . into_owned ( ) ;
1256912572 assert_eq ! (
1257012573 flags. config_path_args( & cwd) ,
1257112574 Some ( vec![ cwd. join( "sub_dir" ) . clone( ) ] )
0 commit comments