forked from extern/nushell
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:
@ -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)?;
|
||||
|
||||
|
@ -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,
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
));
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user