Track call arguments in a single list (#5125)

* Initial implementation of ordered call args

* Run cargo fmt

* Fix some clippy lints

* Add positional len and nth

* Cargo fmt

* Remove more old nth calls

* Good ole rustfmt

* Add named len

Co-authored-by: Hristo Filaretov <h.filaretov@protonmail.com>
This commit is contained in:
Hristo Filaretov
2022-04-09 04:55:02 +02:00
committed by GitHub
parent 3bac480ca0
commit 683b912263
25 changed files with 263 additions and 190 deletions

View File

@ -28,7 +28,7 @@ impl Command for Cd {
call: &Call,
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
let raw_path = call.nth(0);
let raw_path = call.positional_nth(0);
let path_val: Option<Value> = call.opt(engine_state, stack, 0)?;
let cwd = current_dir(engine_state, stack)?;

View File

@ -57,13 +57,18 @@ impl Command for Mkdir {
}
for (i, dir) in directories.enumerate() {
let span = call.positional[i].span;
let span = call
.positional_nth(i)
.expect("already checked through directories")
.span;
let dir_res = std::fs::create_dir_all(&dir);
if let Err(reason) = dir_res {
return Err(ShellError::CreateNotPossible(
format!("failed to create directory: {}", reason),
call.positional[i].span,
call.positional_nth(i)
.expect("already checked through directories")
.span,
));
}

View File

@ -239,7 +239,9 @@ impl Command for Touch {
if let Err(err) = OpenOptions::new().write(true).create(true).open(&item) {
return Err(ShellError::CreateNotPossible(
format!("Failed to create file: {}", err),
call.positional[index].span,
call.positional_nth(index)
.expect("already checked positional")
.span,
));
};
@ -251,7 +253,9 @@ impl Command for Touch {
) {
return Err(ShellError::ChangeModifiedTimeNotPossible(
format!("Failed to change the modified time: {}", err),
call.positional[index].span,
call.positional_nth(index)
.expect("already checked positional")
.span,
));
};
}
@ -268,7 +272,9 @@ impl Command for Touch {
) {
return Err(ShellError::ChangeAccessTimeNotPossible(
format!("Failed to change the access time: {}", err),
call.positional[index].span,
call.positional_nth(index)
.expect("already checked positional")
.span,
));
};
} else {
@ -279,7 +285,9 @@ impl Command for Touch {
) {
return Err(ShellError::ChangeAccessTimeNotPossible(
format!("Failed to change the access time: {}", err),
call.positional[index].span,
call.positional_nth(index)
.expect("already checked positional")
.span,
));
};
}