diff --git a/crates/nu-protocol/src/ast/call.rs b/crates/nu-protocol/src/ast/call.rs index 5407ee5fa4..868ec53bdb 100644 --- a/crates/nu-protocol/src/ast/call.rs +++ b/crates/nu-protocol/src/ast/call.rs @@ -128,7 +128,8 @@ impl Call { pub fn named_iter( &self, - ) -> impl Iterator, Option>, Option)> { + ) -> impl DoubleEndedIterator, Option>, Option)> + { self.arguments.iter().filter_map(|arg| match arg { Argument::Named(named) => Some(named), Argument::Positional(_) => None, @@ -222,7 +223,7 @@ impl Call { } pub fn get_flag_expr(&self, flag_name: &str) -> Option<&Expression> { - for name in self.named_iter() { + for name in self.named_iter().rev() { if flag_name == name.0.item { return name.2.as_ref(); } @@ -232,7 +233,7 @@ impl Call { } pub fn get_named_arg(&self, flag_name: &str) -> Option> { - for name in self.named_iter() { + for name in self.named_iter().rev() { if flag_name == name.0.item { return Some(name.0.clone()); } diff --git a/tests/repl/test_config_path.rs b/tests/repl/test_config_path.rs index 8ed90f913a..5b78ed41dd 100644 --- a/tests/repl/test_config_path.rs +++ b/tests/repl/test_config_path.rs @@ -242,6 +242,29 @@ fn test_alternate_config_path() { assert_eq!(actual.out, env_path.to_string_lossy().to_string()); } +#[test] +fn use_last_config_path() { + let config_file = "crates/nu-utils/src/default_files/scaffold_config.nu"; + let env_file = "crates/nu-utils/src/default_files/scaffold_env.nu"; + + let cwd = std::env::current_dir().expect("Could not get current working directory"); + + let config_path = + nu_path::canonicalize_with(config_file, &cwd).expect("Could not get config path"); + let actual = nu!( + cwd: &cwd, + format!("nu --config non-existing-path --config another-random-path.nu --config {config_path:?} -c '$nu.config-path'") + ); + assert_eq!(actual.out, config_path.to_string_lossy().to_string()); + + let env_path = nu_path::canonicalize_with(env_file, &cwd).expect("Could not get env path"); + let actual = nu!( + cwd: &cwd, + format!("nu --env-config non-existing-path --env-config {env_path:?} -c '$nu.env-path'") + ); + assert_eq!(actual.out, env_path.to_string_lossy().to_string()); +} + #[test] fn test_xdg_config_empty() { Playground::setup("xdg_config_empty", |_, playground| {